Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app xEnterprise

Delete saved messages

Batch delete multiple messages from a conversation and listen for synchronization events across devices.

Copy

Batch deleting messages is a Commercial Edition capability. All messages specified in a single call must belong to the exact same conversation.

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesIdentifier of the conversation containing the target messages.
clientMsgIDsstring[]YesArray of clientMsgID values belonging to this conversation.
IsSyncbooleanYesWhether to synchronize the deletion across other devices logged into the current account; note the PascalCase capitalization.

Code example

import { deleteMessages } from '@/uni_modules/unix-openim-sdk'

await deleteMessages({
  conversationID,
  clientMsgIDs: selectedMessageIDs,
  IsSync: true,
})

Passing IsSync: false deletes the records from the local device and server for the current account. Passing IsSync: true additionally dispatches deletion notifications to other client instances logged into the same account. It does not delete message copies stored by other chat participants or create a revocation notice.

Return value

The Promise resolves with void upon successful completion.

Listen for synchronized message deletions

Centrally subscribe to onMsgDeleted to handle synchronized message deletions. The callback directly receives the deleted OpenIMMessageItem | null object. Determine the owning conversation and remove the item from local state using conversationID:clientMsgID. Duplicate event deliveries should be handled idempotently.

import {
  OpenIMMessageItem,
  off,
  onMsgDeleted,
} from '@/uni_modules/unix-openim-sdk'

const handleMessageDeleted = (message: OpenIMMessageItem | null) => {
  if (message == null || message.clientMsgID == null) return

  const messageConversationID = resolveMessageConversationID(message)
  removeMessage(messageConversationID, message.clientMsgID)
}

const messageDeletedSubscription = onMsgDeleted(handleMessageDeleted)

function removeMessageDeletedListener() {
  off(messageDeletedSubscription)
}

Unregister the listener when unmounting the view, logging out, or switching accounts. To calibrate message state after network reconnects, re-query the conversation's history list.