Message pinned to top
Introduction
To use this feature, please subscribe to the Enterprise plan.
ZIM SDK supports adding specific messages to the pinned message list in a conversation, and conversation members can query messages in the pinned message list at any time. This feature can be used to pin important messages at the top of the conversation for quick viewing by conversation members.
Listen for message pinned status changes
Conversation members register on to listen for messagePinStatusChanged callbacks to receive notifications of message pinned status changes. When other users pin messages, they can obtain information such as the status change, pinned time, and pinned operator of the pinned messages through this notification.
// 注册事件
zim.on('messagePinStatusChanged', (zim: ZIM, data: ZIMEventOfMessagePinStatusChangedResult) => {
// When the message pinned status changes, the pinned message/unpinned message can be obtained here to refresh the UI
})Pinned messages
Conversation members can call pinMessage to pin messages sent successfully in a conversation. The supported message types are as follows:
| Message type | Description |
|---|---|
| ZIMTextMessage | Text message |
| ZIMMultipleMessage | Multiple message |
| ZIMImageMessage | Image message |
| ZIMFileMessage | File message |
| ZIMAudioMessage | Audio message |
| ZIMVideoMessage | Video message |
| ZIMCombineMessage | Combined message |
| ZIMCustomMessage | Custom message |
After a message is pinned, the result of the pinned operation can be obtained through ZIMMessagePinnedResult interface. When there is a pinned message in a conversation, conversation members can call queryPinnedMessageList to query the pinned message, and obtain the pinned message list through ZIMPinnedMessageListQueriedResult .
- Message pinned to top only supports calling in one-on-one and group chat conversations.
- Each conversation only supports supporting up to ten messages. When trying to pin the eleventh message, the message with the earliest pinned time will be automatically unpinned.
- Repeating the pinning of the same message will update its pinned time.
- The pinnedUserID and pinnedTime fields in the ZIMMessage message object are only returned in ZIMPinnedMessageListQueriedResult and messagePinStatusChanged .
- Whether group pinned/unpinned actions trigger group Tips messages can be configured in the backend (by default, push is not enabled). When the push is enabled, if a message in a group chat is pinned or unpinned, group members will receive a related pinned message Tips notification, such as: "XXX pinned a message to the top". For more information, see Receive tip messages.
// Pin a text message
const messageObj: ZIMMessage = {}; // Get from queryHistoryMessage interface
zim.pinMessage(messageObj, true)
.then((res: ZIMMessagePinnedResult) {
// The operation is successful
})
.catch((err: ZIMError) => {
// The operation failed
});
zim.queryPinnedMessageList(conversationID, conversationType)
.then((res: ZIMMessagePinnedListQueriedResult) {
// Get the pinned message list from here
})
.catch((err: ZIMError) => {
// The operation failed
});