Using PreviousMessageListQuery
's load()
method, which returns a list of BaseMessage
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.
Property name | Type | Description |
---|---|---|
limit | int | Specifies the number of results to return per call. Acceptable values are |
reverse | boolean | Determines whether to sort the retrieved messages in reverse order. If |
The limit
property indicates how many messages should be included in a returned list. The PreviousMessageListQuery
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 load()
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 load()
method again, you must receive a success callback through the callback handler first.
If you create a new PreviousMessageListQuery
instance and call the load()
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.
The following table shows all the supported filters for PreviousMessageListQuery
to search for messages you want to retrieve. You can use any filters in a similar fashion with the sample code above.
Name | Filters |
---|---|
messageTypeFilter | Messages with the specified message type. The |
customTypesFilter | Messages with the specified custom type. The |
senderUserIdsFilter | Messages that are sent by the specified users. The |
messagePayloadFilter | Messages including additional information such as meta arrays and reactions. |