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, delete the entire message history of a conversation, or delete messages in a conversation that are older than a specified timestamp.
Once a message is delivered, it is 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; messages stored on the server remain unaffected. If you have enabled the historical 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 of 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 for 6 months) and 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 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, 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 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. Once 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 for deleting chatroom messages. The local messages of the current user's chatroom are automatically deleted when the user exits the chatroom. If chatroom message cloud storage service is enabled, you can use the server API Clear Messages to clear the historical messages of all users in the chatroom.
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
Future<int> deleteLocalMessages(List<RCIMIWMessage> messages, {IRCIMIWDeleteLocalMessagesCallback? callback});
Parameter Description
Parameter | Type | Description |
---|---|---|
messages | List<RCIMIWMessage> | A list of messages |
callback | IRCIMIWDeleteLocalMessagesCallback | Event callback. The SDK supports callback mode from version 5.3.1. Other callback methods for this interface are deprecated from version 5.4.0. If the callback parameter is passed, only the callback will be triggered. |
Return Value
Return Value | Description |
---|---|
Future<int> | The status code of the current API operation. 0 indicates a successful call, and the specific result needs to be implemented in the interface callback. Non-zero indicates that the current API call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes. |
Code Example
IRCIMIWDeleteLocalMessagesCallback? callback = IRCIMIWDeleteLocalMessagesCallback(onLocalMessagesDeleted: (int? code, List<RCIMIWMessage>? messages) {
//...
});
int? ret = await engine?.deleteLocalMessages(messages, callback:callback);
Callback Method
- onLocalMessagesDeleted
Function(int? code, List<RCIMIWMessage>? messages)? onLocalMessagesDeleted;
Parameter Description
Parameter | Type | Description |
---|---|---|
code | int | The status code of the interface callback. 0 indicates success, non-zero indicates an exception. |
messages | List<RCIMIWMessage> | The collection of deleted messages |
Code Example
engine?.onLocalMessagesDeleted = (int? code, List<RCIMIWMessage>? messages) {
//...
};
Delete Specified Message Collection in a Conversation
This method deletes both local and remote messages.
Only applications that have enabled the single and group chat message cloud storage service can perform this operation. You can go to the Console to enable the service.
Method
Future<int> deleteMessages(RCIMIWConversationType type, String targetId, String? channelId, List<RCIMIWMessage> messages, {IRCIMIWDeleteMessagesCallback? callback});
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 | List<RCIMIWMessage> | A list of message |
callback | IRCIMIWDeleteMessagesCallback | Event callback. The SDK supports callback mode from version 5.3.1. Other callback methods for this interface are deprecated from version 5.4.0. If the callback parameter is passed, only the callback will be triggered. |
Return Value
Return Value | Description |
---|---|
Future<int> | The status code of the current API operation. 0 indicates a successful call, and the specific result needs to be implemented in the interface callback. Non-zero indicates that the current API call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes. |
Code Example
IRCIMIWDeleteMessagesCallback? callback = IRCIMIWDeleteMessagesCallback(onMessagesDeleted: (int? code, List<RCIMIWMessage>? messages) {
//...
});
int? ret = await engine?.deleteMessages(type, targetId, channelId, messages, callback:callback);
Callback Method
-
onMessagesDeleted
Interface call result listener
Function(int? code, RCIMIWConversationType? type, String? targetId, String? channelId, List<RCIMIWMessage>? messages)? onMessagesDeleted;
Parameter Description
Parameter | Type | Description |
---|---|---|
code | int | The status code of the interface callback. 0 indicates success, non-zero indicates an exception. |
type | RCIMIWConversationType | Conversation type |
targetId | String | Conversation ID |
channelId | String | Channel ID, only supported for ultra groups. For other conversation types, pass null. |
messages | List<RCIMIWMessage> | The collection of deleted messages |
Code Example
engine?.onMessagesDeleted = (int? code, RCIMIWConversationType? type, String? targetId, String? channelId, List<RCIMIWMessage>? messages) {
//...
};
Clear Messages in a Conversation by Timestamp
When deleting remote messages, only applications that have enabled the single and group chat message cloud storage service can perform this operation. You can go to the Console to enable the service.
Method
Future<int> clearMessages(RCIMIWConversationType type, String targetId, String? channelId, int timestamp, RCIMIWMessageOperationPolicy policy, {IRCIMIWClearMessagesCallback? callback});
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 | int | The timestamp for clearing messages. recordTime 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 | Event callback. The SDK supports callback mode from version 5.3.1. Other callback methods for this interface are deprecated from version 5.4.0. If the callback parameter is passed, only the callback will be triggered. |
Return Value
Return Value | Description |
---|---|
Future<int> | The status code of the current API operation. 0 indicates a successful call, and the specific result needs to be implemented in the interface callback. Non-zero indicates that the current API call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes. |
Code Example
IRCIMIWClearMessagesCallback? callback = IRCIMIWClearMessagesCallback(onMessagesCleared: (int? code) {
//...
});
int? ret = await engine?.clearMessages(type, targetId, channelId, timestamp, policy, callback:callback);
Callback Method
-
onMessagesCleared
Interface call result listener
Function(int? code, RCIMIWConversationType? type, String? targetId, String? channelId, int? timestamp)? onMessagesCleared;
Parameter Description
Parameter | Type | Description |
---|---|---|
code | int | The status code of the interface callback. 0 indicates success, non-zero indicates an exception. |
type | RCIMIWConversationType | Conversation type |
targetId | String | Conversation ID |
channelId | String | Channel ID, only supported for ultra groups. For other conversation types, pass null. |
timestamp | int | Timestamp |
Code Example
engine?.onMessagesCleared = (int? code, RCIMIWConversationType? type, String? targetId, String? channelId, int? timestamp) {
//...
};