Browse SDKs · React Native
SDKsReact NativeEnterprise

Delete messages in a batch

OpenIM React Native SDK guide for delete messages in a batch.

Copy

Use deleteMessages() to delete multiple messages from one conversation.

await OpenIMSDK.deleteMessages({
  conversationID,
  clientMsgIDs,
  isSync: true,
});

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesConversation containing the messages.
clientMsgIDsstring[]YesIDs of the messages to delete; all must belong to the same conversation.
isSyncbooleanYesWhether to synchronize deletion to the other participant. true deletes the messages for both participants; false deletes them only for the current account. In either case, the deletion is synchronized to the current account's other devices.

After the call completes, the deletion request has completed. With isSync: true, the other participant also deletes the messages; with false, only the current account deletes them.

Listen for message deletion

When messages are deleted, OnMsgDeleted is emitted with the deleted MessageItem. Use clientMsgID to update the corresponding message list.

function handleMessageDeleted(message) {
  // ...
}

// Set the listener
OpenIMSDK.on(OpenIMEvent.OnMsgDeleted, handleMessageDeleted);

// Remove the listener
OpenIMSDK.off(OpenIMEvent.OnMsgDeleted, handleMessageDeleted);

Remove the listener when the component is destroyed, the account signs out, or the account changes.