Skip to main content

Update messages

This guide covers how to update (edit) already-sent messages using the Nexconn SDK.

Overview

After successfully sending a message, you can update its content. The updated content is synced to all recipients. This feature supports all stored message types (text, image, GIF, voice, video, quote, file, and custom messages).

Use cases

  • Direct channels: A user edits a sent message to fix a typo.
  • Group channels: A user or group admin edits a message.

Listen for message updates

When a message is updated, recipients receive a notification through the message handler's onMessagesModified callback.

kotlin
NCEngine.addMessageHandler("MESSAGE_UPDATE_HANDLER", object : MessageHandler {
override fun onMessagesModified(event: MessagesModifiedEvent) {
event.messages.forEach { message ->
Log.d("MessageUpdate", "Message updated: ${message.messageId}")
}
}
})

Remove the handler when no longer needed to prevent memory leaks:

kotlin
NCEngine.removeMessageHandler("MESSAGE_UPDATE_HANDLER")

Update a message

Use modifyMessage() on the channel object to update a sent message.

kotlin
val channel = GroupChannel(groupId)

val params = ModifyMessageParams(
messageId = originalMessage.messageId,
content = TextMessage("Updated message content")
)

channel?.modifyMessage(params) { message, error ->
if (error == null && message != null) {
Log.d("Modify", "Message updated: ${message.content}")
} else {
Log.e("Modify", "Update failed: ${error?.message}")
}
}

Parameters

ParameterTypeDescription
messageIdStringThe ID of the message to update.
contentMessageContentThe new message content.
handlerOperationHandler<Message>Callback returning the updated message or an error.

Refresh quoted messages

note

This is an advanced feature currently implemented through the underlying SDK adapter.

ReferenceMessage caches the original message content. Updating the original message does not automatically update the cached content in quote messages. Refresh the quote message content when displaying it to show the latest version.

Edit draft

note

Edit draft functionality is currently implemented through the underlying SDK adapter and will be integrated into channel objects in a future release.

Save an edit draft so the user can continue editing a message later, improving the user experience.