このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

過去のメッセージをクリアします

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

Call clearC2CHistoryMessage (Java / Swift / Objective-C / C++) to clear one-to-one messages.
Sample code:
Java
Swift
Objective-C
C++
V2TIMManager.getMessageManager().clearC2CHistoryMessage(userID, new V2TIMCallback() {
@Override
public void onSuccess() {
// One-to-one messages cleared successfully
}

@Override
public void onError(int code, String desc) {
// Failed to clear one-to-one messages
}
});
V2TIMManager.shared.clearC2CHistoryMessage(userID: "userID") {
print("clearC2CHistoryMessage succ")
} fail: { code, desc in
print("clearC2CHistoryMessage fail, \(code), \(desc)")
}
[V2TIMManager.sharedInstance clearC2CHistoryMessage:userID
succ:^{
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 successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to clear one-to-one messages
delete callback;
});

Clearing group messages

Call clearGroupHistoryMessage (Java / Swift / Objective-C / C++) to clear group messages.
Sample code:
Java
Swift
Objective-C
C++
V2TIMManager.getMessageManager().clearGroupHistoryMessage(GroupID, new V2TIMCallback() {
@Override
public void onSuccess() {
// Group messages cleared successfully
}

@Override
public void onError(int code, String desc) {
// Failed to clear group messages
}
});
V2TIMManager.shared.clearGroupHistoryMessage(groupID: "groupID") {
print("clearGroupHistoryMessage succ")
} fail: { code, desc in
print("clearGroupHistoryMessage fail, \(code), \(desc)")
}
[[V2TIMManager sharedInstance] clearGroupHistoryMessage:groupID
succ:^{
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 successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to clear group messages
delete callback;
});

V2TIMManager::GetInstance()->GetMessageManager()->ClearGroupHistoryMessage(groupID, callback);