Skip to main content

Delete Conversations

To remove one or multiple conversations from the conversation list, you can use the SDK's conversation deletion feature. The client's conversation list is generated based on local messages, and deleting a conversation refers to removing the local conversation.

Delete a Specific Conversation

Calling removeConversation achieves a soft deletion effect. This interface does not delete 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 this conversation item to users.

Interface

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

Parameter Description

ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
callbackResultCallback<Boolean>Callback interface

Example Code

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) {

}
});

If a new message arrives in the conversation, the conversation will reappear in the conversation list, and App users can view both historical and new 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 both, you must call the message deletion interface while deleting the specified conversation. See Delete Messages for details.

Delete Conversations by Type

To clear all conversations of a specific type (e.g., all group chats), the SDK supports clearing all conversations and their local historical messages for specified conversation types. Multiple conversation types can be cleared at once.

Interface

RongIMClient.getInstance().clearConversations(ResultCallback, mConversationTypes);

Parameter Description

ParameterTypeDescription
callbackResultCallbackCallback indicating whether the conversation removal was successful.
conversationTypesConversationTypeList of conversation types to clear. Ultra groups are not supported.

Example Code

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);

This interface only clears messages stored in the local database on the user's device. If the App has enabled the Cloud Storage for One-to-One and Group Messages service, the historical messages stored on the server remain unaffected. If the user retrieves historical messages from the server, they will receive messages that were deleted locally. To simultaneously delete historical messages from the server, you can call the interface for deleting remote historical messages after deleting the conversation. See Delete Messages for details.

Batch Delete Conversations

Batch delete specified conversations (including local and cloud conversations) from the conversation list based on conversation objects. Supported conversation types: one-to-one chat, group chat, system, ultra group, and official account.

Interface

ChannelClient.getInstance().batchDeleteConversations(params, callback);

Parameter Description

ParameterTypeDescription
paramsConversationBatchDeletionParamsBatch deletion parameters.
callbackOperationCallbackResult callback.

ConversationBatchDeletionParams Attribute Description

ParameterTypeDescription
identifiersList<ConversationIdentifier>List of conversation identifiers (max: 20).
deleteRemotelybooleanWhether to delete remote conversations.
deleteMessagesbooleanWhether to delete all messages in the conversation.

Example Code

List<ConversationIdentifier> identifiers = new ArrayList<>();
identifiers.add(ConversationIdentifier.obtain(Conversation.ConversationType.PRIVATE, "TargetId", ""));
identifiers.add(ConversationIdentifier.obtain(Conversation.ConversationType.GROUP, "TargetId", ""));

ConversationBatchDeletionParams params = new ConversationBatchDeletionParams();
params.setDeleteMessages(true);
params.setDeleteRemotely(false);
params.setIdentifiers(identifiers);

ChannelClient.getInstance().batchDeleteConversations(params, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});

Delete All Conversations

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

  • If your App involves ultra group functionality, you can use Delete Conversations by Type and pass all conversation types. This method clears local messages.
  • Starting from version 5.20.0, clearing ultra group conversations is supported. Ultra group functionality requires submitting a ticket to enable.
  • First, retrieve the conversation list and then loop through to delete specific conversations.