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.