Use CometChat.edit(message:) with a TextMessage or CustomMessage object. Set the message ID on the object before calling edit.
let textMessage = TextMessage(receiverUid: "cometchat-uid-2", text: "Updated message", receiverType: .user)textMessage.id = 12345CometChat.edit(message: textMessage, onSuccess: { (message) in print("Message edited: \(message)")}, onError: { (error) in print("Error: \(error.errorDescription)")})
The edited message object is returned with editedAt (timestamp) and editedBy (UID of editor) fields set.The edit() method returns a BaseMessage object (or a subclass like TextMessage).
When fetching message history, edited messages have editedAt and editedBy fields set. Additionally, an Action message is added to history indicating the edit.The Action object contains:
action — edited
actionOn — Updated message object
actionBy — User who edited the message
actionFor — Receiver (User or Group)
for message in messages { if message.editedAt > 0 { print("Message \(message.id) was edited at \(message.editedAt)") } if let actionMessage = message as? ActionMessage { if actionMessage.action == .messageEdited { print("Edit action detected") } }}
You must be the message sender or a group admin/moderator to edit a message.