Load previous messages
Using SbPreviousMessageListQuery
's LoadNextPage()
method, which returns a list of SbBaseMessage
objects, you can retrieve a set number of previous messages in a channel. With a returned list, you can display the past messages in your UI once they have loaded. The following code is an example of retrieving previous messages in a channel.
SbPreviousMessageListQuery
This table only contains the required properties shown in the code above. See the API reference page for a complete list of properties.
Property name | Type | Description |
---|---|---|
MessageTypeFilter | If specified, it restricts the search scope to only retrieve messages that match the specified message type. | |
CustomTypesFilter | List<string> | If specified, it restricts the search scope to only retrieve messages that match the specified custom type. |
SenderIdsFilter | List<string> | If specified, it restricts the search scope to only retrieve messages sent by the users with the specified user IDs. |
The Limit
property indicates how many messages should be included in a returned list. The SbPreviousMessageListQuery
instance itself does the pagination of a result set according to the value of the Limit
property 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 updates the value of the token to complete the current call and prepare the next call. Before calling the LoadNextPage()
method again, you must receive a success callback through the callback handler first.
If you create a new SbPreviousMessageListQuery
instance and call the LoadNextPage()
method, a set number of the most recently sent messages are retrieved because the new instance's token has nothing to do with the previously created 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.