Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Clear conversation messages

Purge all messages in a conversation while retaining the conversation entry.

Copy

Clear chat history for a specific conversation while preserving its presence in the conversation list:

Code example

import sdk, { ClearConversationAndDeleteAllMsgReq } from '@openimsdk/imsdk';

const request: ClearConversationAndDeleteAllMsgReq = {
  conversationID: conversationID,
};
await sdk.clearConversationAndDeleteAllMsg(request);

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesTarget conversation identifier.

Return value

Returns a Promise that resolves to void when messages are purged.

State changes after the call

Resolving the Promise purges messages locally. The conversation entry itself remains in the conversation list, and the SDK triggers EventOnConversationChanged to reset its latest message snippet, timestamp, and unread count. Correlate and update your conversation view using conversationID, as detailed in Retrieve conversation list. To remove the conversation entry together with its messages, see Delete conversation and messages.