Delete Messages
Participants in one-to-one chat and group chat conversations can delete messages within the conversation. You can delete a specific message or a set of messages, clear the entire message history of a conversation, or delete messages older than a specified timestamp.
Once messages are delivered, they are directly stored in the local database. You can call the API to delete messages from the local database. Messages are only deleted from the local database and will not be affected on the server side. If you have enabled the message cloud storage service, you can still retrieve historical messages from the server.
- By default, messages in one-to-one chat, group chat, and system conversations for App users are only stored 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 messages can be deleted from the remote historical message records.
- For one-to-one chat and group chat, 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 a different 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 offline message compensation for multiple devices 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 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 API to delete chatroom messages. The current user's local chatroom messages 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 Specified Message Collection
You can delete a specific message or a set of messages from the local database. This method only requires providing the array of message IDs to be deleted, regardless of the conversation type.
Method
deleteLocalMessages(
messages: Array<RCIMIWMessage>,
callback: IRCIMIWDeleteLocalMessagesCallback
): Promise<number>;
Parameter Description
Parameter | Type | Description |
---|---|---|
messages | Array<RCIMIWMessage> | Message collection |
callback | IRCIMIWDeleteLocalMessagesCallback | Callback for the API call result. |
Return Value
Return Value | Description |
---|---|
number | Status code of the current API operation. 0 indicates a successful call. The specific result needs to be implemented in the callback. Non-zero indicates that the current API call operation failed and the callback will not be triggered. Refer to the error code for detailed errors. |
Code Example
const callback = {
onLocalMessagesDeleted: (code: number, messages: Array<RCIMIWMessage>) => {
//...
},
};
let code = await engine.deleteLocalMessages(messages, callback);
Delete Specified Message Collection in a Conversation
This method will delete both local and remote messages.
Note
Only applications that have enabled the cloud storage service for one-to-one and group messages can perform this operation. You can go to the Console to enable the service.
Method
deleteMessages(
type: RCIMIWConversationType,
targetId: string,
channelId: string,
messages: Array<RCIMIWMessage>,
callback: IRCIMIWDeleteMessagesCallback
): Promise<number>;
Parameter Description
Parameter | Type | Description |
---|---|---|
type | RCIMIWConversationType | Conversation type |
targetId | string | Conversation ID |
channelId | string | Channel ID, only supported for ultra groups. For other conversation types, pass null. |
messages | Array<RCIMIWMessage> | Message collection |
callback | IRCIMIWDeleteMessagesCallback | Callback for the API call result. |
Return Value
Return Value | Description |
---|---|
number | Status code of the current API operation. 0 indicates a successful call. The specific result needs to be implemented in the callback. Non-zero indicates that the current API call operation failed and the callback will not be triggered. Refer to the error code for detailed errors. |
Code Example
const callback = {
onMessagesDeleted: (code: number, messages: Array<RCIMIWMessage>) => {
//...
},
};
let code = await engine.deleteMessages(type, targetId, channelId, messages, callback);
Clear Messages in a Conversation by Timestamp
When deleting remote messages, only applications that have enabled the cloud storage service for one-to-one and group messages can perform this operation. You can go to the Console to enable the service.
Method
clearMessages(
type: RCIMIWConversationType,
targetId: string,
channelId: string,
timestamp: number,
policy: RCIMIWMessageOperationPolicy,
callback: IRCIMIWClearMessagesCallback
): Promise<number>;
Parameter Description
Parameter | Type | Description |
---|---|---|
type | RCIMIWConversationType | Conversation type |
targetId | string | Conversation ID |
channelId | string | Channel ID, only supported for ultra groups. For other conversation types, pass null. |
timestamp | number | Timestamp for clearing messages. timestamp must be greater than or equal to 0 and less than or equal to the sentTime of the last message in the current conversation. 0 clears all messages, other values clear messages less than or equal to recordTime. |
policy | RCIMIWMessageOperationPolicy | Clear policy |
callback | IRCIMIWClearMessagesCallback | Callback for the API call result. |
Return Value
Return Value | Description |
---|---|
number | Status code of the current API operation. 0 indicates a successful call. The specific result needs to be implemented in the callback. Non-zero indicates that the current API call operation failed and the callback will not be triggered. Refer to the error code for detailed errors. |
Code Example
const callback = {
onMessagesCleared: (code: number) => {
//...
},
};
let code = await engine.clearMessages(type, targetId, channelId, timestamp, policy, callback);