Skip to main content

Get Unread Messages in a Conversation

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

Get the First Unread Message in a Conversation

Retrieve the earliest unread message in a conversation.

RongCoreClient.getInstance().getTheFirstUnreadMessage(conversationType, targetId, callback);
ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
callbackIRongCoreCallback.ResultCallback<Message>Callback interface

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

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) {

}
});

Get Unread Mention Messages in a Conversation

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

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

RongCoreClient.getInstance().getUnreadMentionedMessages(conversationType, targetId, count, desc, callback);
ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
countintNumber of messages. Maximum of 100.
descbooleantrue: Retrieves the latest count messages. false: Retrieves the oldest count messages.
callbackIRongCoreCallback.ResultCallback<List<Message>>Callback interface

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

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) {

}
});