How to get more history messages on the Web client?

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

  1. 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.

  2. Use the RongIMLib.getHistoryMessages API to fetch history messages. For details, refer to the documentation.

  1. To get more messages, adjust the timestamp parameter. Change the timestamp to fetch messages from different time periods, enabling pagination or fetching more messages. If hasMore is false in the response, stop calling the API.

  2. Example: Set timestamp to 0, order to 0, and count to 20 for the first call, which fetches 20 messages in messageList. To get more, assign the smallest sentTime from messageList to timestamp and call the API again.

Get history messages for chatroom

  1. 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.

  2. Use the RongIMLib.getChatroomHistoryMessages API to fetch history messages. For details, refer to the documentation.

  3. The logic for fetching more messages is the same as Get history messages for one-to-one and group chat.