Skip to main content
Who can delete: Message sender, Group admin, Group moderator Deleted fields: deletedAt (timestamp), deletedBy (user who deleted)
This operation is irreversible. Deleted messages cannot be recovered.
While deleting a message is straightforward, receiving events for deleted messages with CometChat has two parts:
  1. Adding a listener to receive real-time message deletes when your app is running.
  2. Calling a method to retrieve missed message delete events when your app was not running.
Available via: SDK | REST API | UI Kits

Delete a Message

In other words, as a sender, how do I delete a message? Use deleteMessage() with the message ID of the message to be deleted.
On Success — A BaseMessage object with deletedAt and deletedBy fields set:BaseMessage Object:
sender Object:
receiver Object:
The deleted message object is returned with deletedAt (timestamp) and deletedBy (UID of deleter) fields set. Relevant fields to access on the returned message: By default, CometChat allows certain roles to delete a message.

Real-time Message Delete Events

In other words, as a recipient, how do I know when someone deletes a message when my app is running? Use onMessageDeleted in MessageListener to receive real-time delete events.
Always remove message listeners when they’re no longer needed (e.g., in the dispose() method). Failing to remove listeners can cause memory leaks and duplicate event handling.
The onMessageDeleted callback receives a BaseMessage object with the deletedAt and deletedBy fields set. Relevant fields to access on the returned message:

Missed Message Delete Events

In other words, as a recipient, how do I know if someone deleted a message when my app was not running? When you retrieve the list of previous messages, for the messages that were deleted, the deletedAt and the deletedBy fields will be set. Also, for example, if the total number of messages for a conversation are 100, and the message with message ID 50 was deleted. Now the message with ID 50 will have the deletedAt and the deletedBy fields set whenever it is pulled from the history. Also, the 101st message will be an Action message informing you that the message with ID 50 has been deleted. For the message deleted event, in the Action object received, the following fields can help you get the relevant information-
  1. action - deleted
  2. actionOn - Updated message object which was deleted.
  3. actionBy - User object containing the details of the user who has deleted the message.
  4. actionFor - User/group object having the details of the receiver to which the message was sent.
You must be the message sender or a group admin/moderator to delete a message.

Next Steps

Edit Message

Modify sent messages before deletion

Send Message

Send text, media, and custom messages

Receive Messages

Handle incoming messages in real-time

Flag a Message

Report inappropriate messages