getConversationList
获取会话列表时,该接口返回的会话列表中,置顶的会话在前,未置顶的会话在后。您可以通过 V2TIMConversation
对象的 isPinned
字段,检查会话有没有置顶。V2TIMConversation
对象的 orderKey
字段排序。orderKey
字段是整型数,当发送新消息、接收新消息、设置草稿或置顶会话时,会话被激活,orderKey
字段会增大。// isPinned 参数为 true,表示置顶会话,否则,表示取消置顶。String conversationID = "conversationID";V2TIMManager.getConversationManager().pinConversation(conversationID, true, new V2TIMCallback() {@Overridepublic void onSuccess() {Log.i("imsdk", "success");}@Overridepublic void onError(int code, String desc) {Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);}});
// isPinned 参数为 YES,表示置顶会话,否则,表示取消置顶。NSString *conversationID = @"conversationID";[[V2TIMManager sharedInstance] pinConversation:conversationID isPinned:YES succ:^{NSLog(@"success");} fail:^(int code, NSString *desc) {NSLog(@"failure, code:%d, desc:%@", code, desc);}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}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_;};V2TIMString conversationID = u8"conversationID";bool isPinned = true;auto callback = new Callback;callback->SetCallback([=]() {// 置顶会话成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 置顶会话失败delete callback;});V2TIMManager::GetInstance()->GetConversationManager()->PinConversation(conversationID, isPinned, callback);
addConversationListener
(Android / iOS & Mac / Windows) 添加会话监听器,就可以在 onConversationChanged
中获取到 V2TIMConversation
对象的 isPinned
字段值。根据这个字段可以判断会话的置顶状态是否变化。public void onConversationChanged(List<V2TIMConversation> conversationList) {// 收到会话信息变更通知Log.i("imsdk", "onConversationChanged");}
- (void)onConversationChanged:(NSArray<V2TIMConversation*> *) conversationList {for (V2TIMConversation *conv in conversationList) {if ([conv.conversationID isEqualToString:self.conversationData.conversationID]) {// conv.isPinned 为会话置顶状态}}}
class ConversationListener final : public V2TIMConversationListener {public:void OnConversationChanged(const V2TIMConversationVector& conversationList) override {// 收到会话信息变更通知}// 其他成员 ...};// 添加会话事件监听器,注意在移除监听器之前需要保持 conversationListener 的生命期,以免接收不到事件回调ConversationListener conversationListener;V2TIMManager::GetInstance()->GetConversationManager()->AddConversationListener(&conversationListener);
本页内容是否解决了您的问题?