By default, PubNub doesn't store messages published on the network. You can choose to store and retrieve messages from PubNub by using the Storage & Playback feature.
The Storage & Playback feature uses a time-series based database in which each message is stored on the channel it was published, timestamped to the nearest 10 nanoseconds. PubNub message retention policy can be configured from your account with the following options: 1 day, 7 days, 1 month, and Forever.
Retrieving unread message counts
PubNub allows you to retrieve message counts on channels. The count returned is the number of messages in history with a timetoken value greater than the passed value in the
You will need to cache the timetoken of the last retrieved message on a channel or the last time the user was online.
Retrieving past messages from history
You can fetch the historical messages that have been sent to a channel using
history(). The request returns a list of messages that were sent on the channel after the
Retrieving more than 100 messages from history
By default, history returns maximum 100 messages. To retrieve more than 100, use timestamp to page through the history.
You can also use the
pubnub-flex-history wrapper to handle it automatically. Refer to the
pubnub-flex-history documentation for more details.
Retrieving messages on multiple chat rooms
You can retrieve messages from history on multiple channels using
Batch History. The batch history is limited to
500 channels and only the last
25 messages per channel.