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

메시지 철회

Overview

The sender can recall a successfully sent message.
By default, the sender can recall a message that is sent within 2 minutes. You can change the time limit for message recall. For detailed directions, see Message recall settings.
Message recall can be implemented through the receiver UI code: When a message is recalled, the receiver will receive the onRecvMessageRevoked notification which contains the msgID of the recalled message. You can identify the recalled message at the UI layer based on the msgID and change the bubble for the message to the "Message recalled" status.
In one-to-one chats, only the sender can recall their own messages through this API.
In group chats, not only the sender can recall their own message, but administrators or group owners can also recall messages sent by other group members through this API.
This API is available for all group types, including audio-video groups (AVChatRoom) and community groups, in 7.4 and later versions.

Recalling a Message (by the Sender)

The sender can call revokeMessage (Android / iOS and macOS / Windows) to recall a message.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getMessageManager().revokeMessage(v2TIMMessage, new V2TIMCallback() {
@Override
public void onError(int code, String desc) {
// The message failed to be recalled
}
@Override
public void onSuccess() {
// Message recalled successfully
}
});
// `selectedMessage` is the message to be recalled.
[[V2TIMManager sharedInstance] revokeMessage:selectedMessage
succ:^{
// Message recalled successfully
} fail:^(int code, NSString *msg) {
// The message failed to be recalled
}];
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(
[=]() {
// Message recalled successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// The message failed to be recalled
delete callback;
});

V2TIMManager::GetInstance()->GetMessageManager()->RevokeMessage(message, callback);

Noticing a Message Recall (by the Receiver)

1. The receiver calls addAdvancedMsgListener (Android / iOS and macOS / Windows) to set the advanced message listener.
2. The receiver receives the message recall notification in onRecvMessageRevoked (Android / iOS & Mac / Windows) .
Note:
Starting from version 7.4, when a message is revoked, the receiver can obtain the reason for revocation and the revoker of the message through the API onRecvMessageRevoked.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getMessageManager().addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {
@Override
public void onRecvMessageRevoked(String msgID, V2TIMUserFullInfo operateUser, String reason) {
for (V2TIMMessage msg : msgList) {
if (msg.getMsgID().equals(msgID)) {
// You need to change the bubble status for the message on the UI after receiving the message recall notification.
}
}
}
}
// V2TIMAdvancedMsgListener
- (void)onRecvMessageRevoked:(NSString *)msgID operateUser:(V2TIMUserFullInfo *)operateUser reason:(NSString *)reason {
// You need to change the bubble status for the message on the UI after receiving the message recall notification.
}
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
public:
/**
* Received a new message
*
* @param message Message
*/
/**
* Received a message recall notification
*
* @param messageID Unique message ID
*/
void OnRecvMessageRevoked(const V2TIMString& messageID, 
const V2TIMUserFullInfo &operateUser, 
const V2TIMString &reason) overrid {
// `msgList` is the message list on the current chat interface
}
// Other members …
};

// Add an event listener for advanced messages. Keep `advancedMsgListener` valid before it is removed to ensure event callbacks are received.
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);