The Web client doesn’t have a local database, so history messages are fetched from the remote server.
Get history messages for one-to-one and group chat
-
Enable Cloud Storage for One-to-One and Group Messages for your App Key on the Chat pricing plans page in the Console. Messages are stored for 6 months by default.
-
Use the
RongIMLib.getHistoryMessages
API to fetch history messages. For details, refer to the documentation.
-
To get more messages, adjust the
timestamp
parameter. Change the timestamp to fetch messages from different time periods, enabling pagination or fetching more messages. IfhasMore
isfalse
in the response, stop calling the API. -
Example: Set
timestamp
to 0,order
to 0, andcount
to 20 for the first call, which fetches 20 messages inmessageList
. To get more, assign the smallestsentTime
frommessageList
totimestamp
and call the API again.
Get history messages for chatroom
-
Enable Cloud Storage for Chatroom Messages for your App Key on the Chat pricing plans page in the Console. Messages are stored for 2 months by default.
-
Use the
RongIMLib.getChatroomHistoryMessages
API to fetch history messages. For details, refer to the documentation. -
The logic for fetching more messages is the same as Get history messages for one-to-one and group chat.