Skip to main content
Deleting a message is straightforward. Receiving delete events has two parts:
  1. Adding a listener for real-time deletes when your app is running
  2. Fetching missed deletes when your app was offline

Delete a Message

Use deleteMessage() with the message ID.
Once the message is deleted, In the onSuccess() callback, you get an object of the BaseMessage class, with the deletedAt field set with the timestamp of the time the message was deleted. Also, the deletedBy field is set. These two fields can be used to identify if the message is deleted while iterating through a list of messages. By default, CometChat allows certain roles to delete a message.

Real-time Message Delete Events

Use onMessageDeleted in MessageListener to receive real-time delete events.
Always remove listeners when they’re no longer needed (e.g., in onDestroy() or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.

Missed Message Delete Events

When fetching message history, deleted messages have deletedAt and deletedBy fields set. Additionally, an Action message is created when a message is 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.
In order to delete a message, you need to be either the sender of the message or the admin/moderator of the group in which the message was sent.


Next Steps

Edit Message

Modify text and custom messages after sending

Send Message

Send text, media, and custom messages

Receive Messages

Handle real-time message events with listeners

Message Structure

Understand message types and properties