Starter Deal! First 3 month from only  $9.9 /month!
Starter Deal! First 3 month from only  $9.9 /month!
Grab It Now 
Chat
  • Web
    • TUIKit
      • Overview
      • Installaton
        • TUIKit
          • Vue
          • React
        • TUIChat Only
          • Vue
      • Features
        • Reactions
        • Read Receipt
        • Typing Status
        • User Online Status
      • Themes
        • Setting UI Styles
          • Web
          • Mobile
      • Customization
        • Customize Messages
      • Localization
    • SDK
      • Install Chat SDK
      • Initialize Chat SDK
      • Login and Logout
      • Client APIs
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Historical Message
        • Forward Messages
        • Modify a Message
        • Delete Messages
        • Clear History Message
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Targeted Group Message
        • Do not Notify
        • Key-Value Extensions
        • Translation
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
        • Group Counter
      • Community Topic
        • Community Management
      • User Profile and Relationship Chain
        • User Profile
        • User Status
        • Friend Management
        • Friend List
        • Block List
  • Android
    • Run Demo
    • UIKit
      • Overview
      • Getting Started
      • Installation
        • TUIKit
        • TUIChat Only
      • Features
        • Reactions
        • Read Receipt
        • User Online Status
        • Search Messages
      • Customization
        • Customize Messages
        • Customize Emojis and Stickers
      • Localization
    • SDK
      • Install Chat SDK
      • Initialize Chat SDK
      • Login and Logout
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Retrieve Messages
        • Forward Messages
        • Modify a Message
        • Insert a Message
        • Delete Messages
        • Clear History Messages
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Metions
        • Targeted Group Message
        • Do not Notify
        • Key-Value Extensions
        • Reactions
        • Translation
        • Pin Messages
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Draft
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Manage Group
        • Profile
        • Manage Members
        • Member Profile
        • Attribute
        • Counter
      • Community and Topic
        • Manage Community
        • Permission Group
      • User
        • User Profile
        • User Status
        • Manage Friends
        • Friend Group
        • Block Lists
      • Local Search
        • Search Messages
        • Search Friends
        • Search Groups
        • Search Group Members
      • Signaling
      • API Reference
        • Java
  • iOS and macOS
    • Run Demo
    • UIKit
      • Overview
      • Getting Started
      • Installation
        • TUIKit
        • TUIChat Only
      • Features
        • Reactions
        • Read Receipt
        • User Online Status
        • Search Messages
      • Customization
        • Customize Messages
        • Customize Emojis and Stickers
      • Localization
    • SDK
      • Installation
        • iOS
        • macOS
      • Initialize Chat SDK
      • Login and Logout
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Retrieve Messages
        • Forward Messages
        • Modify a Message
        • Insert a Message
        • Delete Messages
        • Clear History Messages
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Metions
        • Targeted Group Messages
        • Do not Notify
        • Key-Value Extensions
        • Reactions
        • Translation
        • Pin Messages
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Draft
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Manage Group
        • Profile
        • Manage Members
        • Member Profile
        • Attribute
        • Counter
      • Community and Topic
        • Manage Community
        • Permission Group
      • User
        • User Profile
        • User Status
        • Manage Friends
        • Friend Group
        • Block Lists
      • Local Search
        • Search Messages
        • Search Friends
        • Search Groups
        • Search Group Members
      • Signaling
      • API Reference
        • Swift
        • Objective-C
  • Windows
    • SDK
      • Install Chat SDK
      • Initialize Chat SDK
      • Login and Logout
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Retrieve Messages
        • Forward Messages
        • Modify a Message
        • Insert a Message
        • Delete Messages
        • Clear History Messages
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Metions
        • Targeted Group Messages
        • Do not Notify
        • Key-Value Extensions
        • Reactions
        • Translation
        • Pin Messages
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Draft
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Manage Group
        • Profile
        • Manage Members
        • Member Profile
        • Attribute
        • Counter
      • Community and Topic
        • Manage Community
        • Permission Group
      • User
        • User Profile
        • User Status
        • Manage Friends
        • Friend Group
        • Block Lists
      • Local Search
        • Search Messages
        • Search Friends
        • Search Groups
        • Search Group Members
      • Signaling
      • API Reference
        • C++
        • C
  • Flutter
    • Run Demo
    • UIKIT
      • Overview
      • Installation
        • integrated
      • Features
        • Local Search
        • Offline Push
        • Online Status
        • Typing Status
        • Message Read Receipt
        • Message Reactions
        • Internationalization
        • Adding Custom Messages
        • Emoji & Stickers
      • Customization
        • Modifying UI Themes
        • Setting UI Styles
    • SDK
      • Install Chat SDK
        • Install
      • Initialize Chat SDK
        • Initialize
      • Login And Logout
        • Login and Logout
      • Message
        • Message Overview
        • Sending Message
        • Receiving Message
        • Historical Message
        • Forwarding Message
        • Modifying Message
        • Message Inserting
        • Deleting Message
        • Clearing Messages
        • Recalling Message
        • Online Message
        • Read Receipt
        • Querying Message
        • Group @ Message
        • Targeted Group Message
        • Notification Muting
        • Message Extension
      • Conversation
        • Conversation Overview
        • Conversation List
        • Getting Conversation
        • Conversation Unread Count
        • Pinning Conversation to the Top
        • Deleting Conversation
        • Conversation Draft
        • Conversation Group
      • Group
        • Group Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
      • User
        • User Profile
        • Friend Management
        • Friend List
        • Blocklist
      • Offline Push
        • Offline Push
      • Signaling
        • Signaling Management
      • Local Search
        • Searching for Message
        • Searching for Friend
        • Searching Group
        • Searching for Group Member
      • API Reference
        • Client APIs
  • React Native
    • Run Demo
    • SDK
      • SDK Integration
      • Initialization
      • Login and Logout
      • Message
        • Message Overview
        • Sending Message
        • Receiving Message
        • Historical Message
        • Forwarding Message
        • Modifying Message
        • Message Inserting
        • Deleting Message
        • Clearing Messages
        • Recalling Message
        • Online Message
        • Read Receipt
        • Querying Message
        • Group @ Message
        • Targeted Group Message
        • Notification Muting
        • Message Extension
      • Group
        • Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
        • Community Management
      • User
        • User Profile
        • Friend Management
        • Friend List
        • Blocklist
      • Offline Push
        • Offline Push
      • Local Search
        • Searching for Message
        • Searching for Friend
        • Searching Group
        • Searching for Group Member
      • Signaling
        • Signaling Management
  • Unity(Game Solution)
    • Run Demo
    • SDK
      • SDK Integration
      • Initialization
      • Login and Logout
      • Message
        • Message Overview
        • Sending Message
        • Receiving Message
        • Historical Message
        • Forwarding Message
        • Modifying Message
        • Deleting Message
        • Clearing Messages
        • Recalling Message
        • Online Message
        • Read Receipt
        • Querying Message
        • Group @ Message
        • Targeted Group Message
        • Notification Muting
        • Message Extension
      • Conversation
        • Conversation Overview
        • Conversation List
        • Getting Conversation
        • Conversation Unread Count
        • Pinning Conversation to the Top
        • Deleting Conversation
        • Conversation Draft
        • Conversation Mark
        • Conversation Group
      • Group
        • Group Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
        • Group Counter
      • User
        • User Profile
        • User Status
        • Friend Management
        • Friend List
        • Blocklist
  • Unreal Engine(Game Solution)
    • SDK
      • SDK Integration
  • Free Demos
  • Server APIs
    • Generating UserSig
    • RESTful APIs
      • RESTful API Overview
      • RESTful API List
      • Message Related
        • Send Message
          • Sending One-to-One Messages to One User
          • Sending One-to-One Messages to Multiple Users
          • Sending Ordinary Messages in a Group
          • Sending System Messages in a Group
          • Broadcast Message of Audio-Video Group
          • Importing One-to-One Messages
          • Importing Group Messages
        • Historical Message
          • Modifying Historical One-to-one Messages
          • Modifying Historical Group Messages
          • Pulling Historical One-to-one Messages
          • Pulling Historical Group Messages
        • Delete Message
          • Deleting Messages Sent by a Specified User
        • Withdraw Message
          • Recalling One-to-One Messages
          • Recalling Group Messages
        • Read Receipt
          • Marking One-to-One Messages as Read
          • Pulling Group Message Read Receipt Details
          • Pulling Read Receipts for Group Messages
        • Message Extension
          • Pulling the Message Extension of a One-to-One Message
          • Configuring Message Extension for a One-to-One Message
          • Pulling Message Extension of a Group Message
          • Configuring Message Extension for a Group Message
        • Pushing to All Users
          • API for Pushing to All Users
          • Pushing to All Users
          • Setting Application Attribute Names
          • Getting Application Attribute Names
          • Getting User Attributes
          • Setting User Attributes
          • Deleting User Attributes
          • Getting User Tags
          • Adding User Tags
          • Deleting User Tags
          • Deleting All Tags of a User
      • Session Related
        • Conversation List
          • Pulling a conversation list
        • Session Unread Count
          • Setting the Unread Message Count of a Member
          • Querying Unread One-to-One Message Count
        • Delete Session
          • Deleting a conversation
        • Session Grouping Tag
          • Creating Conversation Group Data
          • Updating Conversation Group Data
          • Deleting Conversation Group Data
          • Creating or Updating Conversation Mark Data
          • Searching for Conversation Group Marks
          • Pulling Conversation Group Mark Data
      • Group Related
        • Group Management
          • Getting All Groups in an App
          • Creating a Group
          • Disbanding a Group
          • Getting the Groups a User Has Joined
        • Group Information
          • Getting Group Profiles
          • Modifying the Profile of a Group
          • Importing a Group Profile
        • Group Member Management
          • Adding Group Members
          • Deleting Group Members
          • Banning Group Members
          • Unbanning Group Members
          • Bulk Muting and Unmuting
          • Getting the List of Muted Group Members
          • Changing Group Owner
          • Querying the Roles of Users in a Group
          • Importing Group Members
        • Group Member Information
          • Getting Group Member Profiles
          • Modifying the Profile of a Group Member
        • Group Custom Attributes
          • Getting Group Custom Attributes
          • Modifying Group Custom Attributes
          • Clearing Group Custom Attributes
          • Resetting Group Custom Attributes
          • Deleting Group Custom Attributes
        • Live Group Management
          • Getting the Number of Online Users in an Audio-Video Group
          • Getting the List of Online Members in Audio-Video Group
          • Setting Audio-Video Group Member Marks
          • Getting the List of Banned Group Members.
        • Community Management
          • Creating Topic
          • Deleting Topic
          • Getting Topic Profile
          • Modifying Topic Profile
          • Importing Topic Profiles
        • Group Counter
          • Getting Group Counters
          • Updating Group Counters
          • Deleting Group Counters
      • User Management
        • Account Management
          • Importing a Single Account
          • Importing Multiple Accounts
          • Deleting Accounts
          • Querying Accounts
        • User Information
          • Setting Profiles
          • Pulling Profiles
        • User Status
          • Invalidating Account Login States
          • Querying Account Online Status
        • Friend Management
          • Adding Friends
          • Importing Friends
          • Updating Friends
          • Deleting Friends
          • Deleting All Friends
          • Verifying Friends
          • Pulling Friends
          • Pulling Specified Friends
        • Friend Lists
          • Adding Lists
          • Deleting Lists
          • Pulling Lists
        • Blocklist
          • Blocklisting Users
          • Unblocklisting Users
          • Pulling a Blacklist
          • Verifying Users on a Blocklist
      • Global Mute Management
        • Setting Global Mute
        • Querying Global Mute
      • Operations Management
        • Pulling Operations Data
        • Downloading Recent Messages
        • Getting Server IP Addresses
      • Chatbots
        • Pulling Chatbot Accounts
        • Creating Chatbot Accounts
        • Deleting Chatbot Accounts
    • Webhooks
      • Webhook Overview
      • Webhook Command List
      • Operations Management Callbacks
        • API Overclocking Alarm Callbacks
      • Online Status Webhooks
        • Status Change Webhooks
      • Relationship Chain Webhooks
        • After a Profile Is Updated
        • Before a Friend Is Added
        • Before a Friend Request Is Responded
        • After a Friend Is Added
        • After a Friend Is Deleted
        • After a User Is Added to Blocklist
        • After a User Is Removed from Blocklist
      • One-to-One Message Webhooks
        • Before a One-to-One Message Is Sent
        • After a One-to-One Message Is Sent
        • After a One-to-One message Is Marked as Read
        • After A One-to-One Message Is Recalled
      • Group Webhooks
        • Before a Group Is Created
        • After a Group Is Created
        • Before Applying to Join a Group
        • Before Inviting a User to a Group
        • After a User Joins a Group
        • After a User Leaves a Group
        • Before Group Message Is Sent
        • After a Group Message Is Sent
        • After a Group Is Full
        • After a Group Is Disbanded
        • After Group Profile Is Modified
        • Callback After Recalling Group Messages
        • Webhook for Online and Offline Status of Audio-Video Group Members
        • Webhook for Exceptions When Group Messages Are Sent
        • Before a Topic Is Created
        • After a Topic Is Created
        • After a Topic Is Deleted
        • Topic Profile Change Webhook
        • Callback After Group Member Profile Changed
        • Callback After Group Attribute Changed
        • Callback After Read Receipt
        • Callback After the Group Owner Changed
      • Webhook Mutual Authentication Configuration Guide
        • Apache Mutual Authentication Configuration
        • Nginx Mutual Authentication Configuration
      • Chatbot webhooks
        • Chatbot Passthrough Message Callback
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes
Chat

