Skip to main content

Delete Conversation

Delete Specified Conversation

Delete a specified conversation by calling the [removeConversation] method.

tip
  • Starting from version 5.26.0, this interface can be used to delete ultra group conversations.
  • Starting from version 5.26.2, the deleteRemotely parameter has been added, which can be used to synchronously delete conversation data from remote servers on Electron platforms.

Parameter Description

ParameterTypeRequiredDescription
conversation[IConversationOption]YesTarget conversation
deleteRemotelyBooleanNoWhether to synchronously delete the conversation from the remote server. Only effective on Electron platforms. Supported since version 5.26.2.

Example Code

const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: 'Recipient's userId',
}

RongIMLib.removeConversation(conversation).then(res => {
// Successfully deleted specified conversation
if(res.code === 0){
console.log(res.code)
} else {
console.log(res.code, res.msg)
}
})


## Batch Delete Conversations

SDK version 5.26.0 introduced the [batchDeleteConversations] interface, which can be used to batch delete local/remote conversations and their historical messages.


### Parameter Description

| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| params | [ConversationBatchDeletionParams] | Yes | |


### Example Code

```js
const params = {
identifiers: [
{
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: '<Target Conversation ID>'
},
{
conversationType: RongIMLib.ConversationType.GROUP,
targetId: '<Target Conversation ID>'
},
],
deleteRemotely: true, // On non-Electron platforms where local data isn't stored, this parameter is invalid. The SDK will delete server-side conversations
deleteMessages: false, // Whether to synchronously delete historical messages in the conversation
};

RongIMLib
.batchDeleteConversations(params)
.then(res => {
if (res.isOk) {
console.log('Deletion successful!')
} else {
console.log('Deletion failed:', res.code, res.msg)
}
})
<!-- links -->
[removeConversation]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#removeConversation
[IConversationOption]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#IConversationOption
[ConversationBatchDeletionParams]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/interfaces/ConversationBatchDeletionParams.html
[batchDeleteConversations]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#batchDeleteConversations