While creating a chat dialog for a group. For e.g User A is creating dialog and User B want to use that dialog. But sometimes scenario is occurring that User A create one dialog and then User B create another dialog. So they are not able to chat with each other because of two different dialogs. Below is the code i am using to create dialog :-
-(void) moveToChatView:(QBChatDialog *)chatDialog ObjFriend:(Friend *)objFriend
{
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog)
{
// Success, do something
}
errorBlock:^(QBResponse *response)
{
}];
}
Edit :- Is there any method like createOrJoinRoomWithName??
To if you want to add user in groupchat then you need to update the group dialogue.
QBChatDialog *updateDialog = [[QBChatDialog alloc] initWithDialogID:@"53aac645535c12bd3b008a40" type:QBChatDialogTypeGroup];
updateDialog.pushOccupantsIDs = @[@"300", @"301", @"302"];
updateDialog.name = @"school friends";
[QBRequest updateDialog:updateDialog successBlock:^(QBResponse *responce, QBChatDialog *dialog) {
} errorBlock:^(QBResponse *response) {
}];
For more detail check this Update_group_dialog
And for chat in group dialogue check Chat_in_group_dialog
Don't forget to use delegate method.
- (void)chatRoomDidReceiveMessage:(QBChatMessage *)message fromDialogId:(NSString *)dialogId{
}
Edit 1:- you will get DialogId with retriving all dialog.
QBResponsePage *page = [QBResponsePage responsePageWithLimit:100 skip:0];
[QBRequest dialogsForPage:page extendedRequest:nil successBlock:^(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, QBResponsePage *page) {
} errorBlock:^(QBResponse *response) {
}];
Edit 2:- To know the dialogId when creating new Dialog use createChatNotificationForGroupChatCreation method.
- (QBChatMessage *)createChatNotificationForGroupChatCreation:(QBDialog *)dialog
{
// create message:
QBChatMessage *inviteMessage = [QBChatMessage message];
NSMutableDictionary *customParams = [NSMutableDictionary new];
customParams[@"xmpp_room_jid"] = dialog.roomJID;
customParams[@"name"] = dialog.name;
customParams[@"_id"] = dialog.ID;
customParams[@"type"] = @(dialog.type);
customParams[@"occupants_ids"] = [dialog.occupantIDs componentsJoinedByString:@","];
// Add notification_type=1 to extra params when you created a group chat
//
customParams[@"notification_type"] = @"1";
inviteMessage.customParameters = customParams;
return inviteMessage;
}