Skip to main content
Quick Reference for AI Agents & Developers
In case you want to delete a conversation, you can use the deleteConversation() method. This method takes two parameters. The unique id (UID/GUID) of the conversation to be deleted & the type (user/group) of conversation to be deleted.

Delete User Conversation

CometChat.deleteConversation(conversationWith: "cometchat-uid-1", conversationType: .user, onSuccess: { (message) in
    print("Conversation deleted: \(message)")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
Method: CometChat.deleteConversation(conversationWith:conversationType:)
ParameterTypeValue
conversationWithString"cometchat-uid-1"
conversationTypeCometChat.ConversationType.user

Delete Group Conversation

CometChat.deleteConversation(conversationWith: "group-guid-1", conversationType: .group, onSuccess: { (message) in
    print("Conversation deleted: \(message)")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
Method: CometChat.deleteConversation(conversationWith:conversationType:)
ParameterTypeValue
conversationWithString"group-guid-1"
conversationTypeCometChat.ConversationType.group
This method deletes the conversation only for the logged-in user. To delete a conversation for all the users of the conversation, please refer to our REST API documentation here.

Method Parameters

The deleteConversation() method takes the following parameters:
ParameterTypeRequiredDescription
conversationWithStringYESUID of user or GUID of group
conversationTypeCometChat.ConversationTypeYES.user or .group
onSuccess(String) -> VoidYESSuccess callback
onError(CometChatException?) -> VoidYESError callback

Success & Failure Responses

Delete Conversation Success Response

When a conversation is successfully deleted, the onSuccess callback returns a success message:
CometChat.deleteConversation(conversationWith: "cometchat-uid-1", conversationType: .user, onSuccess: { (message) in
    // message: String - Success confirmation message
    print("Response: \(message)")  // "Conversation deleted successfully."
    
    // After deletion:
    // - Conversation removed from logged-in user's conversation list
    // - Messages are deleted for the logged-in user only
    // - Other participants still have access to the conversation
}, onError: { (error) in
    // Handle error
})

Delete Conversation Failure Response

When deletion fails, the onError callback returns a CometChatException:
CometChat.deleteConversation(conversationWith: "cometchat-uid-1", conversationType: .user, onSuccess: { (message) in
    // Success
}, onError: { (error) in
    print("Error Code: \(error?.errorCode ?? "")")
    print("Error Description: \(error?.errorDescription ?? "")")
    
    // Handle specific errors
    switch error?.errorCode {
    case "ERR_CONVERSATION_NOT_FOUND":
        // Conversation does not exist
        break
    case "ERR_UID_NOT_FOUND":
        // User with specified UID does not exist
        break
    case "ERR_GROUP_NOT_FOUND":
        // Group with specified GUID does not exist
        break
    case "ERR_NOT_LOGGED_IN":
        // User is not logged in
        break
    default:
        break
    }
})

After Deletion

EffectDescription
Conversation removedFor logged-in user only
Messages deletedFor logged-in user only
Other participantsStill have access

Common Error Codes

Error CodeDescriptionResolution
ERR_CONVERSATION_NOT_FOUNDConversation doesn’t existVerify conversation exists
ERR_UID_NOT_FOUNDUser UID doesn’t existVerify user UID
ERR_GROUP_NOT_FOUNDGroup GUID doesn’t existVerify group GUID
ERR_NOT_LOGGED_INUser is not logged inLogin first