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.

FieldValue
Key ClassesTextMessage, CustomMessage, BaseMessage
Key MethodsCometChat.editMessage()
Listener EventsonMessageEdited
PrerequisitesSDK initialized, user logged in
// Edit a text message
TextMessage updatedMessage = TextMessage(
  text: "Updated message text",
  receiverUid: "receiver_uid",
  receiverType: CometChatReceiverType.user,
  type: CometChatMessageType.text,
);
updatedMessage.id = originalMessageId;

await CometChat.editMessage(updatedMessage,
  onSuccess: (BaseMessage message) {
    debugPrint("Message edited: $message");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

// Listen for real-time edits
CometChat.addMessageListener("edits_listener", MessageListener(
  onMessageEdited: (BaseMessage message) {
    debugPrint("Message was edited: ${message.id}");
  },
));

// Remove listener when done
CometChat.removeMessageListener("edits_listener");
Editing a message is straightforward. Receiving edit events has two parts:
  1. Adding a listener for real-time edits when your app is running
  2. Fetching missed edits when your app was offline

Edit a Message

Use editMessage() with a TextMessage or CustomMessage object. Set the message ID using the id property.
ParameterTypeDescription
messageBaseMessageThe message object to edit. Must be a TextMessage or CustomMessage. Set the id property to the ID of the message to edit.
onSuccessFunction(BaseMessage)Callback triggered on success with the edited message object.
onErrorFunction(CometChatException)Callback triggered on error with exception details.

Add/Update Tags

Use tags to update tags when editing. New tags replace existing ones.
List<String> tags = [];
tags.add("pinned");
textMessage.tags = tags; 
Once the message object is ready, call editMessage().
TextMessage updatedMessage = TextMessage(
                        text: updatedText,
                        receiverUid: receiverID,
                        receiverType: receiverType,
                        type: type);

updatedMessage.id = message.id;

await CometChat.editMessage(updatedMessage, 
  onSuccess: (BaseMessage message){
  	debugPrint("Message Edited successfully: $message");
  }, onError: (CometChatException e){
  	debugPrint("Message Edited failed with exception: ${e.message}");
  }
);
On Success — A BaseMessage object containing all details of the edited message:BaseMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID401
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the message"cometchat-uid-1"
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745554729
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"text"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered1745554750
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited1745554800
parentMessageIdnumberID of the parent message (for threads)0
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"message"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745554800
unreadRepliesCountnumberCount of unread replies0
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"The message could not be modified."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."
The edited message object is returned with editedAt (timestamp) and editedBy (UID of editor) fields set. The editMessage() method returns a BaseMessage object (or a subclass like TextMessage). Relevant fields to access on the returned message:
FieldPropertyReturn TypeDescription
editedAteditedAtintTimestamp when the message was edited
editedByeditedByStringUID 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.
class Class_Name  with MessageListener {

//CometChat.addMessageListener("listenerId", this);
@override
void onMessageEdited(BaseMessage message) {
  // TODO: implement onMessageEdited
}


} 
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.
@override
void dispose() {
  CometChat.removeMessageListener("listenerId");
  super.dispose();
}
The onMessageEdited callback receives a BaseMessage object with the editedAt and editedBy fields set. Relevant fields to access on the returned message:
FieldPropertyReturn TypeDescription
editedAteditedAtintTimestamp when the message was edited
editedByeditedByStringUID 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. The Action object contains:
  • actionedited
  • actionOn — Updated message object with the edited details
  • actionBy — User object containing the details of the user who has edited the message
  • 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 edit a message.

Next Steps

Delete Message

Learn how to delete messages from conversations

Send Message

Send text, media, and custom messages

Receive Messages

Handle incoming messages in real-time

Threaded Messages

Create and manage message threads