Skip to main content

Retrieve Unread Messages in Conversations

The IMLib SDK supports retrieving unread messages from specified conversations, enabling apps to jump to the first unread message or display all unread @mentions.

Retrieve the First Unread Message in a Conversation

Get the earliest unread message in a conversation.

Interface

RongCoreClient.getInstance().getTheFirstUnreadMessage(conversationType, targetId, callback);

Parameters

ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
callbackIRongCoreCallback.ResultCallback<Message>Callback interface

Upon successful retrieval, the callback returns a message object (Message).

Sample Code

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

RongCoreClient.getInstance().getTheFirstUnreadMessage(conversationType, targetId, new ResultCallback<Message>() {
@Override
public void onSuccess(Message message) {

}

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

}
});

Retrieve Unread @Mention Messages in a Conversation

tip
  • Versions below 5.2.5 only provide the getUnreadMentionedMessages method without count and desc parameters, returning a maximum of 10 entries per call.
  • Starting from version 5.2.5, getUnreadMentionedMessages supports the count and desc parameters.

Retrieve the earliest or latest unread @mention messages in a conversation, with a maximum of 100 entries returned.

Interface

RongCoreClient.getInstance().getUnreadMentionedMessages(conversationType, targetId, count, desc, callback);

Parameters

ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
countintNumber of messages. Maximum 100 entries.
descbooleantrue: Retrieve the latest count entries. false: Retrieve the oldest count entries.
callbackIRongCoreCallback.ResultCallback<List<Message>>Callback interface

Upon successful retrieval, the callback returns a list of message objects (Message).

Sample Code

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "Conversation ID";
int count = 100;
boolean desc = true;

RongCoreClient.getInstance().getUnreadMentionedMessages(conversationType, targetId, count, desc, new ResultCallback<List<Message>>() {
@Override
public void onSuccess(List<Message> messageList) {

}

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

}
});

Retrieve Conversation List with Unread @Mention Messages

tip

This feature is supported starting from version 5.28.0.

Interface

RongCoreClient.getInstance().getUnreadMentionMeConversationList(params, callback);

Parameters

ParameterTypeDescription
paramsGetUnreadMentionMeConversationListParamsRequest parameters
callbackIRongCoreCallback.ResultCallback<List<Conversation>>Callback interface

GetUnreadMentionMeConversationListParams Properties

ParameterTypeDescription
conversationTypesList<ConversationType>List of conversation types supported: one-to-one chat, group chat, system, and ultra group.
topPrioritybooleanWhether pinned conversations take priority. true returns pinned conversations first; otherwise, results are sorted by conversation time only.
timestamplongStart time for query (in milliseconds). Pass 0 to query the latest conversations. For subsequent queries, use the conversation time of the last element in the conversations list.
countintNumber of entries to retrieve (valid range: 1-100).

Sample Code

List<Conversation.ConversationType> types = new ArrayList<>();
types.add(Conversation.ConversationType.PRIVATE);
types.add(Conversation.ConversationType.GROUP);
types.add(Conversation.ConversationType.SYSTEM);
types.add(Conversation.ConversationType.ULTRA_GROUP);

GetUnreadMentionMeConversationListParams params = new GetUnreadMentionMeConversationListParams();
params.setConversationTypes(types);
params.setTopPriority(true);
params.setTimestamp(0);
params.setCount(20);

RongCoreClient.getInstance().getUnreadMentionMeConversationList(params, new IRongCoreCallback.ResultCallback<List<Conversation>>() {
@Override
public void onSuccess(List<Conversation> conversations) {

}

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

}
});