Browse SDKs · WASM
SDKsWASMEnterprise

Modify a message

Modify the content of a sent message and synchronize the result to other clients.

Copy

Use modifyMessage() to change the content of an existing message in a conversation. This differs from Delete messages in a batch and Revoke a message: deletion controls whether the current account can still see a message, revocation shows a revoked state to conversation members, and modification replaces the message content and synchronizes it to other clients.

Modify message content

modifyMessage() accepts the message's conversationID and the complete modified MessageItem.

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesID of the conversation containing the message.
messageMessageItemYesComplete modified message object. It must retain the original clientMsgID.
const { data: modifiedMessage } = await openimsdk.modifyMessage({
  conversationID,
  message: {
    ...message,
    textElem: {
      ...message.textElem,
      content: editedText,
    },
  },
});

replaceMessage(modifiedMessage);

This method does not perform a partial update. Copy the current message, change only the intended content, and preserve clientMsgID and all other message fields. OpenIMServer validates the sender, editing time window, and message type. If the call fails, do not leave the edited content only in local state.

Return result

When the Promise resolves, data is the server-confirmed modified MessageItem. The calling client can immediately replace the message with the same clientMsgID; other clients subsequently merge the incremental update through an event.

Promise completion means that the current modification request has completed, not that every client interface has already updated. Other clients receive the modified MessageItem through CbEvents.OnMessageModified and should replace the existing message by clientMsgID.

Listen for message modifications

This page is the canonical reference for OnMessageModified. For deletion events, see Delete messages in a batch. For revocation events, see Revoke a message.

import { CbEvents } from '@openim/wasm-client-sdk';

const handleMessageModified = ({ data }) => {
  replaceMessage(resolveConversationID(data), data.clientMsgID, data);
};

openimsdk.on(CbEvents.OnMessageModified, handleMessageModified);

function removeMessageModifiedListener() {
  openimsdk.off(CbEvents.OnMessageModified, handleMessageModified);
}

OnMessageModified provides one MessageItem in data. Determine its conversation from the message routing fields and merge it by clientMsgID. Call removeMessageModifiedListener() when the component unmounts, the user logs out, or the active account changes.