Delete Conversation
IMKit provides a default operation menu popup with delete functionality in the conversation long-press event.
If the existing implementation doesn't meet your requirements, you can use the delete conversation API provided by IMCenter:
Delete Specified Conversation
Removes a conversation item from the conversation list without deleting its historical messages. This method automatically triggers a refresh of the conversation list page.
Interface
IMCenter.getInstance().removeConversation(conversationType, targetId, callbalk);
Parameters
Parameter | Type | Description |
---|---|---|
conversationType | ConversationType | Conversation type |
targetId | String | Conversation ID |
callback | ResultCallback<Boolean> | Callback interface |
Sample Code
ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "conversation ID";
IMCenter.getInstance().removeConversation(conversationType, targetId, new ResultCallback<Boolean>() {
@Override
public void onSuccess(Boolean success) {
}
@Override
public void onError(RongIMClient.ErrorCode errorCode) {
}
});
This method only removes the conversation item from the list without deleting historical message data. When new messages arrive for this conversation, the system will automatically recreate the conversation list item. To permanently delete conversation data, you must simultaneously call the message deletion API to clear both local and server-side message records. For details, see Delete Messages.
Delete Conversations by Type
Deletes all conversations of specified types from the local database, including their messages. IMKit doesn't provide a "clear all conversations" method—you can achieve this by passing all types you want to delete. This method automatically triggers a refresh of the conversation list page.
Conversation.ConversationType[] mConversationTypes = {
Conversation.ConversationType.PRIVATE,
Conversation.ConversationType.GROUP
};
IMCenter.getInstance().clearConversations(new RongIMClient.ResultCallback() {
@Override
public void onSuccess(Object object) {
}
@Override
public void onError(RongIMClient.ErrorCode errorCode) {
}
}, mConversationTypes);
Parameter | Type | Description |
---|---|---|
callback | ResultCallback | Callback for operation success |
conversationTypes | ConversationType... | List of conversation types to clear |