聊天时会创建多个对话框 快速布洛克斯.



为群组创建聊天对话框时。例如,用户 A 正在创建对话框,用户 B 希望使用该对话框。但有时会出现用户 A 创建一个对话框,然后用户 B 创建另一个对话框的情况。因此,由于两个不同的对话,他们无法相互聊天。以下是我用来创建对话框的代码:-

-(void) moveToChatView:(QBChatDialog *)chatDialog ObjFriend:(Friend *)objFriend
{
    [QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog)
    {
         // Success, do something
    }
    errorBlock:^(QBResponse *response)
    {
    }];
} 

编辑 :- 有没有像创建或加入房间与名称这样的方法?

如果要在群聊中添加用户,则需要更新群组对话框。

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) {
 
}];

有关更多详细信息,请查看此Update_group_dialog

对于群组对话中的聊天,请检查Chat_in_group_dialog

不要忘记使用委托方法。

杂注标记 QBChatDelegate

- (void)chatRoomDidReceiveMessage:(QBChatMessage *)message fromDialogId:(NSString *)dialogId{
 
}

编辑1:-您将通过检索所有对话框获得对话ID。

QBResponsePage *page = [QBResponsePage responsePageWithLimit:100 skip:0];
 
[QBRequest dialogsForPage:page extendedRequest:nil successBlock:^(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, QBResponsePage *page) {
 
} errorBlock:^(QBResponse *response) {
 
}];

编辑 2:- 要在创建新对话框时知道对话框 ID,请使用 createChatNotificationForGroupChatCreation 方法。

- (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;
}