please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Android/
Message/
SDK
  • Install Chat SDK
  • Initialize Chat SDK
  • Login and Logout
  • Message
    • Overview
    • Send a Message
    • Receive a Message
    • Retrieve Messages
    • Forward Messages
    • Modify a Message
    • Insert a Message
    • Delete Messages
    • Clear History Messages
    • Recall a Message
    • Send an Online Message
    • Message Read Receipt
    • Query Messages
    • Mentions
    • Targeted Group Message
    • Do not Notify
    • Key-Value Extensions
    • Reactions
    • Translation
    • Pin Messages
  • Conversation
    • Overview
    • Conversation List
    • Get Conversations
    • Unread Count
    • Pin Conversations
    • Delete Conversations
    • Draft
    • Mark
    • Conversation Group
  • Group
    • Overview
    • Manage Group
    • Profile
    • Manage Members
    • Member Profile
    • Attribute
    • Counter
  • Community and Topic
    • Manage Community
    • Permission Group
  • User
    • User Profile
    • User Status
    • Manage Friends
    • Friend Group
    • Block Lists
    • Follow
  • Local Search
    • Search Messages
    • Search Friends
    • Search Groups
    • Search Group Members
  • Signaling
  • API Reference
    • Java
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Recall a Message

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);