Skip to main content

Multi-End Synchronization for Do Not Disturb and Pinning

The SDK provides a synchronization mechanism for conversation status (pinned or do not disturb). By setting a conversation status synchronization listener, you can monitor changes in conversation status in real-time on this end when modifications are made on other ends.

tip

Before version 5.10.0, there might be inaccuracies in the unread message count. It is recommended to use version 5.10.0 or higher.

Listener Description

The RongIMClient provides a ConversationStatusListener listener. After setting the listener, the following method will be triggered when the conversation status (pinned or do not disturb) changes:

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

The onStatusChanged method returns a list of conversationStatus with the following parameters:

ParameterTypeDescription
conversationTypeConversationTypeThe type of conversation.
targetIdStringThe conversation ID.
isTopbooleanWhether the conversation is set as pinned.
levelPushNotificationLevelThe do not disturb level of the conversation. The SDK supports multi-end synchronization of do not disturb levels starting from version 5.2.5. For specific level descriptions, refer to the Do Not Disturb Function Overview.
notificationStatusConversationNotificationStatusThe conversation notification status. Only supports two states: notify (1) or do not disturb (0).

Setting the Listener

Set the multi-end synchronization listener for conversation status (pinned and do not disturb).

// Synchronization listener
RongIMClient.ConversationStatusListener listener = new RongIMClient.ConversationStatusListener() {
@Override
public void onStatusChanged(ConversationStatus[] conversationStatus) {
if (conversationStatus == null) {
return;
}
for (ConversationStatus status : conversationStatus) {
Conversation.ConversationType conversationType = status.getConversationType(); // Get the conversation type
String targetId = status.getTargetId(); // Get the conversation ID
boolean isTop = status.isTop(); // Get whether the conversation is currently pinned
IRongCoreEnum.PushNotificationLevel level = status.getNotificationLevel(); // Get PushNotificationLevel (added in 5.2.5)
Conversation.ConversationNotificationStatus notificationStatus = status.getNotifyStatus(); // Get the current do not disturb status of the conversation.
}
}
};
RongIMClient.getInstance().setConversationStatusListener(listener); // Set the listener