Skip to main content

Get Conversations

The client SDK generates corresponding conversations in the local database based on the messages sent and received by the user, and maintains a conversation list. Applications can retrieve the conversation list from the local database.

Get a Single Conversation

Retrieve detailed information about a specific conversation.

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

RongCoreClient.getInstance().getConversation(conversationType, targetId, new IRongCoreCallback.ResultCallback<Conversation>() {

@Override
public void onSuccess(Conversation conversation) {
// Success and return conversation information
}

@Override
public void onError(RongIMClient.ErrorCode errorCode) {

}
});
ParameterTypeDescription
conversationTypeConversationTypeConversation type
targetIdStringConversation ID
callbackResultCallback<Conversation>Callback interface

Batch Get Conversation Information

In addition to retrieving a single conversation, the client SDK also supports batch retrieval of conversation details.

Note: The client SDK supports batch retrieval of conversation information starting from version 5.8.2. Supported conversation types: one-to-one chat, group chat, system.

Use the getConversations() method to query detailed information for multiple conversations.

// Assume we have conversation identifiers conIden1 and conIden2, which represent the conversations we want to query.

List<ConversationIdentifier> conversationIdentifiers = new ArrayList<>();
conversationIdentifiers.add(ConversationIdentifier.obtain(ConversationType.PRIVATE, "tId1", ""));
conversationIdentifiers.add(ConversationIdentifier.obtain(ConversationType.PRIVATE, "tId2", ""));

RongCoreClient.getInstance().getConversations(conversationIdentifiers, new IRongCoreCallback.ResultCallback<List<Conversation>>() {
@Override
public void onSuccess(List<Conversation> conversations) {
// Success and return conversation information
}

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

}
});

ParameterTypeDescription
conversationIdentifiersList<ConversationIdentifier>Conversation type
callbackResultCallback<Conversation>Callback interface

Get Conversation List

The conversation list is generated and maintained by the SDK locally. If there has been no uninstallation, reinstallation, or device switch, you can retrieve all historical messages stored on the local device to generate the conversation list.

Paginate Conversation List

Retrieve the conversation list generated by the SDK in the local database in a paginated manner. The returned conversation list is sorted in reverse chronological order. If the returned results include conversations set to the top state, the top conversations will be listed first by default.

Use the getConversationListByPage method. The timestamp (startTime) can be passed as 0 for the first time, and subsequent queries can use the sentTime or operationTime property value of the returned Conversation object as the startTime for the next query. Note: If you are using a version after 5.6.8, please use the operationTime field to avoid data omission issues.

long timeStamp = 0;
int count = 10;
Conversation.ConversationType[] conversationTypes = {ConversationType.PRIVATE, ConversationType.GROUP};

RongCoreClient.getInstance().getConversationListByPage(new IRongCoreCallback.
ResultCallback<List<Conversation>>() {

@Override
public void onSuccess(List<Conversation> conversations) {

}

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

}
},timeStamp, count, conversationTypes);

If you want the returned conversation list to be strictly sorted in reverse chronological order, use the overloaded method with the topPriority parameter and set it to false. This overloaded method is only available in version 5.6.9 and later.

long timeStamp = 0;
int count = 10;
boolean topPriority = false;

Conversation.ConversationType[] conversationTypes = {ConversationType.PRIVATE, ConversationType.GROUP};

RongCoreClient.getInstance().getConversationListByPage(new IRongCoreCallback.
ResultCallback<List<Conversation>>() {

@Override
public void onSuccess(List<Conversation> conversations) {

}

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

}
},timeStamp, count, topPriority, conversationTypes);
ParameterTypeDescription
callbackResultCallback<List<Conversation>>Method callback.
timeStamplongTimestamp to retrieve conversations older than this timestamp. Pass 0 for the first time to start from the latest. Use a real timestamp for subsequent queries.
countintNumber of conversations to retrieve. It is recommended not to exceed 10, as fetching too many conversations at once may cause cross-process communication crashes, leading to failure in retrieving the conversation list and interruption of communication connection.

If the actual number of conversations retrieved is less than count, it indicates that all data has been retrieved.
topPrioritybooleanWhether to prioritize top messages. Requires SDK version ≧ 5.6.9.
conversationTypesArray of ConversationTypeSelect the conversation types to retrieve. Multiple conversation types can be set.

Get Unread Conversation List

tip

This interface is available starting from SDK version 5.3.2.

Use the RongCoreClient's getUnreadConversationList method to retrieve the list of conversations with unread messages of the specified types, supporting one-to-one chat, group chat, and system conversations. The retrieved conversation list is sorted in reverse chronological order, with top conversations listed first.

ConversationType[] conversationTypes = {ConversationType.PRIVATE, ConversationType.GROUP, ConversationType.SYSTEM};

RongCoreClient.getInstance().getUnreadConversationList(new IRongCoreCallback.ResultCallback<List<Conversation>>() {

@Override
public void onSuccess(List<Conversation> conversations) {
// Success and return conversation information
}

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

}
}, conversationTypes);
ParameterTypeDescription
callbackResultCallback<List<Conversation>>Callback interface
conversationTypesArray of ConversationTypeArray of conversation types

Handling Reinstallation or Device Switch

If your user reinstalls the app or logs in from a different device, they may find the conversation list empty or perceive that some conversations are missing.

The reasons are as follows:

  • During uninstallation, the local database is deleted, leaving no historical messages locally, resulting in an empty conversation list after reinstallation.
  • If logging in from a different device, there may be no local historical message data, resulting in an empty conversation list.
  • If your App Key has enabled the Multi-Device Message Synchronization feature, the server will also enable the offline message compensation feature. The server will automatically synchronize messages from 0:00 on the same day after the SDK connects successfully. Upon receiving the compensated messages from the server, the client SDK can generate some conversations and conversation lists. Compared to before uninstallation or device switch, there may be a perception that some conversations are missing.

If you want to retrieve the previous conversation list after reinstallation or device switch, you can refer to the following solutions:

  • Apply to increase the number of days for offline message compensation, up to a maximum of 7 days. Note: Setting a long time may cause processing pressure on the client if the message volume per user is extremely large.If needed, please submit a ticket.
  • Maintain the conversation list on your server and retrieve the historical messages to be displayed through the API.