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
Use getConversation:targetId:completion: to get the details of a specific conversation.
[[RCCoreClient sharedCoreClient] getConversation:ConversationType_PRIVATE
targetId:@"targetId"
completion:^(RCConversation *conversation) {
}];
Parameter | Type | Description |
---|---|---|
conversationType | RCConversationType | Conversation type, pass ConversationType_PRIVATE for one-to-one chat |
targetId | NSString | Conversation ID |
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:success:error:
method to query details of multiple conversations. If only part of the conversation information exists in the local database, the successBlock
will only return the conversations that exist locally; if none of the queried conversations are found in the local database, the errorBlock
will be triggered.
// Assume we have conversation identifiers conIden1 and conIden2, representing the conversations we want to query.
RCConversationIdentifier *conIden1 = [[RCConversationIdentifier alloc] initWithConversationIdentifier:ConversationType_PRIVATE targetId:@"tId1"];
RCConversationIdentifier *conIden2 = [[RCConversationIdentifier alloc] initWithConversationIdentifier:ConversationType_PRIVATE targetId:@"tId2"];
// Create an array containing the conversation identifiers.
NSArray *conversationIdentifiers = @[
conIden1,
conIden2
// If there are more conversation identifiers, continue adding them to this array.
];
// Use the getConversations:success:error: method to batch retrieve conversation information
[[RCCoreClient sharedCoreClient] getConversations:conversationIdentifiers
success:^(NSArray<RCConversation *> * _Nonnull conversations) {
// Logic to handle successful retrieval of conversation information.
}
error:^(RCErrorCode status) {
// Error handling logic, status is the error code.
// Handle the error based on the status.
NSLog(@"Error fetching conversations: %@", @(status));
}];
Parameter | Type | Description |
---|---|---|
conversationIdentifiers | NSArray | Array of conversation identifiers to query, with a maximum of 100 conversations per retrieval. |
success | Block | Callback for successful retrieval of conversation information, returns an array containing conversation information. |
error | Block | Callback for failed retrieval of conversation information, returns an error code. |
Get Conversation List
The conversation list is generated and maintained by the SDK locally. If the app has not been uninstalled and reinstalled or the user has not logged in on a different device, you can retrieve all historical messages stored on the local device to generate the conversation list.
Paginate Conversation List
Use getConversationList:count:startTime:completion: to paginate the conversation list generated by the SDK in the local database. The returned conversation list is sorted in reverse chronological order. If the result includes conversations that have been set to the top, the top conversations will be listed first by default.
For the timestamp (startTime
), you can pass 0
for the first query, and subsequently use the operationTime
property of the returned RCConversation object as the startTime
for the next query.
Starting from version 5.6.8, the operationTime
of the conversation is required; for versions prior to 5.6.8, the sentTime
of the conversation is also required.
[[RCCoreClient sharedCoreClient] getConversationList:@[@(ConversationType_PRIVATE)]
count:100
startTime:0
completion:^(NSArray<RCConversation *> *conversationList) {
}];
If you want the returned conversation list to be strictly sorted in reverse chronological order, use the method with the topPriority
parameter and set it to NO
. This method is only available in version 5.6.9 and later.
[[RCCoreClient sharedCoreClient] getConversationList:@[@(ConversationType_PRIVATE)]
count:100
startTime:0
topPriority:NO
completion:^(NSArray<RCConversation *> *conversationList) {
}];
Parameter | Type | Description |
---|---|---|
conversationTypeList | NSArray | Array of conversation types, RCConversationType needs to be converted to NSNumber to build the array. |
count | int | Number of conversations to retrieve |
startTime | long long | Specified timestamp to retrieve conversations older than this timestamp. Pass 0 for the first query to start from the latest. Use the actual timestamp for subsequent queries. |
topPriority | boolean | Whether to prioritize top messages. Requires SDK version ≧ 5.6.9. |
completion | Block | Callback for successful retrieval of the conversation list |
Get Unread Conversation List
This interface is available starting from SDK version 5.3.2.
Use getUnreadConversationList:completion: to get the list of conversations with unread messages for the specified types, supporting one-to-one chat, group chat, and system conversations. It returns a list of RCConversation, sorted in reverse chronological order, with top conversations listed first.
[[RCCoreClient sharedCoreClient] getUnreadConversationList:@[@(ConversationType_GROUP),@(ConversationType_SYSTEM),@(ConversationType_PRIVATE)]
completion:^(NSArray<RCConversation *> * _Nullable conversationList) {
}];
Parameter | Type | Description |
---|---|---|
conversationTypeList | NSArray | Array of conversation types, RCConversationType needs to be converted to NSNumber to build the array |
completion | Block | Callback for successful retrieval of the conversation list |
Handling Uninstall and Reinstall or Device Switch
If your user uninstalls and reinstalls the app or logs in on a different device, they may find that the conversation list is empty or feel that some conversations are missing.
The reasons are as follows:
- Uninstalling the app deletes the local database, so there are no historical messages locally, resulting in an empty conversation list after reinstallation.
- If the user logs in on a different device, there may be no historical message data locally, resulting in an empty conversation list.
- If the Multi-Device Message Synchronization feature is enabled for your App Key in the Console, the server will also enable the Offline Message Compensation feature. The server will automatically synchronize messages from the current day's 0:00 after the SDK connects successfully. After the client SDK receives the compensated messages from the server, it can generate some conversations and a conversation list. Compared to before uninstalling or switching devices, there may be a perception that some conversations are missing.
If you want to retrieve the previous conversation list after uninstalling and reinstalling or switching devices, 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 that setting this time too long may cause excessive message compensation for a single user, leading to performance issues on the client side. If needed, please submit a ticket.
- Maintain the conversation list on your server and use the API to retrieve the historical messages that need to be displayed from the server.