Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Set periodic server message destruction

Enable, disable, and configure the periodic message destruction window on the server for a conversation.

Copy

Configure server-side retention policies to automatically delete aged messages from server stores after a specific expiration window:

Code example

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

const request: SetConversationReq = {
  conversationID: conversationID,
  isMsgDestruct: true,
  msgDestructTime: 3600,
};
await sdk.setConversation(request);

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesTarget conversation identifier.
isMsgDestructbooleanYesSet to true to enable automatic destruction; set to false to disable.
msgDestructTimenumberYesRetention window in seconds before messages are purged on the server.

Return value

Returns a Promise that resolves to void when the policy is applied.

State changes after the call

Set isMsgDestruct: false to disable server destruction. This setting deletes messages from server storage only; it does not purge messages already downloaded and cached locally on existing devices. Once deleted from the server, messages cannot be synchronized to newly installed devices or after clearing local caches. After the Promise resolves, the SDK emits EventOnConversationChanged. Match the item by conversationID and update isMsgDestruct and msgDestructTime, as detailed in Retrieve conversation list.