Modify a message
Edit the content of an already-sent message and synchronize edits with chat participants.
Modifying messages is a Commercial Edition capability. It updates the content of an existing message in-place and synchronizes changes across all chat participants. This differs from deleting a message (which affects visibility for specific users) and revoking a message (which converts the item into a revocation notice).
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Identifier of the conversation containing the message. |
message | OpenIMMessageItem | Yes | Modified message object; must preserve original clientMsgID and mandatory headers. |
This method is not a partial field patch. Clone the original message record, modify only the payload element corresponding to contentType, and pass the complete message struct. In UTS, avoid TypeScript object spread syntax (...obj); clone using JSON serialization instead. Permission rules, editable message types, and edit time windows are strictly validated by OpenIMServer.
Code example
import {
OpenIMMessageItem,
modifyMessage,
} from '@/uni_modules/unix-openim-sdk'
const updatedMessage = JSON.parse<OpenIMMessageItem>(
JSON.stringify(message),
)
const textElem = updatedMessage.textElem
if (textElem == null) return
textElem.content = editedText
updatedMessage.textElem = textElem
const result = await modifyMessage({
conversationID,
message: updatedMessage,
})
const modifiedMessage = result?.message
if (modifiedMessage != null) {
replaceMessage(conversationID, modifiedMessage)
}Return value
The Promise resolves with an OpenIMModifyMessageResult | null object. The updated message record is contained in message (OpenIMMessageItem | null). Replace the existing message in your local list using conversationID:clientMsgID.
Listen for message modifications
Centrally register onMessageModified to listen for message modifications. The event delivers an opaque string notification signal. Treat this signal as an invalidation trigger to re-query currently visible messages rather than assuming an undocumented JSON schema.
import { off, onMessageModified } from '@/uni_modules/unix-openim-sdk'
const handleMessageModified = (_payload: string) => {
reloadVisibleMessages()
}
const messageModifiedSubscription =
onMessageModified(handleMessageModified)
function removeMessageModifiedListener() {
off(messageModifiedSubscription)
}Unregister the listener when unmounting views, logging out, or switching accounts.
Was this page helpful?