Skip to main content

Get Conversations

The client SDK generates corresponding conversations in the local database based on sent and received messages. You can retrieve the conversation list generated by the SDK from the local database.

Get Conversation List

Use the following interface to paginate and retrieve the conversation list generated by the SDK in the local database. The retrieved conversation list is sorted in reverse chronological order, with pinned conversations appearing first.

Method

Future<int> getConversations(List<RCIMIWConversationType> conversationTypes, String? channelId, int startTime, int count, {IRCIMIWGetConversationsCallback? callback});

Parameter Description

ParameterTypeDescription
conversationTypesList<RCIMIWConversationType>Conversation type
channelIdStringChannel ID, only supported for ultra groups. Pass null for other conversation types.
startTimeintTimestamp (in milliseconds), retrieves conversations before this timestamp. Pass 0 to query the latest data. When paginating, pass the operationTime of the last conversation data from the callback result to get the next page of data.
countintNumber of queries, 0 < count ≤ 50
callbackIRCIMIWGetConversationsCallbackCallback for retrieving the conversation list. The SDK supports callback from version 5.3.1. Other callback methods are deprecated starting from version 5.4.0. If the callback parameter is provided, only the callback will be triggered.

Return Value

Return ValueDescription
Future<int>Status code of the current operation. 0 indicates success, and the specific result needs to be implemented in the callback; non-zero indicates the current operation failed, and no callback will be triggered. Refer to the error codes for detailed errors.

Code Example

IRCIMIWGetConversationsCallback? callback = IRCIMIWGetConversationsCallback(onSuccess: (List<RCIMIWConversation>? t) {
//...
}, onError: (int? code) {
//...
});

int? ret = await engine?.getConversations(conversationTypesInt, channelId, startTime, count, callback:callback);

Callback Method

  • onConversationsLoaded

Callback for retrieving the conversation list

Function(int? code, List<RCIMIWConversationType>? conversationTypes, String? channelId, int? startTime, int? count, List<RCIMIWConversation>? conversations)? onConversationsLoaded;

Parameter Description

ParameterTypeDescription
codeintStatus code of the callback, 0 indicates success, non-zero indicates an exception
conversationTypesList<RCIMIWConversationType>Collection of conversation types
channelIdStringChannel ID, only supported for ultra groups.
startTimeintTimestamp (in milliseconds)
countintNumber of queries
conversationsList<RCIMIWConversation>Retrieved conversation collection

Code Example

engine?.onConversationsLoaded = (int? code, List<RCIMIWConversationType>? conversationTypes, String? channelId, int? startTime, int? count, List<RCIMIWConversation>? conversations) {
//...
};

Get Specific Conversation

Retrieve detailed information about a specific conversation.

Method

Future<int> getConversation(RCIMIWConversationType type, String targetId, String? channelId, {IRCIMIWGetConversationCallback? callback});

Parameter Description

ParameterTypeDescription
typeRCIMIWConversationTypeConversation type
targetIdStringConversation ID
channelIdStringChannel ID, only supported for ultra groups. Pass null for other conversation types.
callbackIRCIMIWGetConversationCallbackCallback for retrieving the conversation. The SDK supports callback from version 5.3.1. Other callback methods are deprecated starting from version 5.4.0. If the callback parameter is provided, only the callback will be triggered.

Return Value

Return ValueDescription
Future<int>Status code of the current operation. 0 indicates success, and the specific result needs to be implemented in the callback; non-zero indicates the current operation failed, and no callback will be triggered. Refer to the error codes for detailed errors.

Code Example

IRCIMIWGetConversationCallback? callback = IRCIMIWGetConversationCallback(onSuccess: (RCIMIWConversation? t) {
//...
}, onError: (int? code) {
//...
});

int? ret = await engine?.getConversation(type, targetId, channelId, callback:callback);

Callback Method

  • onConversationLoaded
Function(int? code, RCIMIWConversationType? type, String? targetId, String? channelId, RCIMIWConversation? conversation)? onConversationLoaded;

Parameter Description

ParameterTypeDescription
codeintStatus code of the callback, 0 indicates success, non-zero indicates an exception
typeRCIMIWConversationTypeConversation type
targetIdStringConversation ID
channelIdStringChannel ID, only supported for ultra groups. Pass null for other conversation types.
conversationRCIMIWConversationRetrieved conversation

Code Example

engine?.onConversationLoaded = (int? code, RCIMIWConversationType? type, String? targetId, String? channelId, RCIMIWConversation? conversation) {
//...
};

Get Unread Conversations

Retrieve the list of conversations with unread messages for specified types, supporting one-to-one chat, group chat, and system conversations. The retrieved conversation list is sorted in reverse chronological order, with pinned conversations appearing first.

Method

Future<int> getUnreadConversations(List<RCIMIWConversationType> conversationTypes, {IRCIMIWGetUnreadConversationsCallback? callback});

Parameter Description

ParameterTypeDescription
conversationTypesList<RCIMIWConversationType>Supports one-to-one chat, group chat, and system conversations
callbackIRCIMIWGetUnreadConversationsCallbackCallback for retrieving the conversation list.

Return Value

Return ValueDescription
Future<int>Status code of the current operation. 0 indicates success, and the specific result needs to be implemented in the callback; non-zero indicates the current operation failed, and no callback will be triggered. Refer to the error codes for detailed errors.

Code Example

IRCIMIWGetUnreadConversationsCallback? callback = IRCIMIWGetUnreadConversationsCallback(onSuccess: (List<RCIMIWConversation>? t) {
//...
}, onError: (int? code) {
//...
});

int? ret = await engine?.getUnreadConversations(conversationTypesInt, callback:callback);

FAQ

Q1: When a user reinstalls the app, the conversation list is empty or some conversations are missing. A1: Since the conversation list is retrieved from the local database, which is stored in the SDK's internal database, uninstalling the app deletes the local database, resulting in an empty conversation list upon reinstallation. The presence of some conversations is due to the offline message compensation feature being enabled. This feature is part of the Multi-Device Message Synchronization functionality purchased in the backend, which by default includes offline message compensation for the current day (starting at 0 o'clock). When a user logs in on a new device, the offline message compensation feature is triggered, retrieving some conversations and creating the illusion of missing conversations. If you need offline message compensation for more days, you can submit a ticket to modify this, with a maximum of 7 days. Setting a longer duration may cause excessive message compensation for users with a large volume of messages, leading to processing pressure on the client.