Multi-Device Synchronization of Read Status
In instant messaging services, a single user account may be logged in on multiple devices. RC synchronizes message data across multiple devices only when the Multi-Device Message Synchronization service is enabled. However, the read/unread status of messages in conversations on each device is stored locally. Therefore, applications may want to synchronize the read/unread status of a specific conversation on the user's currently logged-in device to other endpoints.
The SDK has designed a mechanism for synchronizing the unread status of messages in one-to-one and group chat conversations across multiple devices. When one device actively calls the syncConversationReadStatus
interface to synchronize the unread status of messages, other devices can listen for the latest data on the unread status of messages in the conversation through the conversation status synchronization listener.
- If the SDK version ≦ 5.6.2, it does not support multi-device synchronization of the read status for system conversations.
Actively Synchronize Message Read Status
When logged in on multiple devices, notify other terminals to synchronize the read status of messages in a specific conversation.
RongIMClient.getInstance().syncConversationReadStatus(conversationType, targetId, timestamp, callback);
Parameter | Type | Description |
---|---|---|
conversationType | ConversationType | Conversation type |
targetId | String | Conversation ID |
timestamp | String | The timestamp of the last read message in the conversation |
callback | RongIMClient.OperationCallback | Callback interface |
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 Synchronized Message Read Status Data
The RongIMClient
provides a SyncConversationReadStatusListener
. The client must set this listener to receive synchronized read status data from other devices.
RongIMClient.getInstance().setSyncConversationReadStatusListener(listener);
When synchronized read status data is received, the following method of the listener is triggered. The SDK will mark all messages in the specified conversation that are earlier than or equal to the timestamp passed in syncConversationReadStatus
as read:
onSyncConversationReadStatus(Conversation.ConversationType type, String targetId)
Parameter | Type | Description |
---|---|---|
conversationType | ConversationType | Conversation type |
targetId | String | Conversation ID |