Conversation List

Overview

After a user logs in to the application, the list of recent conversations can be displayed to make it easy to locate the target conversation.
The conversation list features include getting the conversation list and processing the conversation list update.This section describes how to implement such features.

Ordinary API for Getting the Conversation List

You can call getConversationList (Android / iOS and macOS / Windows) 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.
User conversations are returned in a list that stores V2TIMConversation objects. Currently, the IM SDK sorts conversations according to the following rules:
Starting from v5.5.892, the obtained conversations are sorted based on the 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.
On versions earlier than v5.5.892, the obtained conversations are sorted based on the lastMessage > timestamp of the conversation by default. The greater the timestamp value, the higher the position of the conversation is in the list.
Caution
In certain cases, the lastMessage of a conversation may be empty, such as when the messages in the conversation are cleared. If you use the SDK earlier than v5.5.892, you need to handle the exception when sorting the conversations by lastMessage. We recommend you upgrade the SDK to v5.5.892 or later and sort the conversations by orderKey.
You can use getConversationList to implement one-time or paged pull as detailed below.

One-time pull

One-time pull is suitable for scenarios with a small number of conversations (up to 100). You can set the count of the pull to INT_MAX (which is generally greater than the number of conversations).
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getConversationManager().getConversationList(0, Integer.MAX_VALUE, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
long nextSeq = v2TIMConversationResult.getNextSeq();
Log.i("imsdk", "success nextSeq:" + nextSeq + ", isFinish:" + v2TIMConversationResult.isFinished());

List<V2TIMConversation> v2TIMConversationList = v2TIMConversationResult.getConversationList();
for (V2TIMConversation v2TIMConversation : v2TIMConversationList) {
Log.i("imsdk", "success showName:" + v2TIMConversation.getShowName());
}
}

