Skip to content

[Info] Notification badge unread count tips (discussion) #511

Open
@kevinaboos

Description

@kevinaboos

Just noting this here for future use, for when Robrix supports notifications on mobile and we need to calculate the count of unread messages/notifications.

Danny from the Element X iOS team made this very helpful comment (and there is some context behind it as well) https://matrix.to/#/!qSsPTKDfMGYqhgiLPJ:flipdot.org/$_rJfoHNfV7O4oo_h7go1GA0V5ZBMkgO5DmAu9AuCa_8?via=flipdot.org&via=matrix.org&via=element.io

Relevant conversation snippets are copied here for posterity:

Danny:

I'm working on the notification badge count in a fork of Element X iOS (hopefully can push the changes upstream). I'm seeing that the notification extension isn't persisting the incoming notification that it looks up with a sliding sync to the main database. I see there is cross-process locking implemented, and I have the main app force quit when I test. Any idea why the NotificationClient isn't writing to the shared DB? Or gotchas in regard to this? Perhaps I should not be expecting it to be persisted at all and this is not implemented yet.

Ivan:

The state store isn’t cross-process “friendly”. It’s in-progress, and sadly paused due to other projects with higher priority.

Danny:

dang, it seems that's how Signal and Telegram compute a reliable badge count locally. I'll come up with some backup method for now. Or maybe look into making it cross-process friendly. I would appreciate any links to issues regarding the current status on that project if possible. Thank you

Ivan:

matrix-org/matrix-rust-sdk#4285 and this comment especially matrix-org/matrix-rust-sdk#4285 (comment). That’s for the generalisation of the cross-process lock poison. But but but it won’t solve the badge counter. This will just allow to access the state store from different processes. To get a correct badge counter, we need to automatically back paginate. I have started to write an issue for that but it still a draft since a week.

I see, thank you for the pointers. I've decided to compute the count locally based on the rooms, messages, etc in the local database. Computing the count is smooth in the main app, and for now to compute it in the notification service extension (iOS), I've added a lightweight shared sqlite DB in the shared app group. It basically just stores all the roomID's that have live notifications (based on the settings the user selects in the app). Then the extension uses that and the information for the incoming notifications room to compute the count.

Of course the badge count currently is the number of rooms with unread messages, not the actual unread messages count. But I think we will add a toggle in the app to let the user decide.

In this way we avoid any inaccurate server side counts, as there were reports of ghost badge counts that never go away even with no unread messages in the main app.

The main issue with a solution like this is if you have multiple devices. But when registering the phone's "push id" I added the "content-available:1" flag to the default payload that will be sent with all notifications to wake up the main app, where it can perform a sliding sync, persist it, and fix up this new lightweight shared DB. Of course "content-available" is not reliable and at most may open the main app twice an hour I hear. And it doesn't open the main app if it is force quit I believe.

Ideally the extension one day will be able to write back what it has learned about the incoming notifications room to the main database and there will be no issues with multiple devices. A kludge but as elegant as possible. Since refactoring the cross process lock and getting the notification service extension to persist that data feels like a much larger fix.

Manu:

this is a very smart approach, Danny. Where do you manage this shared sqlite DB? Is it on the iOS app side or on a fork of the SDK

Danny:

Thanks Manu, I manage the shared sqlite db on the iOS app side

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedBlocked on another issue or missing feature

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions