/ SDKs / Unreal
Chat SDKs Unreal v3
Chat SDKs Unreal
Chat SDKs
Version 3

Load previous messages

Copy link

After creating a query instance from the CreatePreviousMessageListQuery() method and using the LoadNextPage() method which returns a list of message objects, you can retrieve a set number of previous messages in a channel. With the returned list, you can display the past messages in your UI once they have loaded.

Note: Whether a user can load previous messages sent before joining the channel depends on your settings. On Sendbird Dashboard, go to Settings > Chat > Channels > Group channels, find the Chat history option. If this option is turned on, new users can view all messages sent before they've joined the channel. If not, new users can see only messages sent after they've been invited.

SBDPreviousMessageListQuery* query = channel->CreatePreviousMessageListQuery();

query->LoadNextPage(LIMIT, REVERSE, [](std::vector<SBDBaseMessage*> messages, SBDError* error) {
    if (error != nullptr) {
        // Handle error.

A LIMIT parameter indicates how many messages should be included in the returned list. A SBDPreviousMessageListQuery instance itself does pagination according to the value of the limit parameter and internally manages a token to retrieve the next page in the result set. Each time the LoadNextPage() method is called, the instance retrieves a set number of messages in the next page, and then updates the value of the token to complete the current call and prepare a next call.

If you create a new SBDPreviousMessageListQuery instance and call the LoadNextPage() method, a set number of the most recent messages are retrieved because its token has nothing to do with that of the existing instance. So we recommend that you create a single query instance and store it as a member variable for traversing through the entire message history.

Note: Before calling the LoadNextPage() method again, you must receive a success callback from the server first.