Unread

LAST EDIT May 17 2021

The most common use case for client level events are unread counts. Here's an example of a complete unread count integration for your chat app. As a first step we get the unread count when the user connects:

By default the UI component SDKs (React, React Native, ...) mark messages as read automatically when the channel is visible. You can also make the call manually like this:

While you're using the app, the unread count can change. A user can be added to a channel, a new message can be created, or the user can mark the messages as seen on another tab/device.

Unread counts are only stored and returned at connection time for channel members.

The markRead function can also be executed server-side by passing a user ID as shown in the example below:

To support updating the unread count in real time, you can listen to these events:

  • notification.message_new

  • notification.mark_read

These two events include the fields total_unread_count and unread_channels. You can listen to them all at once like this: