Recall messages
Overview
The ZIM SDK supports the ability to recall messages sent by the local end in one-on-one or group chat sessions, as well as the ability for the group owner to recall messages sent by others in a group chat session.
This document describes how to use the interfaces of the ZIM SDK to recall specified messages in a particular session.
If the ZIM SDK version used by the message recipient is lower than 2.5.0, the following three situations may occur when a message is recalled:
- If the user is online and receives the message, they will still see the message.
- If the user is offline and receives the message, they will not see the message if they do not actively query the message history after logging in.
- If the user is offline and receives the message, they will see the message with the message type displayed as "unknown" if they actively query the message history after logging in.
Implementation process
The In-app Chat SDK supports recalling a specified message in a session. Developers can call ZIMMessageRevokeConfig to configure advanced attributes for recalling messages.
Recalling a message sent from Client A to Client B is used as an example:
- Client A and Client B create their In-app Chat instances and register the onMessageRevokeReceived callback API listened for by setEventHandler to receive message recalling notifications.
- Client A and Client B log in to the In-app Chat service.
- Client A sends one-to-one messages to Client B and wants to recall a message.
(1) Client A calls the revokeMessage API and introduces the
message
andconfig
parameters to recall the specified message. (2) Client A obtains the recalling result through the ZIMMessageRevokedCallback callback API. (3) Client B obtains message recalling notifications through the onMessageRevokeReceived callback API.
Configure the function of listening for message recalling
After successful login, users can listen for message recalling notifications through the onMessageRevokeReceived callback API. After other users recall a message, the SDK can obtain related information of the recalled message, including the recalling time and recalled message type.
Recall messages
By default, users can call the revokeMessage API to recall a message sent in 2 minutes. The recalling result will be sent to the user through the ZIMMessageRevokedCallback callback API.
- To enable the group owner to revoke messages from other users, please integrate ZIM SDK version 2.9.0 or above.
- Currently, ZIM SDK supports revoking messages within 2 minutes by default. If you need to modify the configuration (up to 24 hours maximum), please contact ZEGOCLOUD technical support.
ZIMMessage message = new ZIMMessage();
ZIMPushConfig pushConfig = new ZIMPushConfig();
pushConfig.content = "content";
pushConfig.title = "title";
ZIMMessageRevokeConfig revokeConfigConfig = new ZIMMessageRevokeConfig();
revokeConfigConfig.config = pushConfig;
ZIM.GetInstance().RevokeMessage(message, revokeConfigConfig, (ZIMMessage message, ZIMError errorInfo) =>
{
// Resule of the recall operation.
});