과거 메시지 비우기
Overview
One-to-one messages and group messages can be cleared.
When messages in a conversation are cleared, all the messages in the conversation will be cleared both locally and from the cloud, but the conversation itself will not be deleted.
Note
Do not use this API if you do not want to clear messages from the cloud.
This API is supported by the SDK on v5.4.666 or later.
After messages are cleared, the
lastMessage
in the conversation will become empty, and:If your SDK version is earlier than v5.5.892 and the
lastMessage
is used for sorting, the sequence in the conversation list will be affected.If your SDK is on v5.5.892 or later and
orderKey
is used for sorting, the sequence in the conversation list will not be affected.
For more information, see Conversation List.Clearing one-to-one messages
Sample code:
V2TIMManager.getMessageManager().clearC2CHistoryMessage(userID, new V2TIMCallback() {@Overridepublic void onSuccess() {// One-to-one messages cleared successfully}@Overridepublic void onError(int code, String desc) {// Failed to clear one-to-one messages}});
[V2TIMManager.sharedInstance clearC2CHistoryMessage:userIDsucc:^{NSLog(@"One-to-one messages cleared successfully");} fail:^(int code, NSString *desc) {NSLog(@"Failed to clear one-to-one messages, 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_;};auto callback = new Callback;callback->SetCallback([=]() {// One-to-one messages cleared successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to clear one-to-one messagesdelete callback;});
Clearing group messages
Sample code:
V2TIMManager.getMessageManager().clearGroupHistoryMessage(GroupID, new V2TIMCallback() {@Overridepublic void onSuccess() {// Group messages cleared successfully}@Overridepublic void onError(int code, String desc) {// Failed to clear group messages}});
[[V2TIMManager sharedInstance] clearGroupHistoryMessage:groupIDsucc:^{NSLog(@"Group messages cleared successfully");} fail:^(int code, NSString *desc) {NSLog(@"Failed to clear group messages, 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_;};auto callback = new Callback;callback->SetCallback([=]() {// Group messages cleared successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to clear group messagesdelete callback;});V2TIMManager::GetInstance()->GetMessageManager()->ClearGroupHistoryMessage(groupID, callback);