pinConversation
(Android / iOS and Mac / Windows) to set whether to pin a conversation to the top.getConversationList
is called to get the conversation list, it will first return the conversation that is pinned to the top and then other conversations. You can check whether a conversation is pinned to the top through the isPinned
field of the V2TIMConversation
object.orderKey
field of the V2TIMConversation
object. This 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.// If `isPinned` is `true`, the conversation is pinned to the top; otherwise, it is not.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);}});
// If `isPinned` is `YES`, the conversation is pinned to the top; otherwise, it is not.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([=]() {// The conversation is pinned to top successfully.delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pin the conversation to the top.delete callback;});V2TIMManager::GetInstance()->GetConversationManager()->PinConversation(conversationID, isPinned, callback);
addConversationListener
(Android / iOS and macOS / Windows) to add a conversation listener, you can get the isPinned
value of the V2TIMConversation
object in onConversationChanged
and determine whether the pinned status of a conversation has changed.public void onConversationChanged(List<V2TIMConversation> conversationList) {// Received the notification of a change in the conversation informationLog.i("imsdk", "onConversationChanged");}
- (void)onConversationChanged:(NSArray<V2TIMConversation*> *) conversationList {for (V2TIMConversation *conv in conversationList) {if ([conv.conversationID isEqualToString:self.conversationData.conversationID]) {// `conv.isPinned` is the pinned status.}}}
class ConversationListener final : public V2TIMConversationListener {public:void OnConversationChanged(const V2TIMConversationVector& conversationList) override {// Received the notification of a change in the conversation information}// Other members …};// 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);
Was this page helpful?