Quickblox Javascript SDK + Angular + webRTC - Chat room filter by name is not showing up in results after creation by another user

淺唱寂寞╮ 提交于 2019-12-12 03:33:45

问题


I am adding a chat client to my webRTC app and my issue comes when a chat room doesn't exist. One user logs in and looks to see if the chat room exists with a certain name. If it doesn't exist the user creates one. Now here is where the issue comes in. The second user logs in with the same chat room name to search with and does a search with QB.chat.dialog.list({name: 'stringWithMyChatRoomName'}) but even after the first user had just created the room it doesn't get returned in the results. I can see the rooms in the admin so I know they are being constructed in the DB. Here is the code to get the current lack of results.

QB.createSession(function(err,result){
    if (result) {
        QB.login($scope.userParams, function(loginErr, loginUser){
            if (loginUser) {
                console.log('Logged in as:');
                console.log(loginUser);
                QB.users.update($scope.userParams.id, {tag_list: $scope.userParams.tag_list}, function(err, user){
                    if (user) {
                        console.log('updated room');
                        //console.log(user);
                    }else if (err) {
                        console.log('Didn\'t update room');
                        //console.log(err);
                    }
                    QB.chat.connect({
                        userId: $scope.userParams.id,
                        password: $scope.userParams.password,
                        login: $scope.userParams.full_name
                    }, function(err, result) {
                        if (result) {  
                            console.log($scope.userParams.tag_list);
                            //$scope.userParams.user_tags = $scope.userParams.tag_list;
                            //$scope.updatePeerList();
                            var filters = {type: 2,name: $scope.userParams.tag_list};
                            //var filters = {name: $scope.userParams.tag_list}
                            QB.chat.dialog.list(filters, function(err, resDialogs) {
                                if (resDialogs) {
                                    console.log(resDialogs);
                                    if (resDialogs.total_entries === 0) {
                                        QB.chat.dialog.create({
                                            type: 2,
                                            name: $scope.userParams.tag_list
                                        }, function(err, createdDialog) {
                                            if (createdDialog) {
                                                console.log(createdDialog);
                                                QB.chat.muc.join(createdDialog.xmpp_room_jid, function() {

                                                });
                                            } else {
                                                console.log(err);
                                            }
                                        });
                                    }else {
                                        angular.forEach(resDialogs.items, function(item, i, arr) {
                                            console.log('item found');
                                            console.log(item);
                                            $scope.chatSession = item;

                                            // join room
                                            if ($scope.chatSession.type !== 3) {
                                                QB.chat.muc.join($scope.chatSession.xmpp_room_jid, function() {

                                                });
                                            }
                                            //$scope.occupants = [];
                                            $scope.chatSession.occupants_ids.map(function(userId) {
                                                if ($scope.userParams.id !== userId && $scope.occupants.indexOf(userId) < 1) {
                                                    $scope.occupants.push(userId);
                                                }
                                            });

                                            angular.forEach($scope.occupants, function (user_id) {
                                                if (user_id !== $scope.userParams.id) {
                                                    var msg = {
                                                        type: 'chat',
                                                        extension: {
                                                            notification_type: 1,
                                                            _id: $scope.chatSession.xmpp_room_jid,
                                                            name: $scope.userParams.full_name,
                                                            occupant: $scope.userParams.id
                                                        }
                                                    };
                                                    console.log(user_id);
                                                    QB.chat.send(user_id, msg);
                                                }
                                            });
                                        });
                                        console.log('scope apply occupants and chatSession');
                                        $scope.$apply();
                                    }
                                } else {
                                    console.log('error with chat.dialog.list');
                                    console.log(err);
                                }
                            });                                                 
                        } else { 
                            console.log('chat.connect failed');
                            console.log(res); 
                        }
                    }); 
                });
            }else {
                console.log('log in error');
                console.log(loginErr);
            }
        });
    }else if (err) {
        console.log('Error creating session');
        console.log(err);
    }
});

Now I have tried making a search for just all the groups period but that returns 0 as well. I tried changing it to create a public group but for some reason QB doesn't show the user ids of the people in the room so I have no way to send a message to a user without having the user id first.

Please advise on how to get the desired effect. Thank you.


回答1:


are you sure about QB.chat.dialog.list(filters) ?

var filters = {type: 2,name: $scope.userParams.tag_list};

tag_list is an array, but name in a dialog is a string. https://quickblox.com/developers/Web_XMPP_Chat_Sample#Filters

Could you log on and show us them? By debug: {mode: 1} See https://quickblox.com/developers/Javascript#Configuration



来源:https://stackoverflow.com/questions/42940140/quickblox-javascript-sdk-angular-webrtc-chat-room-filter-by-name-is-not-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!