Skip to main content

Delete Messages (Electron)

This document is only applicable to the Electron solution and is limited to use with the Electron modules (@rongcloud/electron and @rongcloud/electron-renderer).

tip
  • Messages from one-to-one chat, group chat, and system conversation for App users are stored by default only in the local database and can only be deleted locally. If the App (App Key/environment) has enabled Cloud Storage for One-to-One and Group Messages, the user's messages will also be stored on the RC server (default 6 months) and can be deleted from the remote history message records.
  • For one-to-one chat and group chat, if the remote message is deleted by passing a timestamp through any interface, the server will not delete the corresponding offline message compensation by default (this mechanism only takes effect after enabling Multi-Device Message Synchronization). In this case, if you log in on another device or reinstall the app, you may still receive the deleted historical messages due to the message compensation mechanism. To completely delete message compensation, please submit a ticket to apply for enabling Delete server-side historical messages and simultaneously delete multi-device offline message compensation. If the remote message is deleted by passing the message object, the server will definitely delete the corresponding message in the message compensation.
  • For one-to-one chat and group chat, if an App administrator or a regular user wants to completely delete a message from the historical records of all conversation participants, they should use the recall message function. After the message is successfully recalled, the original message content will be deleted from the local and server-side historical message records of all users.
  • The client SDK does not provide an interface to delete chatroom messages. The local chatroom messages of the current user will be automatically deleted when they exit the chatroom. After enabling the Cloud Storage for Chatroom Messages service, if you need to clear the historical messages of all users in the chatroom, you can use the server API Clear Messages.

This document describes how to delete local messages on the client.

Delete by Conversation

tip

This interface is supported starting from SDK 5.4.0.

Call electronExtension.clearMessages to delete all messages of a specified conversation from the local message database.

const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Target User ID>"
}
RongIMLib.electronExtension.clearMessages(conversation).then(res => {
if (res.code === 0) {
console.log('Successfully cleared messages in this conversation');
} else {
console.log(res.code, res.msg);
}
}).catch(error => {
console.log(error)
})
ParameterTypeDescription
conversationIConversationOptionConversation

Delete by Timestamp

tip

This interface is supported starting from SDK 5.4.0.

Call electronExtension.deleteMessagesByTimestamp to delete messages in a single conversation that are older than the specified timestamp from the local message database.

const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Target User ID>"
}
const timestamp = 1632728573423

RongIMLib.electronExtension.deleteMessagesByTimestamp(conversation, timestamp, false).then(res => {
if (res.code === 0) {
console.log('Successfully cleared messages in this conversation');
} else {
console.log(res.code, res.msg);
}
}).catch(error => {
console.log(error)
})
ParameterTypeDescription
conversationIConversationOptionConversation
timestampnumberSpecify to delete messages before this timestamp
cleanSpacebooleanWhether to clean up the disk space used by the data entries
tip

Cleaning up disk space will block the process and take a long time, so it is not recommended. In the case of data erasure, the uncleaned disk space will be reused in subsequent storage operations and will not affect data queries.

Delete by Message ID

tip

This interface is supported starting from SDK 5.4.0.

Call electronExtension.deleteMessages to delete one or a group of specified messages from the local message database by message ID. When deleting multiple messages, ensure that the message IDs belong to the same conversation.

const messageIds = [<messageId>]

RongIMLib.electronExtension.deleteMessages(messageIds).then(res => {
if (res.code === 0) {
console.log('Successfully deleted messages');
} else {
console.log(res.code);
}
}).catch(error => {
console.log(error)
})
ParameterTypeDescription
messageIdsnumber[]Array of message IDs, must belong to the same conversation