Recall Message
Supports recalling successfully sent messages.
By default, RC does not impose restrictions on who can recall messages. If restrictions are needed, consider the following approaches:
-
The app client can implement its own restrictions on message recall. For example, regular users in the app's business logic may be prohibited from recalling messages sent by others, while administrator roles may be permitted to do so.
-
To prevent users from recalling messages not sent by themselves, you can submit a ticket to enable the IMLib SDK feature that only allows recalling self-sent messages. This implements server-side restrictions to prohibit users from recalling messages not sent by themselves.
Recall Message
Call the recallMessage method to recall a specified message.
On the Electron platform, when receiving a remote recall notification or actively initiating a message recall, if the recall parameter isDelete is false, the SDK will generate a RC:RcNtf message in the local database to replace the original message content.
Interface
RongIMLib.recallMessage(conversation, options)
#### Parameters
| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| conversation | [IConversationOption] | Yes | Target conversation |
| options | [IRecallMessageOptions] | Yes | Parameters for the message to be recalled. See the options parameter description below. |
- **`options` Parameter Description**
| Parameter | Type | Required | Description |
| :------------------ | :----------- | :------- | :---------------------- |
| messageUId | string | Yes | Unique ID of the message |
| sentTime | number | Yes | Timestamp when the message was sent |
| user | IUserProfile | No | User profile of the operator recalling the message |
| disableNotification | boolean | No | Whether to send a silent message |
| pushConfig | IPushConfig | No | Push configuration for mobile devices, similar to MessagePushConfig on Android and iOS |
| extra | string | No | (Supported since 5.3.0) Additional information carried when recalling the message |
| isDelete | boolean | No | (Supported since 5.3.1) Specifies whether the local and recipient's original message records should be deleted.<br/>`false`: Do not delete the original message record, replace it with a recall notification (gray bar notification);<br/>`true`: Delete the original message record without displaying a notification |
| isAdmin | boolean | No | (Supported since 5.16.0) Passes this field during recall for IMKit to display the operator's identity when rendering the recall notification message. No impact on other functionality. |
#### Example Code
```js
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: '<Target User ID>',
}
RongIMLib.recallMessage(conversation, {
messageUId: 'BS4O-QEBR-VJM6-9GPP',
sentTime: 1632728573423,
})
.then((res) => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
})
.catch((error) => {
console.log(error)
})
## Listen for Message Recall Notifications \{#addEventListener}
:::tip[**Note**]
- **One-to-One and Group Chat Business**: Listen for the `Events.MESSAGES` event to receive `RC:RcCmd` and `RC:RcNtf` messages and obtain remote recall notifications.
- **Ultra Group Business**: Listen for the `Events.ULTRA_GROUP_MESSAGE_RECALLED` event to receive remote recall notifications.
:::
#### Example Code
```javascript
// Listen for one-to-one and group chat recall notifications
RongIMLib.addEventListener(RongIMLib.Events.MESSAGES, (messageList) => {
console.log(messageList)
})
// Listen for ultra group recall notifications
RongIMLib.addEventListener(RongIMLib.Events.ULTRA_GROUP_MESSAGE_RECALLED, (messageList) => {
console.log(messageList)
})