Modify a message
Modify the content of a sent message with OpenIM iOS SDK.
Invoke modifyMessageWithConversationID:message:onSuccess:onFailure: on OIMManager to edit the content of a previously sent message in a conversation. This differs from Delete a message and Revoke a message: deletion controls visibility for the current account, revocation displays a placeholder indicating the message was recalled, and modification updates the body content across all devices.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | NSString * | Yes | Target conversation identifier. |
message | OIMMessageInfo * | Yes | Complete modified message model. Must preserve the original clientMsgID and routing attributes. |
onSuccess | OIMSuccessCallback | Yes | Success callback confirming the modification request was accepted. |
onFailure | OIMFailureCallback | Yes | Failure callback returning error code code and descriptive message errorMessage. |
Code example
if (message.textElem == nil || editedText.length == 0) {
return;
}
NSString *previousText = message.textElem.content;
message.textElem.content = editedText;
[[OIMManager manager]
modifyMessageWithConversationID:conversationID
message:message
onSuccess:^(NSString * _Nullable data) {
// Modification accepted; update local UI bubble
[self replaceMessage:message
conversationID:conversationID
clientMsgID:message.clientMsgID];
}
onFailure:^(NSInteger code, NSString * _Nullable errorMessage) {
// Roll back edited text on failure
message.textElem.content = previousText;
[self showModifyError:code message:errorMessage ?: @"Failed to modify message"];
}];Return value
The onSuccess callback confirms that the modification request was accepted by the server. The callback string is not the updated message object; client state is merged using clientMsgID (scoped to conversationID).
Listen for message modifications
When other members or other logged-in clients receive an edited message, the SDK dispatches the update via onMessageModified: in OIMAdvancedMsgListener:
- (void)onMessageModified:(OIMMessageInfo *)message {
if (message.clientMsgID.length == 0) {
return;
}
NSString *conversationID = [self conversationIDForMessage:message];
// Replace cached message by clientMsgID
[self replaceMessage:message
conversationID:conversationID
clientMsgID:message.clientMsgID];
}State changes after the call
- Full model replacement: Message modification is not an incremental field patch. Start from the complete existing
OIMMessageInfoinstance and update only the target content property while strictly preservingclientMsgID, conversation type, sender, send time, and other elements. - Server policy validation: The server verifies editor permissions, editable time windows, and supported message types. If modification fails, restore the original content rather than leaving an unconfirmed local edit in the UI.
- Multi-client synchronization: Calling the API and receiving
onMessageModified:across other clients are distinct phases. For listener registration and lifecycle details, see Receive messages.
Was this page helpful?