Skip to main content

Recall Message

After a user successfully sends a message through the app, they might discover that the message content is incorrect or needs to be retracted. They may wish to recall the message and remove it from the recipient's message history. You can use the recall message feature to fulfill this requirement.

recallMessage will replace the original message in the chat history with a recall notification message (RecallNotificationMessage) with the objectName RC:RcNtf. Additionally, the message recipient can receive server notifications through the OnRecallMessageListener listener. When a recall notification is received, the recipient can perform corresponding actions and refresh the interface.

For the structure of the recall notification message, refer to the server documentation Notification Message Format.

By default, RC does not restrict who can recall messages. If you need to impose restrictions, consider the following solutions:

  • The app client can restrict the operator of the recall message. For example, regular users in the app’s business logic may not be allowed to recall messages sent by others, while administrators can recall messages sent by others.
  • To prevent users from recalling messages sent by others, you can submit a ticket to enable the IMLib SDK to only allow recalling messages sent by oneself. This restriction is enforced by the RC server, preventing users from recalling messages not sent by themselves.

IMLib does not impose a time limit on recalling messages. However, most mainstream social apps enforce a time limit for message recall. It is recommended that developers implement their own time restrictions for message recall.

Recall Message

Recall a specific message. Only successfully sent messages can be recalled. The result of the recall is returned via the callback. The onSuccess callback will return the replaced recall notification message (RecallNotificationMessage), which you can display in the interface as needed.

RongIMClient.getInstance().recallMessage(message, pushContent, callback);
ParameterTypeDescription
messageMessageThe message object to be recalled
pushContentStringWhen sending a push message, this field will be displayed in the notification bar. For custom messages, this field must be filled; otherwise, the push message will not be received. For default message types like RC:TxtMsg, RC:VcMsg, RC:ImgMsg, this field is not required as it is already specified by the SDK.
callbackIRongCallback.ResultCallback<RecallNotificationMessage>Callback interface
Message message = Message.obtain("123", ConversationType.GROUP, "12345");

RongIMClient.getInstance().recallMessage(message, " ", new RongIMClient.ResultCallback<RecallNotificationMessage>() {
/**
* Success callback
*/
@Override
public void onSuccess(RecallNotificationMessage recallNotificationMessage) {

}

/**
* Failure callback
* @param errorCode Error code
*/
@Override
public void onError(RongIMClient.ErrorCode errorCode) {

}
});

If you need to recall a message using the message ID (database index unique value) or UID (server message unique ID), you can first retrieve the message to be recalled using the following methods, and then use recallMessage to recall it.

    /**
* Get the message body by message ID (database index unique value).
*
* @param messageId Message ID.
* @param callback Callback.
*/
public abstract void getMessage(final int messageId, final ResultCallback<Message> callback);

/**
* Get the message entity by global unique ID.
*
* @param uid Global unique ID (server message unique ID).
* @param callback Callback to retrieve the message.
*/
public abstract void getMessageByUid(final String uid, final ResultCallback<Message> callback);

Listen for Message Recall Events

After the message sender calls recallMessage, the message recipient can listen for the message recall event through OnRecallMessageListener and handle it accordingly.

The message recipient needs to use setOnRecallMessageListener to set up a listener to monitor the recall of received messages. When a received message is recalled, this listener will be triggered.

RongIMClient.setOnRecallMessageListener(listener);

The listener parameter is the message recall listener (OnRecallMessageListener), which provides an onMessageRecalled method as follows:

Return TypeMethodDescription
booleanonMessageRecalled(Message message, RecallNotificationMessage recallNotificationMessage)This callback is triggered when a received message is recalled.