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";
V2TIMString draftText = u8"The draft text";
auto callback = new Callback;
callback->SetCallback(
[=]() {
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
delete callback;
});
V2TIMManager::GetInstance()->GetConversationManager()->SetConversationDraft(conversationID, draftText,
callback);
Was this page helpful?