Skip to main content

Multi-device unread sync

When a user is signed in on multiple devices, the Multi-device Message Sync service keeps messages in sync across devices. Read and unread status is still stored locally on each device. Use multi-device unread sync to share that status across all signed-in devices.

The Chat SDK provides a mechanism for syncing unread status in direct and group channels. When one device clears the unread count, other devices receive the updated read state through the channel handler.

tip

Community channels use a different sync mechanism.

Sync read status

Use channel.clearUnreadCount() to clear the unread count and notify other logged-in devices.

kotlin
val channel = DirectChannel("userId")

channel.clearUnreadCount { result, error ->
if (error == null) {
// Unread count cleared and synced to other devices
} else {
// Failed
}
}

Listen for read status sync

Use NCEngine.addChannelHandler() to receive a notification when the channel list is synced from the server. After this callback fires, refresh your channel list to get the updated unread counts.

kotlin
NCEngine.addChannelHandler("UNREAD_SYNC", object : ChannelHandler {
override fun onRemoteChannelsSyncCompleted(event: RemoteChannelsSyncCompletedEvent) {
if (event.error == null) {
// Refresh the channel list and unread counts in the UI
}
}
})

Remove the listener

kotlin
NCEngine.removeChannelHandler("UNREAD_SYNC")