@Override
public void onError(int code, String desc) {
Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
}
});
[[V2TIMManager sharedInstance] getConversationList:0
count:INT_MAX
succ:^(NSArray<V2TIMConversation *> *list, uint64_t lastTS, BOOL isFinished) {
// Obtained the conversation list successfully. `list` is the conversation list.
} fail:^(int code, NSString *msg) {
// Failed to obtain
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

uint64_t nextSeq = 0;
uint32_t count = std::numeric_limits<uint32_t>::max();

auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list obtained successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain the conversation list
delete callback;
});

V2TIMManager::GetInstance()->GetConversationManager()->GetConversationList(nextSeq, count, callback);

Pulling by page

If the number of conversations is great, pulling by page is recommended to enhance the loading efficiency and save network traffic. The recommended number of conversations pulled per page is up to 100.
Directions:
1. When you call 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).
2. After the conversation list is pulled successfully for the first time, the V2TIMConversationResult callback of getConversationList will contain nextSeq (field for the next pull) and isFinish (indicating whether the conversation pull is completed).
If isFinished is true, all the conversations have been pulled.
If 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 software, a paged pull is often triggered by a swipe operation.
3. When the user continues to pull up the conversation list, if there are more conversations that can be pulled, you can continue to call the getConversationList API and pass in the nextSeq (the value is from the V2TIMConversationResult object returned by the last pull) and count parameters for the next pull.
4. Repeat step 3 until isFinished is true.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getConversationManager().getConversationList(0, 20, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
long nextSeq = v2TIMConversationResult.getNextSeq();
Log.i("imsdk", "success nextSeq:" + nextSeq + ", isFinish:" + v2TIMConversationResult.isFinished());

List<V2TIMConversation> v2TIMConversationList = v2TIMConversationResult.getConversationList();
for (V2TIMConversation v2TIMConversation : v2TIMConversationList) {
Log.i("imsdk", "success showName:" + v2TIMConversation.getShowName());
}

if (!v2TIMConversationResult.isFinished()) {
getConversationListInternal(nextSeq, 20);
}
}

