Modify a message
Modify the content of a sent message with OpenIM iOS SDK.
modifyMessageWithConversationID:message:onSuccess:onFailure: changes the content of an existing message in a conversation. It differs from Delete a message and Revoke a message: deletion controls whether the current account can still see a message, revocation displays a revoked state to conversation participants, and modification replaces the content and synchronizes it to other clients.
Modify message content
The selector accepts the message's conversationID and the complete modified OIMMessageInfo.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | NSString * | Yes | The ID of the conversation containing the message. |
message | OIMMessageInfo * | Yes | The complete modified message; it must retain the original clientMsgID. |
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) {
[self replaceMessage:message
conversationID:conversationID
clientMsgID:message.clientMsgID];
}
onFailure:^(NSInteger code, NSString * _Nullable errorMessage) {
message.textElem.content = previousText;
[self showModifyError:code message:errorMessage ?: @"Failed to modify the message"];
}];This method is not a partial update. Start from the current complete message and change only the intended content, preserving clientMsgID, routing, sender, time, and all other elements. OpenIMServer validates the permitted sender, time window, and message types. If the call fails, restore the original content or query again; do not retain a local-only edit.
Result
The success callback's NSString * is not declared as a modified message object and must not be parsed as the WASM return model. Success means that the current modification request has completed. The caller can optimistically display the submitted complete message by clientMsgID, then reconcile it through a modification event or a new query.
Success does not mean that every client UI has already updated. Other clients receive the modified OIMMessageInfo through onMessageModified:.
Listen for message modifications
This page is the sole owner of onMessageModified:. It belongs to the application's registered OIMAdvancedMsgListener:
- (void)onMessageModified:(OIMMessageInfo *)message {
if (message.clientMsgID.length == 0) {
return;
}
NSString *conversationID = [self conversationIDForMessage:message];
[self replaceMessage:message
conversationID:conversationID
clientMsgID:message.clientMsgID];
}The event carries one complete modified OIMMessageInfo. Replace the original by clientMsgID, and derive its conversation from sessionType, sendID, recvID, and groupID. Do not match by array position or displayed text. For strong listener retention, registration, and removal, see Receive messages.
Related pages
Was this page helpful?