Skip to main content

Handling Unread Mentions

This document describes how to implement features such as retrieving all unread mentions and navigating to specific unread mentions in ultra group operations.

tip

The functionality for handling unread mentions relies on the unread mention digests data stored by RC's server for ultra group conversations. Digest data for @all messages is stored for a fixed period of 7 days (non-adjustable). Digest data for other types of mentions follows the same retention period as ultra group historical messages.

Retrieving All Unread Mentions

tip

Requires IMLib SDK version ≧ 5.2.5.

The IMLib SDK supports retrieving a list of digest information (MessageDigestInfo) for all unread mentions in a specified ultra group channel from the remote server. You can use this digest information to fetch the complete unread mention messages.

For example, to implement a scenario displaying only unread mentions:

  1. Retrieve unread mention digests for an ultra group channel (maximum 50 items, with count ranging [1-50]). The success callback returns a list of MessageDigestInfo objects, each containing digest information for one unread message. Construct a Message list using these digests, ensuring each message object includes the ConversationType, targetId, channelId, messageUid, and sentTime obtained from MessageDigestInfo.

Sample Code

String targetId = "conversation ID";
String channelId = "channel ID";
long sendTime = 1662542712112L;
int count = 20;

ChannelClient.getInstance().getUltraGroupUnreadMentionedDigests(targetId, channelId, sendTime, count,
new IRongCoreCallback.ResultCallback<List<MessageDigestInfo>>() {
@Override
public void onSuccess(List<MessageDigestInfo> messageDigestInfos) {
List<Message> msgList = new ArrayList<>();
for (MessageDigestInfo info : messageDigestInfos) {
// Use MessageDigestInfo properties to filter mention digests
Message message = new Message();
message.setConversationType(info.getConversationType());
message.setTargetId(info.getTargetId());
message.channelId = info.getChannelId();
message.setUId(info.getMessageUid());
message.setSentTime(info.getSentTime());
// Starting from v5.6.0, MessageDigestInfo includes the message type identifier ObjectName
message.setObjectName(info.getObjectName());
msgList.add(message);
}}

@Override
public void onError(IRongCoreEnum.CoreErrorCode errorCode) {

}});
  1. Use the getBatchRemoteUltraGroupMessages(msgList, callback) method with the constructed message list to batch retrieve complete mention message content from the remote server.

    ChannelClient.getInstance().getBatchRemoteUltraGroupMessages(msgList,
    new IRongCoreCallback.IGetBatchRemoteUltraGroupMessageCallback(
    @Override
    public void onSuccess(List<Message> matchedMsgList, List<Message> notMatchedMsgList) {}

    @Override
    public void onError(IRongCoreEnum.CoreErrorCode errorCode) {}

    ));
tip

Requires SDK version ≧ 5.2.5.

The getUltraGroupUnreadMentionedDigests interface enables navigation to specific mention messages when entering a conversation from the conversation list.

  1. Retrieve unread mention digests for an ultra group channel (maximum 50 items). Each MessageDigestInfo object contains digest information for one unread mention.

    public void getUltraGroupUnreadMentionedDigests(
    String targetId,
    String channelId,
    long sendTime,
    int count,
    IRongCoreCallback.ResultCallback<List<MessageDigestInfo>> callback);
  2. Construct a HistoryMessageOption object for fetching historical messages. Extract sendTime from MessageDigestInfo as the DataTime for HistoryMessageOption.

    HistoryMessageOption option = new HistoryMessageOption();
    option.setOrder(HistoryMessageOption.PullOrder.DESCEND);
    option.setCount(count);
    option.setDataTime(sendTime);
  3. (Optional) Adjust HistoryMessageOption's dataTime. Note that getMessages results won't include messages where message.sentTime == dataTime. Make the following adjustments based on PullOrder if needed:

    • HistoryMessageOption.PullOrder.DESCEND: dataTime = message.sentTime + 1
    • HistoryMessageOption.PullOrder.ASCEND : dataTime = message.sentTime - 1
  4. Use the ultra group ChannelClient's getMessages interface to retrieve historical messages before/after specific mentions.

    public void getMessages(
    final Conversation.ConversationType conversationType,
    final String targetId,
    final String channelId,
    final HistoryMessageOption historyMessageOption,
    final IRongCoreCallback.IGetMessageCallbackEx getMessageCallback);

When to Clear Unread Mentions

Unread counts should be cleared in the conversation view:

  • When the conversation view is about to disappear
  • When returning to the foreground while in the conversation view
  • After loading the latest messages

Refer to Clearing Message Unread Status for clearing methods.

tip

After successfully calling syncUltraGroupReadStatus, the local Conversation's firstUnreadMsgSendTime will reset to 0. The server-stored first unread time will also reset to 0, and the unread mention digest list will be cleared.