@Override
public void onError(int code, String desc) {
Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
}
});
// It will be triggered when the user pulls up the conversation list to the bottom and no more conversation data is displayed.
- (void)loadConversation {
if (self.isFinished) {
return;
}
@weakify(self)
[[V2TIMManager sharedInstance] getConversationList:self.nextSeq
count:20 // Pull 20 conversations each time
succ:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {
// Conversations pulled successfully
@strongify(self)
// Update the `nextSeq` and `isFinished` for the next pull
self.nextSeq = nextSeq;
self.isFinished = isFinished;

// Update the UI with the `list`
} fail:^(int code, NSString *msg) {
// Failed to pull the conversations; in this case, end the pull.
self.isFinished = YES;
}];
}
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

uint64_t nextSeq = 0;
uint32_t count = 20;

auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list obtained successfully
if (!conversationResult.isFinished) {
nextSeq = conversationResult.nextSeq;
// Get more...
}

delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain the conversation list
delete callback;
});

V2TIMManager::GetInstance()->GetConversationManager()->GetConversationList(nextSeq, count, callback);

Advanced API for Getting the Conversation List

If the ordinary API mentioned above cannot meet your needs to pull the conversation list, you can use the advanced API getConversationListByFilter (Android / iOS and macOS / Windows). Here, V2TIMConversationListFilter of the conversations is pulled and as detailed below:
Attribute
Definition
Description
type
Conversation type (0 means not filtering this attribute)
One-to-one or group conversation.
conversationGroup
Conversation group name (empty means not filtering this attribute)
It is not the group name, but the name of the conversation group. For more information, see Conversation Group.
markType
Conversation tag type (0 means not filtering this attribute)
For more information, see Conversation Tag.
hasUnreadCount
Conversation contains unread counts
true: return conversations containing unread counts; false: return all conversations.
hasGroupAtInfo
Conversation contains group @ messages
true : return conversations containing group @ messages; false : return all conversations.
Sample code:

