Get Chatroom History Messages
The client SDK supports retrieving chatroom history messages. The specific capabilities are as follows:
- Use getHistoryMessages to retrieve chatroom history messages stored locally. Please note that by default, the chatroom business clears locally stored history messages when a user exits the chatroom.
- Use getRemoteChatroomHistoryMessages to retrieve chatroom history messages stored on the server. Please note that this feature relies on the Cloud Storage for Chatroom Messages service.
Enable the Service
Using getRemoteChatroomHistoryMessages requires enabling the Cloud Storage for Chatroom Messages service. Please confirm that the service is enabled before use. Once enabled, chatroom history messages are stored in the cloud by default for 2 months.
Retrieve Remote Chatroom History Messages
You can use getRemoteChatroomHistoryMessages to retrieve remote chatroom history records. If local database contains history messages from the same time period, calling this interface will return an array with a size of 0. Therefore, first call getHistoryMessages to retrieve local history records. If it is empty, then call getRemoteChatroomHistoryMessages
to retrieve remote history records.
NSArray *history = [[RCIMClient sharedRCIMClient]
getHistoryMessages:ConversationType_CHATROOM
targetId:@"chatroomId"
oldestMessageId:lastMessageID
count:count];
if (history.count == 0) {
[[RCIMClient sharedRCIMClient]
getRemoteChatroomHistoryMessages:@"chatroomId"
recordTime:recordTime
count:50
order:RC_Timestamp_Desc
success:^(NSArray *messages, long long syncTime) {
} error:^(RCErrorCode status) {
}];
}
The successBlock returns an array of retrieved history messages and syncTime
. If the pull order is RC_Timestamp_Desc
, it is the timestamp of the earliest message in the pull result (i.e., the smallest timestamp). If the pull order is RC_Timestamp_Asc
, it is the timestamp of the latest message in the pull result (i.e., the largest timestamp). If the pull order remains unchanged, the syncTime
value returned this time can be used as the recordTime
for the next pull, facilitating continuous pulling.
Parameter | Type | Description |
---|---|---|
targetId | NSString | Chatroom ID, with a maximum length of 64 characters. |
recordTime | long long | Message send timestamp (in milliseconds), indicating messages before or after recordTime . |
count | int | Number of messages to retrieve, with a maximum of 200. |
order | RCTimestampOrder | Pull order. RC_Timestamp_Desc : Descending, retrieves messages sent before recordTime in descending order of send time. RC_Timestamp_Asc : Ascending, retrieves messages sent after recordTime in ascending order of send time. Default is descending. |
successBlock | Block | Callback for successful retrieval. |
errorBlock | Block | Callback for failed retrieval. status returns the error code RCErrorCode. |