PubNub allows you to store and retrieve messages as they are sent over the network by using the Storage & Playback feature. PubNub Storage 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 counts of messages in spaces
The messageCounts method returns a count of unread messages in one or more spaces. The count returned is the number of messages in history with a timetoken value greater than the passed value in the timetoken parameter.
You will need to cache the timetoken of the last retrieved message on a channel or the last time the user was online.
Retrieving missed messages in spaces
Use this method to catch up on missed messages when a device comes back online. The request returns a list of messages that were published before the start timetoken and after the end timetoken.
The method returns a maximum of 100 messages in a single channel, or 25 messages per channel if multiple channels are passed in the request. To retrieve more messages, use timestamps to page through the next batch of messages.
Start and End parameters
If you specify only the start parameter (without end), you will receive messages that are older than and up to that start timetoken value.
If you specify only the end parameter (without start), you will receive messages from that timetoken value and newer.
Specify values for both start and end parameters to retrieve messages between those timetokens (inclusive of the end value).
Retrieving most recent messages in spaces
Use the fetchMessages() method to fetch the past messages retrieve the most recent messages that were published in the specified spaces before the current time.
The method returns a maximum of 100 messages in a single channel and 25 messages per channel if multiple channels are passed in the request. To retrieve more messages, use the timestamps to page through the next batch of messages.