Pulling one-to-one or group conversations

Android
iOS & Mac
Windows
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();
filter.setConversationType(V2TIMConversation.V2TIM_C2C); // Pulling one-to-one conversations
// filter.setConversationType(V2TIMConversation.V2TIM_GROUP); // Pulling group conversations
V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
// Conversation list polled successfully
}

@Override
public void onError(int code, String desc) {
// Failed to poll the conversation list
}
});
V2TIMConversationListFilter *filter = [[V2TIMConversationListFilter alloc] init];
filter.type = V2TIM_C2C; // Pulling one-to-one conversations
// filter.type = V2TIM_GROUP; // Pulling group conversations
[[V2TIMManager sharedInstance] getConversationListByFilter:filter nextSeq:0 count:50 succ:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {
// Conversation list polled successfully
} fail:^(int code, NSString *desc) {
// Failed to poll the conversation list
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMConversationListFilter filter;
filter.type = V2TIMConversationType::V2TIM_C2C; // Pulling one-to-one conversations
// filter.type = V2TIMConversationType::V2TIM_GROUP; // Pulling group conversations
auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list polled successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to poll the conversation list
delete callback;
});
V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);

Pulling conversations of a specified group

Android
iOS & Mac
Windows
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();
filter.setConversationGroup("conversation_group");
V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
// Conversation list polled successfully
}

@Override
public void onError(int code, String desc) {
// Failed to poll the conversation list
}
});
V2TIMConversationListFilter *filter = [[V2TIMConversationListFilter alloc] init];
filter.conversationGroup = @"conversation_group";
[[V2TIMManager sharedInstance] getConversationListByFilter:filter nextSeq:0 count:50 succ:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {
// Conversation list polled successfully
} fail:^(int code, NSString *desc) {
// Failed to poll the conversation list
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMConversationListFilter filter;
filter.conversationGroup = u8"conversation_group";
auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list polled successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to poll the conversation list
delete callback;
});
V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);

Pulling conversations of a specified tag

Android
iOS & Mac
Windows
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();
filter.setMarkType(V2TIMConversation.V2TIM_CONVERSATION_MARK_TYPE_STAR);
V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
// Conversation list polled successfully
}

