getConversationList
(Details) to get the conversation list. This API pulls locally cached conversations. If any server conversation is updated, the SDK will automatically sync the update and notify you in the V2TIMConversationListener
callback.V2TIMConversation
objects. Currently, the IM SDK sorts conversations according to the following rules:orderKey
conversation object by default. The greater the orderKey
value of a conversation, the higher position the conversation is in the list. The orderKey
field is an integer that increases as the conversation is activated when a message is sent/received, a draft is set, or the conversation is pinned to the top.getConversationList
to implement one-time or paged pull as detailed below.count
of the pull to INT_MAX
(which is generally greater than the number of conversations).const nextSeq = "0";const count = 100;const convList = await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationList(count, nextSeq);
getConversationList
for the first time, set nextSeq
to 0
(indicating to pull the conversation list from the beginning) and count
to 50
(indicating to pull 50 conversation objects at a time).V2TIMConversationResult
callback of getConversationList
will contain nextSeq
(field for the next pull) and isFinish
(indicating whether the conversation pull is completed).isFinished
is true
, all the conversations have been pulled.isFinished
is false
, there are more conversations that can be pulled. This does not mean that the next page of the conversation list will be pulled immediately. In common communications software, a paged pull is often triggered by a swipe operation.getConversationList
API and pass in the nextSeq
and count
parameters (the values are from the V2TIMConversationResult
object returned by the last pull) for the next pull.isFinished
is true
.const nextSeq = "0";const count = 100;const convList = await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationList(count, nextSeq);const seq = convList.data.nextSeq;if (!convList.data.isFinished) {// If there are more conversations that can be pulledconst convList = await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationList(count, seq);}
addConversationListener
(Details) to add a conversation listener to receive conversation change events.TencentImSDKPlugin.v2TIMManager.getConversationManager().addConversationListener({onConversationChanged: (conversationList) => {},// Others ));});
V2TIMConversationListener
(Details) to get the notification of a conversation list change.Event | Description | Suggestion |
onSyncServerStart | Server conversation sync started. | The SDK will automatically sync server conversations after a successful login or network reconnection. You can listen for such an event and display the event progress on the UI. |
onSyncServerFinish | Server conversation sync was completed. | If there is a conversation change, the change will be notified through the onNewConversation /onConversationChanged callback. |
onSyncServerFailed | Server conversation sync failed. | You can listen for such an event and display the event exception on the UI. |
onNewConversation | A new conversation was added. | When the user receives a one-to-one message from a new colleague or is invited to a new group, you can re-sort the conversations. |
onConversationChanged | There is a conversation update | When the unread count changes or the last message is updated, you can re-sort the conversations. |
onTotalUnreadMessageCountChanged | Notification of a change in the total unread count of the conversation |
// Listen for the conversationTencentImSDKPlugin.v2TIMManager.getConversationManager().addConversationListener({onConversationChanged: (conversationList) => {},onNewConversation: (conv) => {},onSyncServerFailed: () => {},onSyncServerFinish: () => {},onSyncServerStart: () => {},onTotalUnreadMessageCountChanged: (count) => {},});
removeConversationListener
(Details) to remove a conversation listener to stop receiving conversation change events.
This step is optional and can be performed as needed.conversationManager.removeConversationListener(conversationListener);
lastMessage
of V2TIMConversation
as the data source for implementation. However, in some cases, if you don't want some messages (such as system tips) to be displayed as the latest message in a conversation, you can set isExcludedFromLastMessage
to false
/no
when calling sendMessage
.
Was this page helpful?