Get Conversation (Electron)
-
This document applies only to the Electron Solution and must be used with the Electron modules (@rongcloud/electron and @rongcloud/electron-renderer).
-
Methods must be executed after successfully establishing a connection by calling RongIMLib.connect().
This document describes how to retrieve conversations from the client-side locally.
Get All Conversations
Starting from version 5.28.0, it is recommended to use the [getAllConversationList] interface instead of electronExtension.getAllConversationList. Refer to the [Get Conversation List] section.
Interface
RongIMLib.electronExtension.getAllConversationList(channelId)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| channelId | String | No | Channel ID. By default, retrieves the conversation list for all channels. |
Example Code
RongIMLib.electronExtension.getAllConversationList().then(res => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
})
Paginated Retrieval of Local Conversations
Starting from version 5.28.0, it is recommended to use the [getConversationListByTimestamp] interface instead of electronExtension.getConversationList. Refer to the [Get Conversation List] section.
Interface
RongIMLib.electronExtension.getConversationList(startTime, count, channelId, topPriority)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| startTime | number | Yes | The starting timestamp for retrieving the conversation list. Defaults to 0, meaning retrieval starts from the current time. |
| count | number | Yes | The number of conversations to retrieve. |
| channelId | string | No | Channel ID. |
| topPriority | boolean | No | Whether to sort by pinned status. Default is false. |
Example Code
const startTime = 0
const count = 10
RongIMLib.electronExtension.getConversationList(startTime, count).then(res => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
})
Batch Retrieve Conversation Information
This interface is supported starting from SDK version 5.9.9.
Call the electronExtension.getConversations method to retrieve conversation information.
Interface
RongIMLib.electronExtension.getConversations(conversations)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| conversations | IConversationOption[] | Yes | Conversation list. A maximum of 100 conversations can be retrieved at once. |
Example Code
// Supports up to 100 conversations
const conversations = [{ targetId:"user1", conversationType:1 }];
RongIMLib.electronExtension.getConversations(conversations).then(res => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
})
Synchronize Server-Side Conversation Information to Local
This interface is available starting from SDK version 5.26.2. You can submit a ticket to enable this feature.
For scenarios such as switching devices or reinstalling the app, the electronExtension.getRemoteConversations interface can be used to synchronize server-side conversation information to the local device. This interface only triggers the pull operation. After synchronization is complete, the SDK will dispatch the Events.CONVERSATIONS_SYNCED event notification.
Interface
RongIMLib.electronExtension.getRemoteConversations()
Parameter Description
This interface does not require any parameters.
Usage Steps
1. Listen for Synchronization Completion Event
Before calling the synchronization interface, it is recommended to listen for the conversation synchronization completion event to promptly obtain the synchronization result.
RongIMLib.addEventListener(RongIMLib.Events.CONVERSATIONS_SYNCED, (code) => {
if (code === ErrorCode.SUCCESS) {
console.log('Conversation list synchronization completed');
} else {
console.log('Conversation list synchronization failed:', code);
}
});
2. Call the Synchronization Interface
RongIMLib.electronExtension.getRemoteConversations().then(({ isOk, code }) => {
if (isOk) {
console.log('Synchronization request initiated successfully');
} else {
console.log('Synchronization request initiation failed:', code)
}
})