QuickBlox / quickblox-ios-sdk

QuickBlox iOS SDK for messaging and video calling
https://quickblox.com/developers/IOS
MIT License
397 stars 358 forks source link

*** Assertion failure in -[QMDialogsMemoryStorage addChatDialog:andJoin:completion:] #988

Closed shaharukhs closed 6 years ago

shaharukhs commented 6 years ago

New Issue Checklist

Environment details

Info Value
iOS Version e.g. 8.0
Quickblox iOS SDK version e.g. 2.7.6
QuickbloxWebRTC SDK version e.g. 2.2.1
Xcode Version e.g. Xcode 8.1
Repro with our demo sample e.g. does it happen with our demo sample?

Did this work before?

Expected behavior

Actual behavior crashing with this error NSAssert(chatDialog.type != 0, @"Chat type is not defined"); Logs

Please use the following template for logs:

To enable full logs use the following code:

[QBSettings setLogLevel:QBLogLevelDebug];
[QBSettings enableXMPPLogging];
Title for logs ```logos // Your logs here 2018-04-02 19:11:51.921451+0530 VideoInspectionSystem[5824:2493678] [QBCore]: Request[7]: POST URL:https://api.quickblox.com/chat/Dialog.json headers: { "Accept-Language" = "en-IN;q=1"; "Content-Type" = "application/x-www-form-urlencoded"; "QB-OS" = "iOS 11.2.6"; "QB-SDK" = "iOS 2.15"; "QB-Token" = d0e99e13a9f51431a283fa54476f0ed763010de8; "QuickBlox-REST-API-Version" = "0.1.1"; "User-Agent" = "VideoInspectionSystem/0.1 (iPhone; iOS 11.2.6; Scale/2.00)"; } parameters: { "occupants_ids" = 46238050; type = 3; } 2018-04-02 19:11:52:138 VideoInspectionSystem[5824:900f] SEND: 2018-04-02 19:11:52:139 VideoInspectionSystem[5824:900f] SEND: 2018-04-02 19:11:52.443355+0530 VideoInspectionSystem[5824:2493669] [QBCore]: Response[7]: headers: { "Access-Control-Allow-Origin" = "*"; "Cache-Control" = "max-age=0, private, must-revalidate"; Connection = "keep-alive"; "Content-Type" = "application/json; charset=utf-8"; Date = "Mon, 02 Apr 2018 13:41:52 GMT"; Duration = "0.521087"; Etag = "W/\"46b50ef5f6b1fa8a3ce1ef4792639cc2\""; "QB-Token-ExpirationDate" = "2018-04-02 15:41:51 +0000"; "QuickBlox-REST-API-Version" = "0.1.1"; Server = "openresty/1.9.15.1"; "Set-Cookie" = "_mkra_ctxt=b31e79ba724f35758bb6fffddb4a1cef--201; path=/; max-age=5; HttpOnly; secure"; Status = "201 Created"; "Strict-Transport-Security" = "max-age=31536000, max-age=15768000;"; "Transfer-Encoding" = Identity; "X-Content-Type-Options" = nosniff; "X-Frame-Options" = SAMEORIGIN; "X-Request-Id" = "eb34dfe6-98a5-437e-a9cb-70c2be75b94a"; "X-Runtime" = "0.018721"; "X-XSS-Protection" = "1; mode=block"; } object: { "_id" = 5ac2324ea28f9a3151ecb5dc; "created_at" = "2018-04-02T13:38:22Z"; "last_message" = ""; "last_message_date_sent" = ""; "last_message_user_id" = ""; name = Deepak; "occupants_ids" = ( 45597452, 46238050 ); photo = ""; type = 3; "unread_messages_count" = ""; "updated_at" = "2018-04-02T13:38:22Z"; "user_id" = 45597452; "xmpp_room_jid" = ""; } 2018-04-02 19:11:52.497198+0530 VideoInspectionSystem[5824:2493640] [QBCore]: Request[8]: GET URL:https://api.quickblox.com/chat/Message.json?chat_dialog_id=5ac2324ea28f9a3151ecb5dc&limit=20 headers: { "Accept-Language" = "en-IN;q=1"; "QB-OS" = "iOS 11.2.6"; "QB-SDK" = "iOS 2.15"; "QB-Token" = d0e99e13a9f51431a283fa54476f0ed763010de8; "QuickBlox-REST-API-Version" = "0.1.1"; "User-Agent" = "VideoInspectionSystem/0.1 (iPhone; iOS 11.2.6; Scale/2.00)"; } parameters: { "chat_dialog_id" = 5ac2324ea28f9a3151ecb5dc; limit = 20; } [] 2018-04-02 19:11:52.776080+0530 VideoInspectionSystem[5824:2493640] [QBCore]: Response[8]: headers: { "Access-Control-Allow-Origin" = "*"; "Cache-Control" = "max-age=0, private, must-revalidate"; Connection = "keep-alive"; "Content-Length" = 32; "Content-Type" = "application/json; charset=utf-8"; Date = "Mon, 02 Apr 2018 13:41:52 GMT"; Duration = "0.273259"; Etag = "W/\"95e7c20d19f78c5b3bcc34ac35ea0d09\""; "QB-Token-ExpirationDate" = "2018-04-02 15:41:51 +0000"; "QuickBlox-REST-API-Version" = "0.1.1"; Server = "nginx/1.8.1"; "Set-Cookie" = "_mkra_ctxt=cb756c6b5ec5fe3e60f94a556a11f4f9--200; path=/; max-age=5; HttpOnly; secure"; Status = "304 Not Modified"; "Strict-Transport-Security" = "max-age=31536000, max-age=15768000;"; "X-Content-Type-Options" = nosniff; "X-Frame-Options" = SAMEORIGIN; "X-Request-Id" = "b11726bf-2edf-42ee-8cf8-a6a9f7a47fb2"; "X-Runtime" = "0.033045"; "X-XSS-Protection" = "1; mode=block"; } object: { items = ( ); limit = 20; skip = 0; } 2018-04-02 19:11:53:662 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:53:889 VideoInspectionSystem[5824:4503] RECV: PLAINANONYMOUSPLAIN_FASTzlib 2018-04-02 19:11:53:892 VideoInspectionSystem[5824:303] SEND: ADQ1NTk3NDUyLTY5MDk2AHdlYkFwcFBhc3M= 2018-04-02 19:11:54.149 rtc::[RTCClient] Signaling channel connected 2018-04-02 19:11:54:146 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54:147 VideoInspectionSystem[5824:2707] SEND: DE922725-F585-4202-88ED-C14D54FBA282 2018-04-02 19:11:54.154029+0530 VideoInspectionSystem[5824:2493663] [ChatService]: Connected 2018-04-02 19:11:54:150 VideoInspectionSystem[5824:2707] SEND: 2018-04-02 19:11:54.154383+0530 VideoInspectionSystem[5824:2493663] [ChatService]: SNT: 2018-04-02 19:11:54:151 VideoInspectionSystem[5824:9503] SEND: 2018-04-02 19:11:54:152 VideoInspectionSystem[5824:900f] SEND: 2018-04-02 19:11:54.156719+0530 VideoInspectionSystem[5824:2493663] [ChatService]: SNT: 2018-04-02 19:11:54:155 VideoInspectionSystem[5824:9e07] SEND: 2018-04-02 19:11:54.157282+0530 VideoInspectionSystem[5824:2493663] [ChatService]: SNT: 2018-04-02 19:11:54:403 VideoInspectionSystem[5824:9503] RECV: 45597452-69096@chat.quickblox.com/DE922725-F585-4202-88ED-C14D54FBA282 2018-04-02 19:11:54.405720+0530 VideoInspectionSystem[5824:2493663] [ChatService]: RCV: 45597452-69096@chat.quickblox.com/DE922725-F585-4202-88ED-C14D54FBA282 2018-04-02 19:11:54:660 VideoInspectionSystem[5824:4503] RECV: 2018-04-02 19:11:54.662056+0530 VideoInspectionSystem[5824:2493640] [ChatService]: SMT: 2018-04-02 19:11:54:887 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54.892509+0530 VideoInspectionSystem[5824:2493672] [ChatService]: RCV: 2018-04-02 19:11:54:889 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54:889 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54.892980+0530 VideoInspectionSystem[5824:2493672] [ChatService]: RCV: 2018-04-02 19:11:54:890 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54:890 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54.897149+0530 VideoInspectionSystem[5824:2493672] [ChatService]: RCV: 2018-04-02 19:11:54:890 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54:890 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54.897484+0530 VideoInspectionSystem[5824:2493672] [ChatService]: RCV: 2018-04-02 19:11:54:891 VideoInspectionSystem[5824:2707] RECV: 2018-04-02 19:11:54:893 VideoInspectionSystem[5824:4503] SEND: 2018-04-02 19:11:54:893 VideoInspectionSystem[5824:4503] SEND: 2018-04-02 19:11:54:893 VideoInspectionSystem[5824:4503] SEND: 2018-04-02 19:11:54:893 VideoInspectionSystem[5824:4503] SEND: 2018-04-02 19:12:01:598 VideoInspectionSystem[5824:2707] RECV: SystemNotifications15ac2324ea28f9a3151ecb5dc 2018-04-02 19:12:01.600560+0530 VideoInspectionSystem[5824:2493634] [ChatService]: RCV: SystemNotifications 1 5ac2324ea28f9a3151ecb5dc 2018-04-02 19:12:01.611901+0530 VideoInspectionSystem[5824:2493420] *** Assertion failure in -[QMDialogsMemoryStorage addChatDialog:andJoin:completion:], ```

