logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Pin a conversation


Introduction

Pinning conversations refers to fixing one-on-one or group chat conversations at the top of the conversation list, preventing them from being pushed to the bottom by other non-pinned conversations, and making it easier for users to find them. When users pin a conversation through the client, the pinned status is stored on the server. Therefore, when users switch to another device, the pinned status will be synchronized to the current device.

ZIM supports users to pin conversations and query the pinned conversation list

Note
  • Pinned conversations are only supported in ZIM SDK version 2.8.0 or above.
  • The maximum limit for pinned conversations is 100.
  • Pinned conversations are always placed before unpinned conversations.

    Note

    This rule also applies to the conversation list fetched by calling the queryConversationList interface. Developers can confirm whether a conversation is pinned by checking the isPinned field of the ZIMConversation in the fetched results.

  • After a user pins multiple conversations, the relative order between these conversations will remain unchanged.
    Let's assume there are 5 conversations, and the existing order in the conversation list is: a, b, c, d, e.
    If the user pins conversations b and d (regardless of the order in which they are pinned), the new order will be b, d, a, c, e. In other words, conversations b and d are placed at the front, and conversation b is still placed before conversation d.

    Note

    The above example assumes that the orderKey of the related conversations remains unchanged before and after pinning. If the orderKey changes, the order in the pinned conversation list will also change.

Pin a conversation

After the login, a user can pin or unpin a conversation in their conversation list by calling the updateConversationPinnedState interface.

Untitled
// Pin a one-on-one conversation
ZIM.getInstance().updateConversationPinnedState(true, "conversationID", ZIMConversationType.peer
    ).then((value){

}).catchError((onError){
    // You can print the error code and error message to troubleshoot the error, please refer to the ZIM official website error code documentation for the error reasons.
});
1
Copied!

Get the pinned conversation list

After the login, a user can use the queryConversationPinnedList interface to get the full list of pinned conversations.

Untitled
ZIMConversationQueryConfig config;
// pass null for the first time to start querying from the latest
config.nextConversation = null;
// Number of pinned conversations to retrieve each time
config.count = 20;
// Fetch the list of pinned conversations

ZIM.getInstance().queryConversationPinnedList(config).then((value) {
    // Callback for the result of getting the list of pinned conversations
}).catchError((onError){
    // You can print the error code and error message to troubleshoot the error cause, refer to the ZIM official website error code documentation
});
1
Copied!

Previous

Delete conversation

Next

Query a conversation