Skip to main content

Get Chatroom History Messages

The client SDK supports retrieving chatroom history messages. The specific capabilities are as follows:

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.

ParameterTypeDescription
targetIdNSStringChatroom ID, with a maximum length of 64 characters.
recordTimelong longMessage send timestamp (in milliseconds), indicating messages before or after recordTime.
countintNumber of messages to retrieve, with a maximum of 200.
orderRCTimestampOrderPull 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.
successBlockBlockCallback for successful retrieval.
errorBlockBlockCallback for failed retrieval. status returns the error code RCErrorCode.