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. Please ensure that the service is enabled before use. 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
Parameter | Type | Description |
---|---|---|
targetId | String | Chatroom conversation ID |
timestamp | int | Starting message timestamp |
order | RCIMIWTimeOrder | Pull order: 0 for reverse, 1 for forward |
count | int | Number of messages to retrieve, range: greater than 0, less than or equal to 50. |
callback | IRCIMIWGetChatRoomMessagesCallback | Event 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 Value | Description |
---|---|
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
Parameter | Type | Description |
---|---|---|
code | int | Interface callback status code. 0 indicates success, non-zero indicates an exception. |
targetId | String | Conversation ID |
messages | List<RCIMIWMessage> | Loaded messages |
syncTime | int | Timestamp for the next pull |
Code Example
engine?.onChatRoomMessagesLoaded = (int? code, String? targetId, List<RCIMIWMessage>? messages, int? syncTime) {
//...
};