Steps to reproduce the behavior

Any others comments

ghost commented 6 years ago

@shaharukhs, Hello. You should specify dialog type before saving it to the memory storage.

ghost commented 6 years ago

Dialogs can have next types:

type - Chat dialog type:

//objective-c
    typedef NS_ENUM(NSUInteger, QBChatDialogType) {
        QBChatDialogTypePublicGroup = 1,
        QBChatDialogTypeGroup = 2,
        QBChatDialogTypePrivate = 3,
    };

//swift4
    public enum QBChatDialogType : UInt {
        case publicGroup
        case group
        case `private`
    }
shaharukhs commented 6 years ago

But This one happening on message receive


- (void)chatDidReceiveSystemMessage:(QBChatMessage *)message {

    [self handleSystemMessage:message];
}

Please check screenshot screen shot 2018-04-03 at 11 35 49 am

ghost commented 6 years ago

Hello @shaharukhs, from your logs:

2018-04-02 19:12:01.600560+0530 VideoInspectionSystem[5824:2493634] [ChatService]: RCV: <message xmlns="jabber:client" type="headline" from="46238050-69096@chat.quickblox.com/1571722472-quickblox-15002733" to="45597452-69096@chat.quickblox.com" id="5ac233283a5d4e2e54000003">
  <extraParams xmlns="jabber:client">
    <moduleIdentifier>SystemNotifications</moduleIdentifier>
    <notification_type>1</notification_type>
    <dialog_id>5ac2324ea28f9a3151ecb5dc</dialog_id>
  </extraParams>
