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.
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
- Java
val channel = DirectChannel("userId")
channel.clearUnreadCount { result, error ->
if (error == null) {
// Unread count cleared and synced to other devices
} else {
// Failed
}
}
DirectChannel channel = new 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
- Java
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
}
}
})
NCEngine.addChannelHandler("UNREAD_SYNC", new ChannelHandler() {
@Override
public void onRemoteChannelsSyncCompleted(RemoteChannelsSyncCompletedEvent event) {
if (event.getError() == null) {
// Refresh the channel list and unread counts in the UI
}
}
});
Remove the listener
- Kotlin
- Java
NCEngine.removeChannelHandler("UNREAD_SYNC")
NCEngine.removeChannelHandler("UNREAD_SYNC");