Skip to main content

Delete Conversation

App users may need to delete one or more conversations from the conversation list, which can be achieved through the SDK's delete conversation feature. The client's conversation list is generated based on local messages, and deleting a conversation refers to deleting the local conversation.

Delete a Specific Conversation

Calling removeConversation achieves a soft delete effect. This interface does not actually delete the messages within the conversation but only removes the conversation item from the SDK's conversation list. After successfully deleting the conversation, the App can refresh the UI to no longer display the conversation item to the user.

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "conversation ID";

RongIMClient.getInstance().removeConversation(conversationType, targetId, new ResultCallback<Boolean>() {

@Override
public void onSuccess(Boolean success) {

}

@Override
public void onError(RongIMClient.ErrorCode errorCode) {

}
});
ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
callbackResultCallback<Boolean>Callback interface

If a new message arrives in the conversation, the conversation will reappear in the conversation list, and the App user can view the historical and latest messages within the conversation.

The SDK does not provide an interface to simultaneously delete a specific conversation item and its historical messages. If you need to delete the messages within the conversation at the same time, you can call the delete message interface while deleting the specified conversation. For details, see Delete Messages.

Delete Conversations by Type

App users may need to clear all conversations of a certain type, such as clearing all group chat conversations. The SDK supports clearing all conversations and conversation information of a specified type, and it can clear multiple types of conversations at once.

Conversation.ConversationType[] mConversationTypes = {
Conversation.ConversationType.PRIVATE,
Conversation.ConversationType.GROUP
};

RongIMClient.getInstance().clearConversations(new RongIMClient.ResultCallback() {

@Override
public void onSuccess(Object object) {

}

@Override
public void onError(RongIMClient.ErrorCode errorCode) {

}, mConversationTypes);
ParameterTypeDescription
callbackResultCallbackCallback for whether the conversation was successfully removed
conversationTypesConversationType...List of conversation types to be cleared.

This interface only clears the messages in the local database of the current user's device. If the App has enabled the Cloud Storage for One-to-One and Group Messages service, the historical message records of the user stored on the server will not be affected. If the user retrieves historical messages from the server, they may retrieve messages that have been deleted locally. If you need to delete the historical messages of the conversation on the server at the same time, you can call the delete message interface after deleting the conversation. For details, see Delete Messages.

Delete All Conversations

The SDK does not have a method to clear all conversations internally. If needed, you can achieve this through either of the following methods:

  • If the App does not involve ultra group business, you can use Delete Conversations by Type and pass in all conversation types. This method will clear local messages.
  • First, retrieve the conversation list, then loop through and delete each specified conversation.