Skip to main content

Delete Message

The SDK supports deleting historical messages of one-to-one chats and group chats stored on the RC server directly from the client. You can delete a specific message or a group of messages, or delete messages in a conversation that are older than a specified timestamp.

tip
  • This feature is only applicable to apps whose App Key has enabled Cloud Storage for One-to-One and Group Messages. After enabling the message cloud storage service, user messages will be stored on the RC server (default duration is 6 months).
  • For one-to-one chats and group chats, if you delete remote messages by passing a timestamp through any API, the server will not delete the corresponding offline message compensation by default (this mechanism only takes effect after enabling the Multi-Device Message Synchronization switch). 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 the message compensation, please submit a ticket to apply for enabling deleting multi-device compensation offline messages when deleting server-side historical messages. If you delete remote messages by passing a message object, the server will definitely delete the corresponding message in the message compensation.
  • For one-to-one chats and group chats, 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 message recall function. After a message is successfully recalled, the original message content will be deleted from the local and server-side historical records of all users.
  • The client SDK does not provide an interface for deleting chatroom messages. The local messages of the current user in the chatroom will be automatically deleted when they exit the chatroom. After enabling the chatroom message cloud storage service, if you need to clear the historical messages of all users in the chatroom, you can use the server API Clear Messages.

Delete by Message

Call deleteMessages to delete a specific message or a group of messages from the server in a specified conversation based on the message ID, timestamp, and direction (sent or received).

const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Target User ID>"
}
RongIMLib.deleteMessages(conversation, [
{
messageUId: "BS4O-P5AO-D1O6-9GPP",
sentTime: 1632728405345,
messageDirection: RongIMLib.MessageDirection.SEND
},
{
messageUId: "BS4O-QEBR-VJM6-9GPP",
sentTime: 1632728573423,
messageDirection: RongIMLib.MessageDirection.SEND
}
]).then(res => {
if (res.code === 0) {
console.log('Deletion successful')
} else {
console.log(res.code, res.msg)
}
}).catch(error => {
console.log(error)
})

ParameterTypeDescription
conversationIConversationOptionConversation. Chatrooms are not supported.
messagesMessage ArrayArray of messages to be deleted. See messages Structure Description for details.
  • messages Structure Description

    ParameterTypeDescription
    messageUIdstringMessage UId
    sentTimenumberMessage send time
    messageDirectionMessageDirectionMessage direction

Delete by Timestamp

Call clearHistoryMessages to delete messages older than a specified timestamp from the server in a specified conversation.

const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Target User ID>"
}
RongIMLib.clearHistoryMessages(conversation, <Timestamp>).then(res => {
if (res.code === 0) {
console.log('Clear successful')
} else {
console.log(res.code, res.msg)
}
}).catch(error => {
console.log(error)
})

ParameterTypeDescription
conversationIConversationOptionConversation. Chatrooms are not supported.
timestampnumberTimestamp, messages before this timestamp will be deleted