Skip to main content

Multi-Device Read Status Synchronization

In instant messaging services, a single user account may be logged in across multiple devices. While RC synchronizes message data across devices when Multi-Device Message Synchronization is enabled, the read/unread status of messages in conversations is only stored locally on each device. Therefore, applications may need to synchronize the read/unread status of specified conversations from the user's currently logged-in device to other endpoints.

The IMLib SDK provides a mechanism for synchronizing unread message status across devices for one-to-one and group chats. When one endpoint actively calls the syncConversationReadStatus interface to synchronize message read status, other endpoints can receive the latest unread status data through the conversation status synchronization listener.

tip
  • For SDK versions ≤ 5.6.2, multi-device synchronization of system conversation read status is not supported.
  • Ultra groups use a different mechanism for synchronizing unread message status across devices. For details, refer to the ultra group documentation Clear Unread Message Status.

Actively Synchronize Message Read Status

When logged in on multiple devices, notify other endpoints to synchronize the read status of a specific conversation.

Interface

RongIMClient.getInstance().syncConversationReadStatus(conversationType, targetId, timestamp, callback);

Parameter Description

ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
timestampStringThe timestamp of the last read message in the conversation
callbackRongIMClient.OperationCallbackCallback interface

Example Code

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "Conversation ID";
String timestamp = "12222222";

RongIMClient.getInstance().syncConversationReadStatus(conversationType, targetId, timestamp, new RongIMClient.OperationCallback() {
@Override
public void onSuccess() {
}

@Override
public void onError(RongIMClient.ErrorCode errorCode) {
}
});

Listen for Message Read Status Synchronization Data

The RongIMClient provides a SyncConversationReadStatusListener. Clients must set this listener to receive synchronized read status data from other endpoints.

Interface

RongIMClient.getInstance().setSyncConversationReadStatusListener(listener);

When the IMLib SDK receives read status synchronization data, it triggers the listener's onSyncConversationReadStatus method. The SDK will mark all messages in the specified conversation with timestamps earlier than or equal to the syncConversationReadStatus parameter as read:

onSyncConversationReadStatus(Conversation.ConversationType type, String targetId)

Parameter Description

ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID