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

과거 메시지 비우기

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 (Android / iOS and macOS / Windows) to clear one-to-one messages.
Sample code:
Android
iOS and macOS
Windows
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.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 (Android / iOS and macOS / Windows) to clear group messages.
Sample code:
Android
iOS and macOS
Windows
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 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);