2016-03-07 59 views
0

爲羣組創建聊天對話框時。 例如,用戶A正在創建對話框,並且用戶B想要使用該對話框。 但有時情況發生,用戶A創建一個對話框,然後用戶B創建另一個對話框。 因此,由於兩個不同的對話框,他們無法與對方聊天。 下面是我用來創建對話框代碼: -聊天時會創建多個對話框Quickblox

-(void) moveToChatView:(QBChatDialog *)chatDialog ObjFriend:(Friend *)objFriend 

{ 
    [QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) 

    { 
     // Success, do something 
    } 
    errorBlock:^(QBResponse *response) 
    { 

    }]; 
} 

編輯: - 有沒有像createOrJoinRoomWithName任何方法?

+0

你想對話只爲A和B或像A,B,C,D這樣的組? –

+0

嗨巴達爾,我想它像A,B,C,D可以有很多用戶。所以我想要一個組 –

回答

2

如果您想在groupchat中添加用戶,則需要更新組對話。

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: -你會得到DialogId與retriving所有對話。

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: -要知道dialogId創造新的對話框使用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; 
} 
+0

但是badal有一個場景。我不知道該對話框是否已經存在或不存在? 如果更新對話框不存在,更新對話框會返回一個錯誤嗎? –

+0

我如何知道dialogID?我已經在initWithDialogID –

+0

dialogID中傳遞了對你的幫助。 –