Insert Messages
The message insertion API does not send messages to the remote server, so inserted messages will not sync to the local database when reinstalling the app or logging in from another device.
Insert Outgoing Messages
Use the insertOutgoingMessage:
method to insert an outgoing message into the local database. The following example uses the insertOutgoingMessage
method from RCChannelClient
.
- Incorrect
sentTime
may affect message sorting—use with caution! - Inserted messages won’t immediately appear in the chat UI.
Method Signature
- (void)insertOutgoingMessage:(RCConversationType)conversationType
targetId:(NSString *)targetId
sentStatus:(RCSentStatus)sentStatus
content:(RCMessageContent *)content
sentTime:(long long)sentTime
completion:(nullable void(^)(RCMessage *_Nullable message))completion;
To enable message extensions for locally inserted messages, use the insertion method from RCChannelClient
. Otherwise, the canIncludeExpansion
property remains unavailable. Note that extension data cannot be set during insertion. You may set it later as needed. For details, see [Message Extensions].
Parameters
Parameter | Type | Description |
---|---|---|
conversationType | [RCConversationType] | Conversation type. |
targetId | NSString | Target ID of the conversation. |
channelId | NSString | Channel ID for ultra group conversations. Pass nil for non-ultra groups. |
canIncludeExpansion | BOOL | Whether the message supports extensions. YES : enabled; NO : disabled. |
sentStatus | [RCSentStatus] | Message delivery status. |
content | [RCMessageContent] | Message content. |
sentTime | long long | Unix timestamp (ms) of the message. Pass 0 to use the local time. |
completion | Block | Async callback returning the inserted [RCMessage] object. |
Example
RCTextMessage *content = [RCTextMessage messageWithContent:@"Test message"];
[[RCChannelClient sharedChannelManager]
insertOutgoingMessage:ConversationType_PRIVATE
targetId:@"targetId"
channelId:@"channelId"
canIncludeExpansion:YES
sentStatus:SentStatus_SENT
content:content
sentTime:sentTime
completion::^(RCMessage * _Nullable message) {
}];
Insert Incoming Messages
Use the insertIncomingMessage:
method to insert an incoming message into the local database.
- Incorrect
sentTime
may affect message sorting—use with caution! - For versions after 5.6.8, use
RCReceivedStatusInfo
to set message receipt status. Earlier versions useRCReceivedStatus
. - Inserted messages won’t immediately appear in the chat UI.
Method Signature
- (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;
Parameters
Parameter | Type | Description |
---|---|---|
conversationType | [RCConversationType] | Conversation type. Use ConversationType_PRIVATE for one-to-one chats. |
targetId | NSString | Unique identifier for the conversation (Target ID or conversation ID). Note: For one-to-one chats, the Target ID is always the peer user's ID. For groups and ultra groups, it’s the group ID or ultra group ID. See Message Introduction for details. |
senderUserId | NSString | Sender’s user ID. |
receivedStatusInfo | RCReceivedStatusInfo | Message receipt status. |
content | [RCMessageContent] | Message content. |
sentTime | long long | Unix timestamp (ms) of the message. Pass 0 to use the local time. |
completion | Block | Async callback returning the inserted [RCMessage] object. |
Example
RCTextMessage *content = [RCTextMessage messageWithContent:@"Test 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) {
}];
Display Inserted Messages in Chat UI
To show inserted messages immediately in RCConversationViewController
, call appendAndDisplayMessage:
with the RCMessage
object returned by the insertion method.
RCMessage *insertMessage;
[self appendAndDisplayMessage:insertMessage];