@Override
public void onError(int code, String desc) {
// Failed to poll the conversation list
}
});
V2TIMConversationListFilter *filter = [[V2TIMConversationListFilter alloc] init];
filter.markType = V2TIM_CONVERSATION_MARK_TYPE_STAR;
[[V2TIMManager sharedInstance] getConversationListByFilter:filter nextSeq:0 count:50 succ:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {
// Conversation list polled successfully
} fail:^(int code, NSString *desc) {
// Failed to poll the conversation list
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMConversationListFilter filter;
filter.markType = V2TIMConversationMarkType::V2TIM_CONVERSATION_MARK_TYPE_STAR;
auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list polled successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to poll the conversation list
delete callback;
});
V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);

Pulling conversations containing unread counts

Android
iOS & Mac
Windows
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();
filter.setHasUnreadCount(true);
V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
// Conversation list polled successfully
}

@Override
public void onError(int code, String desc) {
// Failed to poll the conversation list
}
});
V2TIMConversationListFilter *filter = [[V2TIMConversationListFilter alloc] init];
filter.hasUnreadCount = YES;
[[V2TIMManager sharedInstance] getConversationListByFilter:filter nextSeq:0 count:50 succ:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {
// Conversation list polled successfully
} fail:^(int code, NSString *desc) {
// Failed to poll the conversation list
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMConversationListFilter filter;
filter.hasUnreadCount = true;
auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list polled successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to poll the conversation list
delete callback;
});
V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);

Pulling conversations containing group @ messages

Android
iOS & Mac
Windows
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();
filter.setHasGroupAtInfo(true);
V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {
@Override
public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
// Conversation list polled successfully
}

