Multi-Device Read Status Synchronization
In instant messaging services, a single user account may be logged in on multiple devices. While RC synchronizes message data across devices when Multi-Device Message Synchronization service 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.
For IMLib SDK versions ≤ 5.6.2, multi-device synchronization of read status for system conversations is not supported.
Initiating Conversation Read Status Synchronization
Interface Prototype
- (void)syncConversationReadStatus:(RCConversationType)conversationType
targetId:(NSString *)targetId
time:(long long)timestamp
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode nErrorCode))errorBlock;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| conversationType | RCConversationType | Conversation type |
| targetId | NSString | Conversation targetId |
| timestamp | long long | Unix timestamp (in milliseconds) of the last read message |
| successBlock | Block | Success callback |
| errorBlock | Block | Failure callback |
Sample Code
[[RCCoreClient sharedCoreClient] syncConversationReadStatus:ConversationType_PRIVATE targetId:@"targetId" time:1626422416809 success:^{
} error:^(RCErrorCode nErrorCode) {
}];
Receiving Multi-Device Read Status Synchronization Notifications
The IMLib SDK distributes an RCLibDispatchReadReceiptNotification when receiving read status synchronization notifications. At this point, the message status in the database has already been updated to "read". Applications can use this notification to update the conversation UI, marking messages before messageTime as read.
Registering Notification Observer
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(didReceiveReadReceiptNotification:)
name:RCLibDispatchReadReceiptNotification
object:nil];
Implementing Notification Handler
The Notification's object is nil, and userInfo is an NSDictionary object.
- (void)didReceiveReadReceiptNotification:(NSNotification *)notification {
RCConversationType conversationType = (RCConversationType)[notification.userInfo[@"cType"] integerValue];
long long readTime = [notification.userInfo[@"messageTime"] longLongValue];
NSString *targetId = notification.userInfo[@"tId"];
NSString *senderUserId = notification.userInfo[@"fId"];
}
Parameter Description
userInfo object key values:
| Key | Type | Description |
|---|---|---|
| cType | NSNumber | Conversation type |
| messageTime | NSNumber | Message timestamp (messages with timestamps ≤ this value are marked as read) |
| tId | NSString | Conversation targetId |
| fId | NSString | Message senderUserId |