Skip to main content

Get Conversation (Electron)

tip

This document describes how to retrieve conversations from the client-side locally.

Get All Conversations​

tip

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​

ParameterTypeRequiredDescription
channelIdStringNoChannel 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​

tip

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​

ParameterTypeRequiredDescription
startTimenumberYesThe starting timestamp for retrieving the conversation list. Defaults to 0, meaning retrieval starts from the current time.
countnumberYesThe number of conversations to retrieve.
channelIdstringNoChannel ID.
topPrioritybooleanNoWhether 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​

tip

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​

ParameterTypeRequiredDescription
conversationsIConversationOption[]YesConversation 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​

tip

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