Delete Message
After a user successfully sends a message, they might discover errors in the content and wish to delete it.
Usage
Global IM UIKit enables the delete feature by default. By long-pressing a message (a successfully sent message) in the chat UI, a pop-up window will appear. After clicking delete, options such as Delete on My Device or Delete on All Devices may appear. After deleting on all devices, the message can be re-edited within a certain time frame.
Global IM UIKit implements the message deletion feature as shown above:
- Delete on My Device: Deletes the message from the local message database on the user's device. If message cloud storage is enabled, the corresponding message in the user's cloud history will also be deleted.
- Delete on All Devices: Removes the message from the message sender's (current user) and recipients' message records, effectively recalling the message. By default, this operation is allowed within 120 seconds after the message is sent. After this period, the option will no longer be displayed. After successful deletion, the IMLib SDK replaces the original message in the local message database with a recall notification message (
RCRecallNotificationMessage
). If message cloud storage is enabled, the corresponding message in the cloud history of the current user and all recipients will also be deleted.
Customization
Modify the Time Limit for Deleting on All Devices
Global IM UIKit allows deleting messages on all devices within 120 seconds after sending by default. You can adjust this limit through the chat UI configuration.
self.config.recallDuration = 120;
Handle the Re-edit Button Click Event
After deleting a message, the RCRecallNotificationMessage
is displayed in the chat UI, and the "Re-edit" button appears in the message cell. Regardless of whether the input box has content, each click on re-edit appends a new line, allowing infinite additions. To adjust the re-edit click event, you can override the tableViewCell:didTapReedit:
method in the chat UI:
/*!
Callback for tapping the re-edit button in the recall message cell
- Parameter model: The data model of the message cell
Tapping the re-edit button in the recall message cell will trigger this callback and will not trigger didTapMessageCell:.
*/
- (void)tableViewCell:(UITableViewCell *)cell
didTapReedit:(RCMessageModel *)messageModel;
Customize the Delete Event Handling
The edit events displayed when long-pressing a message can be adjusted by overriding the willDisplayEditMenu:forMessageModel:
method to modify existing events or add new ones:
- (NSArray<RCMessageEditBarItem *> *)willDisplayEditMenu:(NSArray<RCMessageEditBarItem *> *)items forMessageModel:(RCMessageModel *)messageModel {
NSArray *array = [super willDisplayEditMenu:items forMessageModel:messageModel];
for (RCMessageEditBarItem *item in array) {
if (item.tag == RCMessageEditBarItemDelete) {
item.action = ^(RCBarItem *item) {
// custom action
};
break;
}
}
return array;
}
If the existing implementation does not meet your needs, you can use the relevant APIs in the IMLib SDK. Refer to the following documents for more details:
Permissions for Deleting Messages on All Devices
By default, the IM Service does not restrict who can perform the "Delete on All Devices" operation. This means that if you customize the UI, you could allow admin users in your app to recall messages sent by others, or, due to improper implementation, anyone could recall messages sent by others.
When customizing the delete message feature in Global IM UIKit, if you need to restrict permissions for deleting messages on all devices, consider the following solutions:
- Override the
willDisplayEditMenu:forMessageModel:
method in the app client to determine whether a user can delete based on business requirements. - To prevent users from recalling messages not sent by themselves, you can submit a ticket to enable the IMLib SDK Only Allows Recalling Messages Sent by Yourself feature. This restricts users from recalling messages not sent by themselves from the RC server.