Browse SDKs · WASM
Platform
SDKsWASMEnterprise

Pin or unpin a message

Pin or unpin one message with the WASM SDK.

Copy

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesID of the conversation containing the message.
clientMsgIDstringYesID of the message to pin or unpin.
pinnedbooleanYestrue to pin the message; false to unpin it.
await openimsdk.setConversationPinnedMsg({
  conversationID,
  clientMsgID: message.clientMsgID,
  pinned: true,
});

OpenIMServer validates permissions, message types, and quantity limits. Promise completion means that the pinning request has completed; it does not mean the change event has already arrived.

Listen for SdkEvent.OnChangedPinnedMsg to keep pinned messages synchronized. When an event arrives, match the conversation by conversationID, update its pinned message list, and deduplicate items using item.msg.clientMsgID. Retain the handler reference and pass it to off() during logout, account switching, or component unmounting:

import { SdkEvent } from '@openim/wasm-client-sdk';

const handlePinnedChanged = ({ data }) =>
  replacePinnedMessageDetails(data.conversationID, data.msgs);
openimsdk.on(SdkEvent.OnChangedPinnedMsg, handlePinnedChanged);
const removePinnedListener = () =>
  openimsdk.off(SdkEvent.OnChangedPinnedMsg, handlePinnedChanged);