</message>

<notification_type>1</notification_type> is equeal QMMessageTypeCreateGroupDialog Your system message should containts <type>2</type> type field. Check message.dialog implementation ("QBChatMessage+QMCustomParameters.m" file) from method bellow:


- (void)handleSystemMessage:(QBChatMessage *)message {

    if (message.messageType == QMMessageTypeCreateGroupDialog) {

        if ([self.dialogsMemoryStorage chatDialogWithID:message.dialogID] != nil) {
            return;
        }

       //check message.dialog; 

        QBChatDialog *dialogToAdd = message.dialog;

        [self updateLastMessageParamsForChatDialog:dialogToAdd withMessage:message];
        dialogToAdd.updatedAt = message.dateSent;

        __weak __typeof(self)weakSelf = self;
        [self.dialogsMemoryStorage addChatDialog:dialogToAdd
                                         andJoin:self.isAutoJoinEnabled
                                      completion:^(QBChatDialog *addedDialog, NSError *error)
         {
             __typeof(weakSelf)strongSelf = weakSelf;

             if (message.senderID != strongSelf.serviceManager.currentUser.ID) {
                 addedDialog.unreadMessagesCount++;
             }

             if ([strongSelf.multicastDelegate respondsToSelector:@selector(chatService:didAddChatDialogToMemoryStorage:)]) {
                 [strongSelf.multicastDelegate chatService:strongSelf
                           didAddChatDialogToMemoryStorage:addedDialog];
             }
         }];
    }
}

You should use this method:

- (void)sendSystemMessageAboutAddingToDialog:(QBChatDialog *)chatDialog
                                  toUsersIDs:(NSArray *)usersIDs
                                    withText:(NSString *)text
                                  completion:(QBChatCompletionBlock)completion {

or add all field in your system message for represent chat dialog.

For example, should be:

    <notification_type>1</notification_type>
    <dialog_id> 5ac2324ea28f9a3151ecb5dc </dialog_id>
    <room_name>@shaharukhs</room_name>
    <room_updated_date>1522739811</room_updated_date>
    <type>2</type>
    <current_occupant_ids>1,2,3,4,5,6,7,8</current_occupant_ids>
    <date_sent>1522739810</date_sent>

Thanks!

shaharukhs commented 6 years ago

Thanks for your reply.

But I am receiving chat from web app which was using JS to achieve this Your system message should contains <type>2</type> type field. So my back end team need to change on there side right?

ghost commented 6 years ago

@shaharukhs

So my back end team need to change on there side right?

Yes, if this is notification message about creating dialog. Required fields:

  <notification_type>1</notification_type>
    <dialog_id> 5ac2324ea28f9a3151ecb5dc </dialog_id>
    <room_name>@shaharukhs</room_name>
    <room_updated_date>1522739811</room_updated_date>
    <type>2</type>
    <current_occupant_ids>1,2,3,4,5,6,7,8</current_occupant_ids>
    <date_sent>1522739810</date_sent>

Thanks.

ghost commented 6 years ago

@shaharukhs, if you will have any other problems or questions please let us know by creating a separate issue.

Thanks!