-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Total unread message count in push notifications #221
Comments
Not really worth a PR, but I did a quick check with sending a badge using FCM after line 181 in push_fcm.go:
|
The main problem is in counting the total unread messages for a given user. The server has the value per subscription (user-topic), but not the total. The count is not stored directly either. It's calculated as This is further complicated by the asynchronous nature of the server and the fact that the server may not have the data of a specific user. User's data is stored in the 'me' topic but it's loaded into memory only when the given user is online and subscribed to 'me'. So, even if I have the unread count available in a topic, generally there is no central place where it can be summed up for the given user. This place has to be created. It's not too hard, but has to be done and debugged. Unfortunately it gets more complicated as some topics are muted, some archived, some banned. In those cases the user does not get notifications of new messages. The unread messages in those topics probably should not be counted towards the total. Otherwise it would be viewed by users as an annoying bug: the badge shows some non-zero count while none of the topics in the UI have unread messages. It's certainly possible to account for all these nuances but it's a lot of work, it may get computationally heavy and/or may require changes to the storage schema, and it's going to be brittle. One solution, rather unorthodox, is to ask the client to report the number of unread messages back to the server. Currently the user reports the read ID in
The (a) would still require the "central repository of user data", the (b) would not. |
Yep - I know it's a bit fraught - and depending on the schema of synchronisation to the IOS client, there may be sync issues (if you're caching messages, for example) with what has been cached, but not read. |
That's fine. Clients already explicitly and separately report received (
Sure, but that's a simpler problem to solve. The server just increments the counter as new messages are being sent to the client until the client comes online and explicitly resets the unread counter. This way there is no issue with the unread counter on a badge being out of whack with the unread counts shown in the app. There is a very annoying bug in FB Messenger when the unread count gets stuck at 1 or 2. Mine has been showing "1 unread message" for the past 6 months with no ability to reset it. I would really prefer not to have anything like that in Tinode. |
@ozobken Hi Ken. Please take a look at https://github.com/tinode/chat/tree/ios-unread. It has the feature you requested. I've done some basic testing, but I don't have an iOS client. This version does not require any changes to the client. Could you please check if it actually works as expected. Thanks! |
Awesome - I'll have a play - hopefully later today, otherwise it'll be early next week |
I got the branch installed, and updated my client to more reliably send {note topic="usr123abc" what="read" seqId=n} messages, and now it always sends a badge value of 0. |
Just had a look at the commit - Does this only get updated if I specifically supply an "unread" {note}? |
Although I did add the option for the client to report the unread count it's currently not used by the server at all. Everything should work without any charges to the client: the unread message count is incremented with every new |
Can you show a session log with |
Here's a server log for a cycle of connect/sub/read
I do note that the server is not logging the InfoNote type, but I assume that's arriving ok Here's a subsequent send to one of the subbed channels from another client - I added a debugging
|
I'll try to reproduce later today. |
It's probably fixed: a0b891f The issue was with the unread message count being reset to 0 on the first message. All subsequent messages generated pushes with incremented badge value. |
Thx will test |
Looking good so far
|
@ozobken Hi Ken, Would you mind testing the latest from https://github.com/tinode/chat/tree/ios-unread ? It has bug fixes from devel as well as measures to prevent unbounded cache growth. Thanks! |
Sorry, @or-else Gene, I missed this - do you still need specific testing on the branch, or is this merged now? |
The branch is merged but it would be nice to test the feature some more. My iOS client is not yet handling push notifications. Thanks! |
It's been released a while ago and seems to work correctly. |
In order to display icon badges with unread count iOS requires the value to be sent by the server #154 @ozobken:
The text was updated successfully, but these errors were encountered: