Alternatively, you can use the async/await syntax:
try { let receiverID = "RECEIVER_UID"; let messageText = "Hello world!"; let receiverType = CometChat.RECEIVER_TYPE.USER; let messageId = "MESSAGE_ID_OF_THE_MESSAGE_TO_BE_EDITED"; let textMessage = new CometChat.TextMessage(receiverID, messageText, receiverType); textMessage.setId(messageId); const message = await CometChat.editMessage(textMessage); console.log("Message Edited", message);} catch (error) { console.log("Message editing failed with error:", error);}
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:
Field
Getter
Return Type
Description
editedAt
getEditedAt()
number
Timestamp when the message was edited
editedBy
getEditedBy()
string
UID of the user who edited the message
By default, CometChat allows certain users to edit a message.Message editing in CometChat is controlled by -
Always remove message listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.
The onMessageEdited callback receives a BaseMessage object with the editedAt and editedBy fields set.Relevant fields to access on the returned message:
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:
action — edited
actionOn — Updated message object
actionBy — User who edited the message
actionFor — Receiver (User/Group)
You must be the message sender or a group admin/moderator to edit a message.