Skip to main content

Retrieve Chatroom Historical Messages

Enable Service​

To use the Retrieve Chatroom Remote Historical Messages feature, you need to enable the Cloud Storage for Chatroom Messages service. To enable this service, please submit a ticket. Once enabled, chatroom historical messages will be stored in the cloud by default for 2 months.

Retrieve Chatroom Remote Historical Messages​

When you exit a chatroom, local chatroom historical messages will be cleared. If you need to retrieve previous historical messages upon rejoining the chatroom, you can call this interface.

Method​

Future<int> getChatRoomMessages(String targetId, int timestamp, RCIMIWTimeOrder order, int count, {IRCIMIWGetChatRoomMessagesCallback? callback});

Parameter Description​

ParameterTypeDescription
targetIdStringChatroom conversation ID
timestampintStarting message timestamp
orderRCIMIWTimeOrderPull order: 0 for reverse, 1 for forward
countintNumber of messages to retrieve, range: greater than 0, less than or equal to 50.
callbackIRCIMIWGetChatRoomMessagesCallbackEvent callback. SDK supports callback from version 5.3.1. Other callback methods are deprecated from version 5.4.0. If a callback parameter is passed, only the callback will be triggered.

Return Value​

Return ValueDescription
Future<int>Status code of the current interface operation. 0 indicates success. Specific results need to be implemented via interface callback. Non-zero indicates failure of the current interface call operation, and no interface callback will be triggered. Refer to the error code for details.

Code Example​

IRCIMIWGetChatRoomMessagesCallback? callback = IRCIMIWGetChatRoomMessagesCallback(onSuccess: (List<RCIMIWMessage>? t) {
//...
}, onError: (int? code) {
//...
});

int? ret = await engine?.getChatRoomMessages(targetId, timestamp, order, count, callback:callback);

Callback Method​

  • onChatRoomMessagesLoaded
Function(int? code, String? targetId, List<RCIMIWMessage>? messages, int? syncTime)? onChatRoomMessagesLoaded;

Parameter Description

ParameterTypeDescription
codeintInterface callback status code. 0 indicates success, non-zero indicates an exception.
targetIdStringConversation ID
messagesList<RCIMIWMessage>Loaded messages
syncTimeintTimestamp for the next pull

Code Example

engine?.onChatRoomMessagesLoaded = (int? code, String? targetId, List<RCIMIWMessage>? messages, int? syncTime) {
//...
};