QuickBlox / quickblox-ios-sdk

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

The operation couldn’t be completed. (com.quickblox.chat error -1002.) #1358

Closed manohar-techahead closed 1 year ago

manohar-techahead commented 1 year ago

I am trying to send message to a particular dialog but I am getting error sometime The operation couldn’t be completed. (com.quickblox.chat error -1002.). I am attaching the dialog detail here along with QBToken

ID:64de08b832eaaf004ded0100

Created At:2023-08-17 11:47:04 +0000

Updated At: 2023-08-17 11:47:04 +0000

Room JID:(null)

name:Kareena Kapoor

photo:(null)

type:3

lastMessage:(null)

lastMessageDate:(null)

occupantIDs:138259703, 138268312

userID:138268312

data:{

"class_name" = "Chat_parameters";

}

unreadMessagesCount:0

lastMessageUserID:0

  lastMessageID:(null)

  "QB-Token" = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NfdHlwZSI6InVzZXJfYWNjZXNzIiwiYXBwbGljYXRpb25faWQiOjEwMTY0MSwiYXVkIjoicWJfY29yZSIsImV4cCI6MTY5MjQyMzIxNCwiaWF0IjoxNjkyMzM2ODE0LCJpc3MiOiJxYl9jb3JlIiwianRpIjoiZTU4NzUzMGYtYTc5Zi00YjQ0LTllNzAtMTQ3MTc5ODFmMGEyIiwibmJmIjoxNjkyMzM2ODEzLCJzdWIiOjEzODI2ODMxMiwidHlwIjoiYWNjZXNzIn0.42MFDZLEb29TEbu0O4R-fb0p6wfObpt4rQ5gSYGSXJdKdTTu0xZ9GGhwlqVQ8c9iVaqV6bD2EFpUjwhVIMBxPA"
IlliaChemolosov commented 1 year ago

Hello @manohar-techahead,

If you encounter Error Code 404 with the message "The operation could not be completed," it typically arises when the dialog.join() method is improperly utilized. To prevent this error, we suggest reviewing the following steps:

  1. Avoid Multiple Calls: Ensure that you refrain from invoking the dialog.join() method multiple times in quick succession. To address this, you can employ a check using the dialog.isJoined() method.

  2. Check Dialog Type: Verify that you are not attempting to join a private dialog. To do this, confirm that dialog.type is not equal to .private.

  3. Reconnect After Disconnection: If a disconnection occurs, you must reestablish the connection before engaging with the dialogs.

Below is the revised code snippet with the edits:

extension MyClass: QBChatDelegate { }

// MARK: QBChatConnectionProtocol part of QBChatDelegate
extension MyClass: QBChatConnectionProtocol {
    func chatDidConnect() {
        joinAll()
    }

    func chatDidReconnect() {
        joinAll()
    }

    private func joinAll() {
        for dialog in dialogs {
            if dialog.type != .private, !dialog.isJoined() {
                dialog.join()
            }
        }
    }
}

Furthermore, if you encounter Error Code -1002, indicating "You are not connected to chat," this typically indicates a lack of connection to the chat service. To resolve this, ensure that a connection is established using QBChat.instance.isConnected before transmitting a message. Additionally, for both group and private messages, verify that dialog.isJoined() returns true.

Please note that based on your logs, it appears that you might be attempting to join a private dialog of type 3, which could be contributing to the "The operation could not be completed" error.

If you have any more questions or need further assistance, don't hesitate to reach out. Additionally, we'd be thrilled to have you join our QuickBlox Dev Community at https://discord.gg/8D7raPJj. Your presence would be greatly appreciated!