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
- Java
NCEngine.addMessageHandler("MESSAGE_UPDATE_HANDLER", object : MessageHandler {
override fun onMessagesModified(event: MessagesModifiedEvent) {
event.messages.forEach { message ->
Log.d("MessageUpdate", "Message updated: ${message.messageId}")
}
}
})
NCEngine.addMessageHandler("MESSAGE_UPDATE_HANDLER", new MessageHandler() {
@Override
public void onMessagesModified(MessagesModifiedEvent event) {
for (Message message : event.getMessages()) {
Log.d("MessageUpdate", "Message updated: " + message.getMessageId());
}
}
});
Remove the handler when no longer needed to prevent memory leaks:
- Kotlin
- Java
NCEngine.removeMessageHandler("MESSAGE_UPDATE_HANDLER")
NCEngine.removeMessageHandler("MESSAGE_UPDATE_HANDLER");
Update a message
Use modifyMessage() on the channel object to update a sent message.
- Kotlin
- Java
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}")
}
}
GroupChannel channel = new GroupChannel(groupId);
MessageContent newContent = new TextMessage("Updated message content");
ModifyMessageParams params = new ModifyMessageParams(
originalMessage.getMessageId(), newContent
);
if (channel != null) {
channel.modifyMessage(params, new OperationHandler<Message>() {
@Override
public void onResult(Message message, NCError error) {
if (error == null && message != null) {
Log.d("Modify", "Message updated: " + message.getContent());
} else {
Log.e("Modify", "Update failed: " + error.getMessage());
}
}
});
}
Parameters
| Parameter | Type | Description |
|---|---|---|
messageId | String | The ID of the message to update. |
content | MessageContent | The new message content. |
handler | OperationHandler<Message> | Callback returning the updated message or an error. |
Refresh quoted messages
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
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.