Delete saved messages
Batch delete messages in a conversation with optional two-way synchronization using the OpenIM React Native SDK.
Batch delete multiple messages from a designated conversation:
await OpenIMSDK.deleteMessages({
conversationID,
clientMsgIDs,
isSync: true,
});Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Conversation ID containing the messages to delete. |
clientMsgIDs | string[] | Yes | Array of client message IDs to delete; all must belong to the specified conversation. |
isSync | boolean | Yes | Whether to synchronize deletion to the counterparty. When true, messages are deleted for both participants; when false, messages are deleted only for the current account. |
Return value
A resolved Promise confirms that the message deletion request was processed on the server.
When isSync is true, the deletion synchronizes to counterparties; when false, it applies only to the current account. Regardless of the setting, deletions are automatically propagated to other active devices logged into the current account.
Listen for message deletion
When messages are deleted, the SDK emits the OnMsgDeleted event carrying the deleted MessageItem. Remove the corresponding entry from the active conversation view using clientMsgID.
const handleMessageDeleted = (message: MessageItem) => {
// Remove message from the active conversation list by message.clientMsgID
};
// Register listener
OpenIMSDK.on(OpenIMEvent.OnMsgDeleted, handleMessageDeleted);
// Unregister listener on cleanup
OpenIMSDK.off(OpenIMEvent.OnMsgDeleted, handleMessageDeleted);Always unregister listeners using identical function references when unmounting components or signing out.
Was this page helpful?