logo
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
var isPinned = true;
var conversationID = "";
var conversationType = 0;
zim.updateConversationPinnedState(isPinned, conversationID, conversationType)
    .then(function(res){
        // Operation succeeded
    })
    .catch(function(err){
        // Operation failed
    })
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
var config = {
    // No need to pass in for the first query
    nextConversation: null,
    // The number of pinned conversations to retrieve each time
    count: 20
};

// Get the pinned
 conversation list
zim.queryConversationPinnedList(config)
    .then(function({ conversationList }){
        // Operation succeeded, you should save and manage the conversation objects in the array 
    })
    .catch(function(err){
        // Operation failed
    })
1
Copied!

Previous

Delete conversation

Next

Query a conversation