이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

대화 획득

Overview

The SDK provides an API for getting conversations, which can be used to get the V2TIMConversation object information of one or multiple specified conversations.

Getting a specified conversation

Call getConversation (Android / iOS and macOS / Windows) to get the information of a conversation, which is a V2TIMConversation object. The composition of conversationID can be referred to the Overview.
Sample code:
Android
iOS and macOS
Windows
String conversationID = "conversationID";
V2TIMManager.getConversationManager().getConversation(conversationID, new V2TIMValueCallback<V2TIMConversation>() {
@Override
public void onSuccess(V2TIMConversation v2TIMConversation) {
Log.i("imsdk", "success");
}

@Override
public void onError(int code, String desc) {
Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
}
});
[V2TIMManager.sharedInstance getConversation:@"conversationID" // ID of the conversation to be queried
succ:^(V2TIMConversation *conv) {
// The conversation obtained successfully. The `V2TIMConversation` object was returned.
} fail:^(int code, NSString *desc) {
// 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_;
};

V2TIMString conversationID = u8"conversationID";

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

V2TIMManager::GetInstance()->GetConversationManager()->GetConversation(conversationID, callback);

Getting specified conversations

Call getConversationList (Android / iOS and macOS / Windows) to get the list of specified conversations that stores V2TIMConversation objects.
Sample code:
Android
iOS and macOS
Windows
List<String> conversationIDList = new ArrayList<>();
conversationIDList.add("conversationID1");
conversationIDList.add("conversationID1");

V2TIMManager.getConversationManager().getConversationList(conversationIDList, new V2TIMValueCallback<List<V2TIMConversation>>() {
@Override
public void onSuccess(List<V2TIMConversation> conversationList) {
Log.i("imsdk", "success");
}

@Override
public void onError(int code, String desc) {
Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
}
});
[V2TIMManager.sharedInstance getConversationList:@[@"convID1", @"convID2"] // List of IDs of the conversations to be queried
succ:^(NSArray<V2TIMConversation *> *list) {
// Conversations obtained successfully. The `list` contains `V2TIMConversation` objects.
} fail:^(int code, NSString *desc) {
// 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_;
};

V2TIMStringVector conversationIDList;
conversationIDList.PushBack(u8"conversationID1");
conversationIDList.PushBack(u8"conversationID2");

auto callback = new ValueCallback<V2TIMConversationVector>{};
callback->SetCallback(
[=](const V2TIMConversationVector& conversationList) {
// Obtained multiple conversations successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain multiple conversations
delete callback;
});

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