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.V2TIMConversation
objects. SDK sorts conversations according to the following rules:orderKey
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.lastMessage
-> timestamp
of the conversation by default. The greater the timestamp
value, the higher the position of the conversation is in the list.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
.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).V2TIMManager.getConversationManager().getConversationList(0, Integer.MAX_VALUE, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic 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());}}@Overridepublic void onError(int code, String desc) {Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);}});
[[V2TIMManager sharedInstance] getConversationList:0count:INT_MAXsucc:^(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 successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtain the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationList(nextSeq, count, callback);
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 software, a paged pull is often triggered by a swipe operation.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.isFinished
is true
.V2TIMManager.getConversationManager().getConversationList(0, 20, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic 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);}}@Overridepublic 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.nextSeqcount:20 // Pull 20 conversations each timesucc:^(NSArray<V2TIMConversation *> *list, uint64_t nextSeq, BOOL isFinished) {// Conversations pulled successfully@strongify(self)// Update the `nextSeq` and `isFinished` for the next pullself.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 successfullyif (!conversationResult.isFinished) {nextSeq = conversationResult.nextSeq;// Get more...}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtain the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationList(nextSeq, count, callback);
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) | |
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. |
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();filter.setConversationType(V2TIMConversation.V2TIM_C2C); // Pulling one-to-one conversations// filter.setConversationType(V2TIMConversation.V2TIM_GROUP); // Pulling group conversationsV2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic void onSuccess(V2TIMConversationResult v2TIMConversationResult) {// Conversation list pulled successfully}@Overridepublic void onError(int code, String desc) {// Failed to pull 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 pulled successfully} fail:^(int code, NSString *desc) {// Failed to pull 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 conversationsauto callback = new ValueCallback<V2TIMConversationResult>{};callback->SetCallback([=](const V2TIMConversationResult& conversationResult) {// Conversation list pulled successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pull the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();filter.setConversationGroup("conversation_group");V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic void onSuccess(V2TIMConversationResult v2TIMConversationResult) {// Conversation list pulled successfully}@Overridepublic void onError(int code, String desc) {// Failed to pull 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 pulled successfully} fail:^(int code, NSString *desc) {// Failed to pull 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 pulled successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pull the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();filter.setMarkType(V2TIMConversation.V2TIM_CONVERSATION_MARK_TYPE_STAR);V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic void onSuccess(V2TIMConversationResult v2TIMConversationResult) {// Conversation list pulled successfully}@Overridepublic void onError(int code, String desc) {// Failed to pull 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 pulled successfully} fail:^(int code, NSString *desc) {// Failed to pull 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 pulled successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pull the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();filter.setHasUnreadCount(true);V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic void onSuccess(V2TIMConversationResult v2TIMConversationResult) {// Conversation list pulled successfully}@Overridepublic void onError(int code, String desc) {// Failed to pull 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 pulled successfully} fail:^(int code, NSString *desc) {// Failed to pull 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 pulled successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pull the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);
V2TIMConversationListFilter filter = new V2TIMConversationListFilter();filter.setHasGroupAtInfo(true);V2TIMManager.getConversationManager().getConversationListByFilter(filter, 0, 50, new V2TIMValueCallback<V2TIMConversationResult>() {@Overridepublic void onSuccess(V2TIMConversationResult v2TIMConversationResult) {// Conversation list pulled successfully}@Overridepublic void onError(int code, String desc) {// Failed to pull 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 pulled successfully} fail:^(int code, NSString *desc) {// Failed to pull 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 pulled successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pull the conversation listdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->GetConversationListByFilter(filter, 0, 50, callback);
V2TIMConversation.orderKey
, and the orderKey
will be incremented as the conversation is updated.orderKey
to increment include: sending and receiving messages (that is, changes in lastMessage
), pinning/unpinning.lastMessage
of the conversation is inconsistent with the orderKey
, the order of the orderKey
shall prevail.addConversationListener
(Android / iOS and macOS / Windows) to add a conversation listener to receive conversation change events.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);
V2TIMConversationListener
(Android / iOS and macOS / Windows) to get the notification of a conversation list change.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. | |
onTotalUnreadMessageCountChanged | The total unread count of the conversation changed. | |
onUnreadMessageCountChangedByFilter | The total unread count of the conversation by filter changed. |
lastMessage
, but note that sometimes lastMessage
may be empty (such as when messages in a conversation are cleared).orderKey
. Therefore, we recommend you upgrade the SDK to v5.5.892 or later.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.// Listen for the conversation callbackV2TIMConversationListener conversationListener = new V2TIMConversationListener() {@Overridepublic void onSyncServerStart() {Log.i("imsdk", "onSyncServerStart");}@Overridepublic void onSyncServerFinish() {Log.i("imsdk", "onSyncServerFinish");}@Overridepublic void onSyncServerFailed() {Log.i("imsdk", "onSyncServerFailed");}@Overridepublic void onNewConversation(List<V2TIMConversation> conversationList) {Log.i("imsdk", "onNewConversation");}@Overridepublic void onConversationChanged(List<V2TIMConversation> conversationList) {Log.i("imsdk", "onConversationChanged");}@Overridepublic void onConversationDeleted(List<String> conversationIDList) {Log.i("imsdk", "onConversationDeleted");}@Overridepublic void onTotalUnreadMessageCountChanged(long totalUnreadCount) {Log.i("imsdk", "onTotalUnreadMessageCountChanged");}@Overridepublic 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);
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.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);
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
.isExcludedFromLastMessage
parameter is supported only by the SDK of the Enhanced edition on v5.4.666 or later.// Create the message objectV2TIMMessage v2TIMMessage = V2TIMManager.getMessageManager().createTextMessage(content);// Set not to update the `lastMessage` of the conversationv2TIMMessage.setExcludedFromLastMessage(true);// Send the messageV2TIMManager.getMessageManager().sendMessage(v2TIMMessage, "userID", null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {Log.i("imsdk", "success");}@Overridepublic void onProgress(int progress) {Log.i("imsdk", "progress:" + progress);}@Overridepublic void onError(int code, String desc) {Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);}});
// Create the message objectV2TIMMessage *message = [V2TIMManager.sharedInstance createTextMessage:content];// Set not to update the `lastMessage` of the conversationmessage.isExcludedFromLastMessage = YES;// Send the message[V2TIMManager.sharedInstance sendMessage:messagereceiver:@"userA"groupID:nilpriority:V2TIM_PRIORITY_NORMALonlineUserOnly:NOofflinePushInfo:nilprogress:^(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