@Override
public void onError(int code, String desc) {
// Failed to poll the conversation list
}
});
V2TIMConversationListFilter *filter = [[V2TIMConversationListFilter alloc] init];
filter.hasGroupAtInfo = YES;
[[V2TIMManager sharedInstance] getConversationListByFilter:filter nextSeq:0 count:50 succ:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {
// Conversation list polled successfully
} fail:^(int code, NSString *desc) {
// Failed to poll the conversation list
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMConversationListFilter filter;
filter.hasGroupAtInfo = true;
auto callback = new ValueCallback<V2TIMConversationResult>{};
callback->SetCallback(
[=](const V2TIMConversationResult& conversationResult) {
// Conversation list polled successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to poll the conversation list
delete callback;
});
V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);

Sorting the Conversation List

The conversation list is always arranged in descending order according to V2TIMConversation.orderKey, and the orderKey will be incremented as the conversation is updated.
Common operations that cause the orderKey to increment include: sending and receiving messages (that is, changes in lastMessage), pinning/unpinning.
When the time order of the lastMessage of the conversation is inconsistent with the orderKey, the order of the orderKey shall prevail.

Updating the Conversation List

After the IM SDK is logged in successfully, the user goes online, or the network is disconnected and reconnected, the IM SDK will automatically update the conversation list. You can get the updated conversation list in the following steps:
1. Add a conversation listener.
2. Receive and process conversation changes.
3. Remove the conversation listener. This step is optional and can be performed as needed.

Adding a conversation listener

Call addConversationListener (Android / iOS and macOS / Windows) to add a conversation listener to receive conversation change events.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getConversationManager().addConversationListener(conversationListener);
// `self` is of the id<V2TIMConversationListener> type.
[[V2TIMManager sharedInstance] addConversationListener:self];
class ConversationListener final : public V2TIMConversationListener {
// Member...
};

// Add a conversation event listener. Keep `conversationListener` valid before the listener is removed to ensure event callbacks are received.
ConversationListener conversationListener;
V2TIMManager::GetInstance()->GetConversationManager()->AddConversationListener(&conversationListener);

Getting the notification of a conversation change

You can listen for the event in V2TIMConversationListener (Android / iOS and macOS / Windows) to get the notification of a conversation list change.
Currently, the IM SDK supports the following conversation change events:
Event
Description
Suggestion
onSyncServerStart
Server conversation sync started.
Listen for such an event when the user logged in successfully or went online or the network was disconnected and reconnected and display the 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.
Listen for such an event and display the exception on the UI.
onNewConversation
There is a new conversation.
Re-sort the conversations when the user receives a one-to-one message from a new colleague or is invited to a new group.
onConversationChanged
A conversation was updated.
Re-sort the conversations when the unread count changes or the last message is updated.
onConversationDeleted
A conversation was deleted.
For more information, see Deleting Conversation. This event is supported by v7.2.4123 or later.
onTotalUnreadMessageCountChanged
The total unread count of the conversation changed.
For more information, see Conversation Unread Count. This event is supported by v5.3.425 or later.
onUnreadMessageCountChangedByFilter
The total unread count of the conversation by filter changed.
For more information, see Conversation Unread Count. This event is supported by v7.0.3754 or later.
Caution
1. To ensure that the conversations are sorted by the last message, you need to re-sort the data sources each time a conversation is changed/added.
If you use the version earlier than v5.5.892, you can sort the conversations by lastMessage, but note that sometimes lastMessage may be empty (such as when messages in a conversation are cleared).
If you use the SDK on v5.5.892 or later, you can sort the conversations by orderKey. Therefore, we recommend you upgrade the SDK to v5.5.892 or later.
2. Conversations pulled by calling the getConversationList API may have been added to the data source of the conversation list on the UI through the onNewConversation callback API. To avoid adding the same conversation repeatedly, you need to find and replace the same conversation based on getConversationID in the data source of the conversation list on the UI.
Sample code:
Android
iOS and macOS
Windows
// Listen for the conversation callback

V2TIMConversationListener conversationListener = new V2TIMConversationListener() {
@Override
public void onSyncServerStart() {
Log.i("imsdk", "onSyncServerStart");
}

@Override
public void onSyncServerFinish() {
Log.i("imsdk", "onSyncServerFinish");
}

@Override
public void onSyncServerFailed() {
Log.i("imsdk", "onSyncServerFailed");
}

@Override
public void onNewConversation(List<V2TIMConversation> conversationList) {
Log.i("imsdk", "onNewConversation");
}

@Override
public void onConversationChanged(List<V2TIMConversation> conversationList) {
Log.i("imsdk", "onConversationChanged");
}

@Override
public void onConversationDeleted(List<String> conversationIDList) {
Log.i("imsdk", "onConversationDeleted");
}

@Override
public void onTotalUnreadMessageCountChanged(long totalUnreadCount) {
Log.i("imsdk", "onTotalUnreadMessageCountChanged");
}

@Override
public void onUnreadMessageCountChangedByFilter(V2TIMConversationListFilter filter, long totalUnreadCount) {
Log.i("imsdk", "onUnreadMessageCountChangedByFilter");
}
};
- (void)onSyncServerStart {
// Server conversation sync started.
}

- (void)onSyncServerFinish {
// Server conversation sync ended.
}

- (void)onSyncServerFailed {
// Server conversation sync failed.
}

- (void)onNewConversation:(NSArray<V2TIMConversation*> *)conversationList {
// Received the notification of a new conversation. `conversationList` is the new conversation.
[self updateConversation:conversationList];
}

- (void)onConversationChanged:(NSArray<V2TIMConversation*> *)conversationList {
// Received the notification of a conversation change. `conversationList` is the changed conversation object.
[self updateConversation:conversationList];
}


- (void)onConversationDeleted:(NSArray<NSString *> *)conversationIDList {
// Conversation was deleted
}

- (void)onTotalUnreadMessageCountChanged:(UInt64) totalUnreadCount {
// Change in total number of unread conversations
}


- (void)onUnreadMessageCountChangedByFilter:(V2TIMConversationListFilter *)filter totalUnreadCount:(UInt64)totalUnreadCount {
// Change in total number of unread conversations by filter
}

- (void)updateConversation:(NSArray *)convList {
// Update the conversation list on the UI. If the new/changed conversation already exists in the conversation list on the UI,
// replace the existing conversation with that new/changed conversation; otherwise, add a conversation object.
for (int i = 0 ; i < convList.count ; ++ i) {
V2TIMConversation *conv = convList[i];
BOOL isExit = NO;
for (int j = 0; j < self.localConvList.count; ++ j) {
V2TIMConversation *localConv = self.localConvList[j];
if ([localConv.conversationID isEqualToString:conv.conversationID]) {
// If the updated conversation exists in the UI conversation list, replace this conversation.
[self.localConvList replaceObjectAtIndex:j withObject:conv];
isExit = YES;
break;
}
}
// If the updated conversation does not exist in the UI conversation list, add this conversation.
if (!isExit) {
[self.localConvList addObject:conv];
}
}
// Re-sort the conversations on the UI
[self sortDataList:dataList];
self.dataList = dataList;
}
class ConversationListener final : public V2TIMConversationListener {
public:
ConversationListener() = default;
~ConversationListener() override = default;

void OnSyncServerStart() override {
// Server conversation sync started.
}

void OnSyncServerFinish() override {
// Server conversation sync ended.
}

void OnSyncServerFailed() override {
// Server conversation sync failed.
}

void OnNewConversation(const V2TIMConversationVector& conversationList) override {
// Received the notification of a new conversation. `conversationList` is the new conversation.
}

void OnConversationChanged(const V2TIMConversationVector& conversationList) override {
// Received the notification of a conversation change. `conversationList` is the changed conversation object.
}

void OnConversationDeleted(const V2TIMStringVector &conversationIDList) override {
// Conversation was deleted
}

void OnTotalUnreadMessageCountChanged(uint64_t totalUnreadCount) override {
// Change in total number of unread conversations
}

void OnUnreadMessageCountChangedByFilter(const V2TIMConversationListFilter &filter, uint64_t totalUnreadCount) {
// Change in total number of unread conversations by filter
}
};

// Note that `conversationListener` should not be released before the IM SDK is uninitialized,
// otherwise the message callback cannot be called.
ConversationListener conversationListener;
V2TIMManager::GetInstance()->GetConversationManager()->AddConversationListener(&conversationListener);

Removing a conversation listener

Call removeConversationListener (Android / iOS and macOS / Windows) to remove a conversation listener to stop receiving conversation change events. This step is optional and can be performed as needed.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getConversationManager().removeConversationListener(conversationListener);
// `self` is of the id<V2TIMConversationListener> type.
[[V2TIMManager sharedInstance] removeConversationListener:self];
class ConversationListener final : public V2TIMConversationListener {
// Member...
};

// `conversationListener` is the instance of `ConversationListener`.
V2TIMManager::GetInstance()->GetConversationManager()->RemoveConversationListener(&conversationListener);

Sending a message without updating the lastMessage

On UI of the conversation list, it is usually necessary to display the preview and send time of the latest message in each conversation. In this case, you can use 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.
For directions on how to send a message by calling sendMessage, see Sending Message.
Note
The isExcludedFromLastMessage parameter is supported only by the SDK of the Enhanced edition on v5.4.666 or later.
Sample code:
Android
iOS and macOS
Windows
// Create the message object
V2TIMMessage v2TIMMessage = V2TIMManager.getMessageManager().createTextMessage(content);
// Set not to update the `lastMessage` of the conversation
v2TIMMessage.setExcludedFromLastMessage(true);

// Send the message
V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, "userID", null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {
@Override
public void onSuccess(V2TIMMessage v2TIMMessage) {
Log.i("imsdk", "success");
}

@Override
public void onProgress(int progress) {
Log.i("imsdk", "progress:" + progress);
}

@Override
public void onError(int code, String desc) {
Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
}
});
// Create the message object
V2TIMMessage *message = [V2TIMManager.sharedInstance createTextMessage:content];
// Set not to update the `lastMessage` of the conversation
message.isExcludedFromLastMessage = YES;
// Send the message
[V2TIMManager.sharedInstance sendMessage:message
receiver:@"userA"
groupID:nil
priority:V2TIM_PRIORITY_NORMAL
onlineUserOnly:NO
offlinePushInfo:nil
progress:^(uint32_t progress) {
// Sending progress
} succ:^{
// Message sent successfully
} fail:^(int code, NSString *desc) {
// The message failed to be sent
}];
class SendCallback final : public V2TIMSendCallback {
public:
using SuccessCallback = std::function<void(const V2TIMMessage&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;
using ProgressCallback = std::function<void(uint32_t)>;

SendCallback() = default;
~SendCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback,
ProgressCallback progress_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
progress_callback_ = std::move(progress_callback);
}

void OnSuccess(const V2TIMMessage& message) override {
if (success_callback_) {
success_callback_(message);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}
void OnProgress(uint32_t progress) override {
if (progress_callback_) {
progress_callback_(progress);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
ProgressCallback progress_callback_;
};

// Create the message object
V2TIMMessage message = V2TIMManager::GetInstance()->GetMessageManager()->CreateTextMessage(u8"content");
// Set not to update the `lastMessage` of the conversation
message.isExcludedFromLastMessage = true;

auto callback = new SendCallback{};
callback->SetCallback([=](const V2TIMMessage& message) { delete callback; },
[=](int error_code, const V2TIMString& error_message) { delete callback; },
[=](uint32_t progress) {});

V2TIMManager::GetInstance()->GetMessageManager()->SendMessage(
message, u8"userID", {}, V2TIMMessagePriority::V2TIM_PRIORITY_NORMAL, false, {}, callback);