Browse SDKs · Flutter
Platform
SDKsFlutterEnterprise

Modify a message

Use the OpenIM Flutter SDK to modify the content of a sent message.

Copy

Modify the content of a previously sent message in a conversation. Unlike Delete saved messages, which affects whether the message remains visible to the current account, and Revoke a message, which displays a revocation notice to all members, modifying a message replaces its body content and synchronizes updates to all conversation members.

Parameters

ParameterTypeRequiredDescription
conversationIDStringYesID of the conversation containing the message. Flutter's Message model does not contain this field.
messageMessageYesThe complete modified message object; must preserve the original clientMsgID and routing fields.

Code example

final clientMsgID = message.clientMsgID;
final textElem = message.textElem;
if (clientMsgID == null || clientMsgID.isEmpty || textElem == null) {
  throw StateError('Message cannot be edited');
}

final previousText = textElem.content;
textElem.content = editedText;

try {
  await OpenIM.iMManager.messageManager.modifyMessage(
    conversationID: conversationID,
    message: message,
  );
  replaceMessage(conversationID, clientMsgID, message);
} catch (_) {
  textElem.content = previousText;
  rethrow;
}

This method is not a partial update. Start with the current complete message object, modify only the target element, and preserve clientMsgID, routing identifiers, sender, timestamps, and custom attributes. OpenIM Server validates the permitted sender, time window, and message types. If modification fails, revert local content or re-query the message; do not retain uncommitted edits in local memory.

Return value

Returns a Future<void>. Success indicates that the server accepted and persisted the message modification request. The local client may preview the submitted message using the composite key conversationID:clientMsgID, awaiting subsequent event delivery for final confirmation.

Future resolution does not imply all participant clients have updated their screens. Events may also originate from other devices or authorized operators; never assume every event corresponds to the call just executed on the current screen.

State changes after the call

Message modification events are delivered through the onMessageModified callback in OnAdvancedMsgListener. The callback provides the single modified Message object. Because Flutter messages omit the conversationID attribute, resolve the conversation routing first, then replace the existing record by conversationID:clientMsgID:

Future<void> handleMessageModified(Message message) async {
  final clientMsgID = message.clientMsgID;
  if (clientMsgID == null || clientMsgID.isEmpty) return;

  final conversationID = await resolveMessageConversationID(
    message,
    currentUserID,
  );
  if (conversationID == null) return;

  replaceMessage(conversationID, clientMsgID, message);
}

The conversation ID resolution logic determines the message origin from sessionType, groupID, sendID, recvID, and the current user ID, then retrieves the conversation ID using the conversation ID helper. For complete helper implementation, see Receive messages. Merge records strictly using conversationID:clientMsgID; never match messages by array index, display text, or list length.

Register this handler within the application's single OnAdvancedMsgListener. For centralized listener setup, see Events overview. When logging out or switching accounts, detach listeners from the prior account state and register the new account's listeners.

Future completion, onMessageModified delivery, and historical re-queries represent three distinct lifecycle stages. Re-read messages when you must confirm final content; a failed query must not be misconstrued as a failed modification request.