Retrieving Chatroom History Messages
The client SDK supports retrieving chatroom history messages with the following capabilities:
- Use getHistoryMessages to fetch chatroom history messages stored locally. Note that by default, the chatroom service clears locally stored history messages when a user exits the chatroom.
- Use getChatroomHistoryMessages to retrieve chatroom history messages stored on the server.
Retrieving Remote Chatroom History Messages
Call the getChatroomHistoryMessages method. If the local database contains history messages from the same time period, this interface will return an array with a size of 0. Therefore, the recommended calling sequence is as follows:
- First, call RongCoreClient's getHistoryMessages, passing in the conversation type, chatroom ID, the ID of the last message, and specifying the number of messages to retrieve, among other parameters, to fetch history messages from the local message database.
- If the result is empty, then call RongChatRoomClient's getChatroomHistoryMessages method, passing in the chatroom ID, the message's timestamp, the query direction, and specifying the number of messages to retrieve, among other parameters, to fetch history messages from the chatroom message cloud storage. When the query direction remains unchanged, the
syncTimereturned in the current call can be used as therecordTimefor the next pull, facilitating continuous retrieval.
Interface
RongCoreClient.getInstance().getHistoryMessages(conversationType, targetId, oldestMessageId, count,callback);
Parameter Description
| Parameter | Type | Description |
|---|---|---|
conversationType | [ConversationType] | Conversation type |
targetId | String | Conversation ID |
oldestMessageId | Long | The ID of the last message. Set to -1 to query the latest messages in the local database. |
count | Int | Number of messages per page. |
callback | ResultCallback<List<Message>> | Callback for retrieving history messages, ordered chronologically from newest to oldest. |