Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Edit a text message
val updatedMessage = TextMessage(
    message.receiverUid, 
    "Updated text", 
    message.receiverType
)
updatedMessage.id = message.id

CometChat.editMessage(updatedMessage, object: CometChat.CallbackListener<BaseMessage>() {
    override fun onSuccess(message: BaseMessage) { }
    override fun onError(e: CometChatException) { }
})

// Listen for edit events
CometChat.addMessageListener("LISTENER_ID", object : CometChat.MessageListener() {
    override fun onMessageEdited(message: BaseMessage) { }
})

Edit a Message

Use editMessage() with a TextMessage or CustomMessage object. Set the message ID using setId().

Add/Update Tags

While editing a message, you can update the tags associated with the Message. You can use the setTags() method to do so. The tags added while editing a message will replace the tags set when the message was sent.
List<String> tags = new ArrayList<>();
tags.add("pinned");
textMessage.setTags(tags);
Once the message object is ready, call editMessage().
TextMessage updatedMessage = new TextMessage(message.getReceiverUid(), ((TextMessage)message).getText() + "edited",message.getReceiverType());

updatedMessage.setId(message.getId());

CometChat.editMessage(updatedMessage, new CometChat.CallbackListener<BaseMessage>() {
  @Override
  public void onSuccess(BaseMessage message) {
    Log.d(TAG,"Message Edited successfully: "+message.toString());
  }

  @Override
  public void onError(CometChatException e) {
    Log.d(TAG,"Message Edited failed with exception: "+e.getMessage());
  }
}); 
The object of the edited message will be returned in the onSucess() callback method of the listener. The message object will contain the editedAt field set with the timestamp of the time the message was edited. This will help you identify if the message was edited while iterating through the list of messages. The editedBy field is also set to the UID of the user who edited the message.
FieldGetterReturn TypeDescription
editedAtgetEditedAt()longTimestamp when the message was edited
editedBygetEditedBy()StringUID of the user who edited the message
By default, CometChat allows certain roles to edit a message.
User RoleConversation TypeEdit Capabilities
Message SenderOne-on-one ConversationMessages they’ve sent
Message SenderGroup ConversationMessages they’ve sent
Group OwnerGroup ConversationAll messages in the group
Group ModeratorGroup ConversationAll messages in the group

Real-time Message Edit Events

Use onMessageEdited in MessageListener to receive real-time edit events.
CometChat.addMessageListener(listenerID, new CometChat.MessageListener() {
  @Override
  public void onMessageEdited(BaseMessage message) {
    Log.d(TAG, "Message Edited");
  }
});
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.
CometChat.removeMessageListener("LISTENER_ID")
FieldGetterReturn TypeDescription
editedAtgetEditedAt()longTimestamp when the message was edited
editedBygetEditedBy()StringUID of the user who edited the message

Missed Message Edit Events

When fetching message history, edited messages have editedAt and editedBy fields set. Additionally, an Action message is created when a message is edited. For the message edited event, in the Action object received, the following fields can help you get the relevant information-
  1. action - edited
  2. actionOn - Updated message object with the edited details.
  3. actionBy - User object containing the details of the user who has edited the message.
  4. actionFor - User/group object having the details of the receiver to which the message was sent.
In order to edit 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

Delete Message

Remove messages from conversations

Send Message

Send text, media, and custom messages

Receive Messages

Handle real-time message events with listeners

Message Structure

Understand message types and properties