Message Modification
Starting from version 5.26.0, IMLib supports message modification functionality, allowing content modification for all stored message types (text, images (including GIF), voice (HD and standard), videos, references, files, and custom messages).
Message Modification
Developers can modify messages using the modifyMessageWithParams:completionHandler: interface.
| Parameter | Type | Description |
|---|---|---|
| params | RCModifyMessageParams | Message modification parameters |
| completionHandler | Block | Result callback |
In the interface, params encapsulates the modification information as RCModifyMessageParams, with the following content:
| Parameter | Type | Description |
|---|---|---|
| messageUId | NSString | Message unique ID |
| messageContent | RCMessageContent | Modified message body |
RCTextMessage *messageContent = (RCTextMessage *)message.content;
messageContent.content = @"modified_text";
RCModifyMessageParams *params = [[RCModifyMessageParams alloc] init];
params.messageUId = message.messageUId;
params.messageContent = messageContent;
[[RCCoreClient sharedCoreClient] modifyMessageWithParams:params completionHandler:^(RCMessage * _Nonnull message, RCErrorCode code) {
// TODO code
}];
Message Modification Callback
After message modification, multi-device users or other users will receive modification callbacks through the onMessagesModified: and onModifiedMessageSyncCompleted methods in the RCIMClientReceiveMessageDelegate protocol.
// Register delegate during initialization.
[[RCCoreClient sharedCoreClient] setReceiveMessageDelegate:self object:nil];
// Implement callback methods in business logic.
- (void)onMessagesModified:(NSArray<RCMessage *> *)messages {
// Messages modified.
}
- (void)onModifiedMessageSyncCompleted {
// Synchronizes remote modifications after each successful connection.
}
Refresh Reference Messages
Developers can refresh reference messages using the refreshReferenceMessageWithParams:localMessageBlock:remoteMessageBlock:errorBlock: interface.
| Parameter | Type | Description |
|---|---|---|
| params | RCRefreshReferenceMessageParams | Message modification parameters |
| localMessageBlock | Block | Local result callback |
| remoteMessageBlock | Block | Remote result callback |
| errorBlock | Block | Error callback |
In the interface, params encapsulates the refresh information as RCRefreshReferenceMessageParams, with the following content:
| Parameter | Type | Description |
|---|---|---|
| messageUIds | NSArray | List of message unique IDs (max 20) |
| conversationIdentifier | RCConversationIdentifier | Conversation identifier |
RCRefreshReferenceMessageParams *params = [[RCRefreshReferenceMessageParams alloc] init];
RCConversationIdentifier *identifier = [[RCConversationIdentifier alloc] init];
identifier.type = message.conversationType;
identifier.targetId = message.targetId;
identifier.channelId = message.channelId;
params.conversationIdentifier = identifier;
params.messageUIds = @[message.messageUId];
params.messageContent = messageContent;
[[RCCoreClient sharedCoreClient] refreshReferenceMessageWithParams:params
localMessageBlock:^(NSArray<RCMessageResult *> * _Nonnull results) {
// TODO Local messages
} remoteMessageBlock:^(NSArray<RCMessageResult *> * _Nonnull results) {
// TODO Remote messages
} errorBlock:^(RCErrorCode code) {
// TODO Error handling
}];
Message Modification Drafts
This interface is available starting from SDK version 5.28.0.
When users modify sent messages, the input box retains the current message content being edited. To enhance user experience, the SDK provides capabilities to save, retrieve, and clear conversation drafts, ensuring users can resume editing when switching conversations or exiting the application.
Save Message Modification Draft
Use the [saveEditedMessageDraft:identifier:completion:] method to save the latest content of a message modification draft in the current conversation. This allows users to save drafts when temporarily leaving the editing interface for later recovery.
Interface Prototype
- (void)saveEditedMessageDraft:(RCEditedMessageDraft *)draft
identifier:(RCConversationIdentifier *)identifier
completion:(nullable void(^)(RCErrorCode code))completion;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
draft | RCEditedMessageDraft | Draft model containing message UID and draft content |
identifier | RCConversationIdentifier | Conversation identifier (supports one-to-one, group, and ultra group chats). targetId is required, channeld is optional |
completion | Block | Operation completion callback |
RCEditedMessageDraft Property Description
| Property | Type | Description |
|---|---|---|
messageUId | NSString | Message unique identifier (required) - identifies the message to be edited |
content | NSString | Draft content (optional) - currently edited text by the user |
Example Code
// Create draft object
RCEditedMessageDraft *draft = [[RCEditedMessageDraft alloc] init];
draft.content = @"Content being edited by user";
draft.messageUId = @"CP50-A35I-P026-DHHT";
// Create conversation identifier (one-to-one chat example)
RCConversationIdentifier *identifier = [[RCConversationIdentifier alloc] init];
identifier.type = ConversationType_PRIVATE;
identifier.targetId = @"user_target_id";
// Save editing draft
[[RCCoreClient sharedCoreClient] saveEditedMessageDraft:draft
identifier:identifier
completion:^(RCErrorCode code) {
if (code == RC_SUCCESS) {
NSLog(@"Editing draft saved successfully");
} else {
NSLog(@"Failed to save editing draft, error code: %ld", (long)code);
}
}];
Retrieve Message Modification Draft
When users re-enter a conversation, use the [getEditedMessageDraft:completion:] method to retrieve saved message draft content and restore the user's editing state.
Interface Prototype
- (void)getEditedMessageDraft:(RCConversationIdentifier *)identifier
completion:(nullable void(^)(RCErrorCode code, RCEditedMessageDraft * _Nullable draft))completion;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
identifier | RCConversationIdentifier | Conversation identifier (supports one-to-one, group, and ultra group chats). targetId is required, channeld is optional |
completion | Block | Result callback returning error code and draft object |
Example Code
// Create conversation identifier (using one-to-one chat as example)
RCConversationIdentifier *identifier = [[RCConversationIdentifier alloc] init];
identifier.type = ConversationType_PRIVATE;
identifier.targetId = @"user_target_id";
// Retrieve edit draft
[[RCCoreClient sharedCoreClient] getEditedMessageDraft:identifier completion:^(RCErrorCode code, RCEditedMessageDraft * _Nullable draft) {
if (code == RC_SUCCESS) {
if (draft) {
// Successfully retrieved draft, restore edit content
NSLog(@"Draft retrieved successfully, Message UID: %@, Content: %@", draft.messageUId, draft.content);
// Restore draft content in UI
} else {
NSLog(@"No edit draft exists for this conversation");
}
} else {
NSLog(@"Failed to retrieve edit draft, error code: %ld", (long)code);
}
}];
Clear Message Edit Draft
When users complete message editing or no longer need saved drafts, you can use the [clearEditedMessageDraft:completion] method to clear message edit drafts and free up storage space.
Method Prototype
- (void)clearEditedMessageDraft:(RCConversationIdentifier *)identifier
completion:(nullable void(^)(RCErrorCode code))completion;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
identifier | RCConversationIdentifier | Conversation identifier (supports one-to-one, group, and ultra group chats). targetId is required, channeld is optional |
completion | Block | Result callback returning error code |
Example Code
// Create conversation identifier (using one-to-one chat as example)
RCConversationIdentifier *identifier = [[RCConversationIdentifier alloc] init];
identifier.type = ConversationType_PRIVATE;
identifier.targetId = @"user_target_id";
// Clear edit draft
[[RCCoreClient sharedCoreClient] clearEditedMessageDraft:identifier completion:^(RCErrorCode code) {
if (code == RC_SUCCESS) {
NSLog(@"Edit draft cleared successfully");
} else {
NSLog(@"Failed to clear edit draft, error code: %ld", (long)code);
}
}];