SDKsHarmonyOSEnterprise
Pin or unpin message
Pin or unpin a message within a conversation.
Use pinned to toggle the pinned status of a message.
Code example
import sdk, {
EventOnChangedPinnedMsgData,
OpenIMSDKEvent,
SetConversationPinnedMsgReq,
} from '@openimsdk/imsdk';
const request: SetConversationPinnedMsgReq = {
conversationID: conversationID,
clientMsgID: message.clientMsgID,
pinned: true,
};
await sdk.setConversationPinnedMsg(request);
const handlePinnedMessagesChanged = (data: EventOnChangedPinnedMsgData): void => {
replacePinnedMessageRecords(data.conversationID, data.msgs);
};
const unsubscribePinnedMessages = sdk.on(
OpenIMSDKEvent.EventOnChangedPinnedMsg,
handlePinnedMessagesChanged,
);
export function removePinnedMessageListener(): void {
unsubscribePinnedMessages();
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Target conversation identifier. |
clientMsgID | string | Yes | Client message identifier of the target message. |
pinned | boolean | Yes | Pass true to pin the message; pass false to unpin it. |
Return value
Returns a Promise that resolves to void upon server acceptance.
State changes after the call
Permissions, eligible message types, and maximum pin count limits are verified by OpenIMServer. Resolving the Promise confirms server processing, but does not indicate that the change event has arrived. The msgs property in the event delivers records containing pinner identity, timestamps, and message details. Clients reconcile pinned states using conversationID and clientMsgID. To load initial pinned messages, see Get pinned messages in conversation. Remove listeners when disposing of the state layer.
Was this page helpful?