Skip to main content

Clear Message Unread Status

The ultra group service can synchronize message read status across multiple clients.

Synchronize Message Read Status

Calling the read status synchronization interface will simultaneously clear the unread status of messages recorded both locally and on the server, while the server will synchronize the latest status to other clients logged into the same user account.

  • If a channel ID (channelId) is specified, it marks all messages in that channel as read and synchronizes with other clients.
  • If the channel ID is empty, it marks all messages in the ultra group conversation that do not belong to any channel as read and synchronizes with other clients.
tip

Ultra groups currently do not support timestamp-based read status synchronization. Calling syncUltraGroupReadStatus will mark all messages as read according to the specified parameters. The timestamp parameter (timestamp) is invalid and can be any number.

Interface Prototype

- (void)syncUltraGroupReadStatus:(NSString *)targetId
channelId:(NSString *)channelId
time:(long long)timestamp
success:(void (^)(void))successBlock
error:(void (^)(RCErrorCode errorCode))errorBlock

Parameter Description

ParameterTypeDescription
targetIdNSStringThe targetId of the ultra group conversation.
channelIdNSStringThe channelId of the ultra group conversation channel.
timestamplong longThis field is invalid and can be any number.
successBlockBlockCallback for successful synchronization of message read status.
errorCodeBlockCallback for failed synchronization of message read status.

Example Code

[[RCChannelClient sharedChannelManager] syncUltraGroupReadStatus:@"targetId" channelId:@"channelId" time:0 success:^{

} error:^(RCErrorCode errorCode) {

}];

Monitor Message Read Time

You can set the setRCUltraGroupReadTimeDelegate delegate to listen for ultra group read synchronization notifications:

  1. Set the message read status synchronization delegate after initializing the IMLib SDK but before connecting to IM:
[[RCChannelClient sharedChannelManager] setRCUltraGroupReadTimeDelegate:self];
  1. Implement the method to monitor message read time and listen for read events from other clients:
/**
Ultra group read time synchronization

@param targetId Conversation ID
@param channelId Channel ID
@param readTime Read time (the time when the server clears the unread count)
*/
- (void)onUltraGroupReadTimeReceived:(NSString *)targetId channelId:(NSString *)channelId readTime:(long long)readTime {

}

Timing for Clearing Unread Count

It is recommended to clear the unread count in the conversation UI under the following circumstances:

  • When the conversation UI is about to disappear (viewWillDisappear)
  • When the app returns to the foreground while in the conversation UI
  • When the latest messages have been loaded
tip

After successfully calling syncUltraGroupReadStatus, the firstUnreadMsgSendTime of the local Conversation object will be set to 0. The first unread time stored on the server will also be set to 0, and the stored unread mention message digest list will be cleared.