Description
After implementing multi-device unread count synchronization, the following issues still occur:
- Inconsistent unread counts across devices during multi-device login
- The total unread count fetched on the web doesn’t match the sum of unread counts from individual conversations. Usually, the total unread count is greater than the sum.
Analysis (Root cause and requirements)
The web doesn’t have a local database. Unread counts are calculated based on offline or compensation messages and stored in the browser cache (local storage). Due to the offline message storage duration (1-7 days), it’s impossible to ensure complete consistency across devices in some scenarios. This also leads to discrepancies between the total unread count and the sum of unread counts from individual conversations.
-
Inconsistent unread counts across devices during multi-device login:
For example: User A has 10 unread messages in conversation B on device 1. When device 1 goes offline and user A logs in on device 2, they clear the unread count for conversation B. After 7 days, when user A logs back into device 1, device 1 can’t receive the unread count sync message from device 2 due to the offline storage duration. As a result, device 1 still shows 10 unread messages. -
Total unread count mismatch on the web:
Since unread counts are stored in the browser cache, the total unread count is calculated by summing up all conversation unread counts in the cache. Discrepancies occur when the cached conversation data exceeds the actual conversation list data. This can happen due to:- Users deleting conversations without clearing the unread count first
- The web can only fetch up to 1000 conversations, but there are 10001 conversation messages in the offline messages, causing the total unread count to be greater than the sum
- Browser cache data issues
Below is an example of how to check the unread count for a conversation in local storage:
Solution
The inconsistency in unread counts is due to mismatched cache data. However, real-time consistency can’t be achieved due to offline message limitations. To ensure accurate unread count accumulation, clear the browser conversation cache. The SDK provides an interface to clear all conversations. For details, refer to: Clear Unread Count for All Conversations
More support
If you have questions, feel free to submit a ticket.