Editing and Deleting Messages

A special AmityMessageEditor class is provided for you to perform actions on messages you've sent or received. These actions include editing and deleting an existing message, as well as marking a message as being read by you. You can only perform edit and delete operations on messages you've sent.

To start, first instantiate a AmityMessageEditor instance with the AmityClient instance you created on setup, as well as a valid messageID.

let editor = AmityMessageEditor(client: client, messageId: "message1")

Edit

When editing a message, the message's editedAtDate will be set to the current time. This allows you to provide UI to the user to inform the user of specific messages that have been edited, if needed. An optional completion block can be provided to notify you of operation success.

// Edit current message with new text.
editor.editText("New edited text") { success, error in
    // Handle success and error.
}

// Edit custom message with new data.
let metaData: [String: Any] = ["foo": "bar"]
editor.editCustomMessage(metaData) { success, error in
    // Handle success and error.
}

// Set tags for current messages.
editor.setTags(["pinned", "important"]) { success, error in
    // Handle success and error.
}

Delete

messageRepository.deleteMessage(withId: "message1") { success, error in
    // Handle success and error.
}

Last updated