fix: #42
Uses https://codeberg.org/UnifiedPush/unifiedpush-rs/
I'm not entirely sure about the UX around it, but functionality-wise it works. One deliberate decision was to skip most of the app startup when activated through dbus. That's because it's quite expensive for stuff that's left unused for handling the notification (e.g. reading secrets, network monitor, proxy, settings etc.). So it just does the bare minimum and if activated normally it will go through the proper startup code. I do think I went a bit too far with the compile time flags and might be annoying to maintain now, might have to let it call the separate function in the non-unifiedpush compilation too...
Onto API:
- on startup we create the unifiedpush instance and try to register a distributor. There's only 1 on Linux as far as I know, so I didn't bother with a UI yet, if there's more than 1, it will use the first it find, if there's 0, it will set a variable so we know that UP is not available.
- if
--unifiedpush-bg push is passed, the process will launch as a service and will die after a while (aka after it handles the message in this case). The above startup workflow will run which is basically skipping the normal workflow.
- on new endpoint, it unregisters and then registers a webpush instance with mastodon, uses the user's settings for what types to receive and sets
unifiedpush_enabled to true for the user if successful
- on unregister, it unregisters from the instance and sets
unifiedpush_enabled to false
- on new message, it gets the account uuid from the instance (it's uuid:fedi_instance) and parses the message which includes {notification_type, icon, title, body, notification_id} among others. If it's running in
--unifiedpush-bg, we basically just use the info from the message and send the notification as is, but if it's running in normal mode, we fetch the actual notification object from the ID and then send the notification like we'd normally do with our own titles, bodies, buttons, grouping, etc. That, again, allows this to be very optimized when the app is closed while fully featured when it's open.
- For a user to register, they go to settings>notifications, if UnifiedPush + distributor is available there will be a clickable switch, otherwise it won't be clickable and the reason will be shown. Oh, and on registration, we also use the VAPID from the mastodon instance, if it has any.
- When the settings window is closed, we also send the muted-notification-types to the webpush api so mastodon only sends us those we want. Some newer ones are missing however, so that's just
true for now.
- To support both UP and our current websocket notifications, if the user has enabled UP, the instance account will disconnect from the websocket and vice-versa
- oh and, we never really requested the "push" permission from fedi servers so accounts will have to be re-authed to use UP
I think that's all, I don't know if I'm missing something. I'm slightly confused about https://unifiedpush.org/developers/ux/#unregistration. Am I supposed to re-register accounts that didn't manually unregister? 🤷
Other than that, I did run across some segfaults, but I didn't manage to dump them and can't reliably reproduce them so I don't know if they are from libunifiedpush or our recent huge refactors, so I'll have to further investigate/stress test it.
cc: @s1m does this sound okay?
image
fix: #42
---
Uses https://codeberg.org/UnifiedPush/unifiedpush-rs/
I'm not entirely sure about the UX around it, but functionality-wise it works. One deliberate decision was to skip most of the app startup when activated through dbus. That's because it's quite expensive for stuff that's left unused for handling the notification (e.g. reading secrets, network monitor, proxy, settings etc.). So it just does the bare minimum and if activated normally it will go through the proper startup code. I do think I went a bit too far with the compile time flags and might be annoying to maintain now, might have to let it call the separate function in the non-unifiedpush compilation too...
---
Onto API:
1. on startup we create the unifiedpush instance and try to register a distributor. There's only 1 on Linux as far as I know, so I didn't bother with a UI yet, if there's more than 1, it will use the first it find, if there's 0, it will set a variable so we know that UP is not available.
2. if `--unifiedpush-bg` push is passed, the process will launch as a service and will die after a while (aka after it handles the message in this case). The above startup workflow will run which is basically skipping the normal workflow.
3. on new endpoint, it unregisters and then registers a webpush instance with mastodon, uses the user's settings for what types to receive and sets `unifiedpush_enabled` to true for the user if successful
4. on unregister, it unregisters from the instance and sets `unifiedpush_enabled` to false
5. on new message, it gets the account uuid from the instance (it's uuid:fedi_instance) and parses the message which includes {notification_type, icon, title, body, notification_id} among others. If it's running in `--unifiedpush-bg`, we basically just use the info from the message and send the notification as is, but if it's running in normal mode, we fetch the actual notification object from the ID and then send the notification like we'd normally do with our own titles, bodies, buttons, grouping, etc. That, again, allows this to be very optimized when the app is closed while fully featured when it's open.
6. For a user to register, they go to settings>notifications, if UnifiedPush + distributor is available there will be a clickable switch, otherwise it won't be clickable and the reason will be shown. Oh, and on registration, we also use the VAPID from the mastodon instance, if it has any.
7. When the settings window is closed, we also send the muted-notification-types to the webpush api so mastodon only sends us those we want. Some newer ones are missing however, so that's just `true` for now.
8. To support both UP and our current websocket notifications, if the user has enabled UP, the instance account will disconnect from the websocket and vice-versa
9. oh and, we never really requested the "push" permission from fedi servers so accounts will have to be re-authed to use UP
I think that's all, I don't know if I'm missing something. I'm slightly confused about https://unifiedpush.org/developers/ux/#unregistration. Am I supposed to re-register accounts that didn't manually unregister? 🤷
Other than that, I did run across some segfaults, but I didn't manage to dump them and can't reliably reproduce them so I don't know if they are from libunifiedpush or our recent huge refactors, so I'll have to further investigate/stress test it.
cc: @s1m does this sound okay?
