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.getHistoryMessagesAPI to fetch history messages. For details, refer to the documentation.
-
To get more messages, adjust the
timestampparameter. Change the timestamp to fetch messages from different time periods, enabling pagination or fetching more messages. IfhasMoreisfalsein the response, stop calling the API. -
Example: Set
timestampto 0,orderto 0, andcountto 20 for the first call, which fetches 20 messages inmessageList. To get more, assign the smallestsentTimefrommessageListtotimestampand 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.getChatroomHistoryMessagesAPI 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.
