Skip to main content

Conversation Pinning

Global IM UIKit provides the functionality to pin conversations and display pinned conversations.

Usage

In the conversation list, long-pressing a conversation will reveal the Pin/Unpin button. Clicking it will update the pinned status of the conversation. Once a conversation is pinned, this status will be synchronized with the server. RC automatically synchronizes the pinned conversation status data across devices for the user. The client can receive synchronization notifications through a listener.

alt(width=250) alt(width=250)

Customization

If the default implementation of Global IM UIKit does not meet your needs, you can use the APIs provided by Global IM UIKit.

Pinning a Conversation

After pinning a conversation, it will be displayed at the top of the conversation list page. All pinned conversations are sorted in descending order by conversation time.

IMCenter.getInstance().setConversationToTop(conversationType, targetId, isTop, needCreate, callback);
ParameterTypeDescription
conversationTypeConversationTypeThe type of conversation
targetIdStringThe ID of the conversation
isTopbooleanWhether to pin the conversation. true for pin, false for unpin
needCreatebooleanWhether to create the conversation if it does not exist
callbackResultCallback<Boolean>Callback interface

The client generally generates conversations and conversation lists automatically based on local message data. If the conversation to be pinned does not exist locally, you can create it using the needCreate parameter.

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "Conversation ID";
boolean isTop = true;
boolean needCreate = true;

IMCenter.getInstance().setConversationToTop(conversationType, targetId, isTop, needCreate, new
ResultCallback<Boolean>() {

@Override
public void onSuccess(Boolean success) {

}

@Override
public void onError(RongIMClient.ErrorCode ErrorCode) {

}
}) ;

Listening for Pinned Status Synchronization

The IM service supports a synchronization mechanism for conversation status (pinned status data and Do Not Disturb status data). After setting up a conversation status synchronization listener, if the conversation status changes, the client will receive a notification.

After the pinned and Do Not Disturb status data of a conversation is synchronized, the SDK will trigger the onStatusChanged method of the ConversationStatusListener.

public interface ConversationStatusListener {
void onStatusChanged(ConversationStatus[] conversationStatus);
}

Retrieving Pinned Status and Pinned Conversations

You can actively retrieve the pinned status data and pinned conversations from the client, but the Global IM UIKit SDK does not directly provide related methods. You need to use the methods provided in IMLib.

For more details, refer to the IMLib documentation on Conversation Pinning under Retrieving Pinned Status and Retrieving Pinned Conversation List.