Delete messages in a batch
Delete multiple messages from one conversation for the current account with the WASM SDK.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | ID of the conversation containing the messages to delete. |
clientMsgIDs | string[] | Yes | IDs of the messages to delete. Every ID in one batch must belong to the same conversation. |
isSync | boolean | Yes | Whether to synchronize the deletion to the current account's other clients. |
await openimsdk.deleteMessages({
conversationID,
clientMsgIDs: selectedMessageIDs,
isSync: true,
});With isSync: false, the operation deletes the current device's copy and the current account's server-side record. With true, it also requests deletion synchronization to the account's other clients. It does not delete copies held by other conversation members or display a revocation notice.
Promise completion means that the deletion request has completed. When synchronization is enabled, it does not mean that other clients have already received the event or updated their interfaces.
The complete listener for SdkEvent.OnMsgDeleted is provided on this page. Its data is a MessageItem. Determine the conversation from the message routing fields, then remove the matching message by clientMsgID. Receiving the same deletion event again should not change the list a second time.
import { SdkEvent } from '@openim/wasm-client-sdk';
const handleMessageDeleted = ({ data }) => {
removeMessage(resolveConversationID(data), data.clientMsgID);
};
openimsdk.on(SdkEvent.OnMsgDeleted, handleMessageDeleted);
function removeMessageDeletedListener() {
openimsdk.off(SdkEvent.OnMsgDeleted, handleMessageDeleted);
}Call removeMessageDeletedListener() when the component unmounts, the user logs out, or the active account changes. To confirm the current message list, query the corresponding conversation history again and use the latest result.
Was this page helpful?