Inserting Messages
The IMLib SDK supports inserting messages into the local database. Messages inserted locally will not be actually sent to the RC server or the other party.
- Ensure all inserted messages support client-side local storage; otherwise, errors will occur. See Understanding Message Storage Strategies.
- The message insertion interface only adds messages to the local database, so when the app is reinstalled or logged in on another device, the inserted messages will not be synced from the remote server to the local database.
Inserting Outgoing Messages
You can use the insertOutgoingMessage: interface to insert an outgoing message into the local database. The following example uses the insertOutgoingMessage method under RCChannelClient.
- Incorrect
sentTimemay affect message sorting—use with caution! - This interface does not support chatroom conversation types.
Interface Prototype
- (void)insertOutgoingMessage:(RCConversationType)conversationType
targetId:(NSString *)targetId
sentStatus:(RCSentStatus)sentStatus
content:(RCMessageContent *)content
sentTime:(long long)sentTime
completion:(nullable void(^)(RCMessage *_Nullable message))completion;
For messages inserted into the local database to support message expansion, you must use the insertion method under RCChannelClient; otherwise, the message's expandable property (canIncludeExpansion) cannot be enabled. Local message insertion does not support setting message expansion data. You can set expansion data for the message at an appropriate time after insertion. See [Message Expansion] for details.
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| conversationType | [RCConversationType] | Conversation type. |
| targetId | NSString | Conversation targetId. |
| channelId | NSString | Channel ID for ultra group conversations; pass nil for non-ultra group conversations. |
| canIncludeExpansion | BOOL | Whether the message supports expansion. YES for expandable; NO for non-expandable. |
| sentStatus | [RCSentStatus] | Message sending status. |
| content | [RCMessageContent] | Message content. |
| sentTime | long long | Unix timestamp (in milliseconds) when the message was sent (passing 0 will use the local time for insertion). |
| completion | Block | Asynchronous callback, returning the inserted [RCMessage] object. |
Example Code
RCTextMessage *content = [RCTextMessage messageWithContent:@"Test text message"];
[[RCChannelClient sharedChannelManager]
insertOutgoingMessage:ConversationType_PRIVATE
targetId:@"targetId"
channelId:@"channelId"
canIncludeExpansion:YES
sentStatus:SentStatus_SENT
content:content
sentTime:sentTime
completion::^(RCMessage * _Nullable message) {
}];
Inserting Incoming Messages
You can use the insertIncomingMessage: interface to insert a received message into the local database.
- Incorrect
sentTimemay affect message sorting—use with caution! - For versions after 5.6.8, use the
RCReceivedStatusInfoobject to construct the received message status; for versions before 5.6.8, use theRCReceivedStatusobject to construct the message received status.
Interface Prototype
- (void)insertIncomingMessage:(RCConversationType)conversationType
targetId:(NSString *)targetId
senderUserId:(NSString *)senderUserId
receivedStatusInfo:(RCReceivedStatusInfo *)receivedStatusInfo
content:(RCMessageContent *)content
sentTime:(long long)sentTime
completion:(nullable void(^)(RCMessage *_Nullable message))completion;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| conversationType | [RCConversationType] | Conversation type; pass ConversationType_PRIVATE for one-to-one chats. |
| targetId | NSString | Target ID used to identify the conversation. Note: In one-to-one chats, the target ID is always the peer user ID. For group chats and ultra groups, the conversation IDs are the group ID and ultra group ID, respectively. See the explanation of Target ID in Message Introduction. |
| senderUserId | NSString | Sender ID. |
| RCReceivedStatusInfo | [RCReceivedStatusInfo] | Message received status. |
| content | [RCMessageContent] | Message content. |
| sentTime | long long | Unix timestamp (in milliseconds) when the message was sent (passing 0 will use the local time for insertion). |
| completion | Block | Asynchronous callback, returning the inserted [RCMessage] object. |
Example Code
RCTextMessage *content = [RCTextMessage messageWithContent:@"Test text message"];
RCReceivedStatusInfo *info = [[RCReceivedStatusInfo alloc] initWithReceivedStatus:0];
[[RCCoreClient sharedCoreClient] insertIncomingMessage:ConversationType_PRIVATE
targetId:@"targetId"
senderUserId:@"senderUserId"
receivedStatusInfo:info
content:content
sentTime:0
completion:^(RCMessage * _Nullable message) {
}];