thunder-app / thunder

Thunder - An open-source cross-platform Lemmy client for iOS and Android built with Flutter
https://thunderapp.dev
GNU Affero General Public License v3.0
745 stars 64 forks source link

Push notification #219

Open Tealk opened 1 year ago

Tealk commented 1 year ago

Is your feature request related to a problem? Please describe. I would like to be informed when I receive responses.

Describe the solution you'd like A push integration, preferably not from google but e.g. with UnifiedPush

trymeouteh commented 1 year ago

Would like to see notifications work on degoogled devices.

shortwavesurfer2009 commented 12 months ago

This seems quite similar to #125

K4LCIFER commented 6 months ago

[...] with UnifiedPush

Agreed. This would require backend support from lemmy -- there is an open issue for this.

micahmo commented 6 months ago

Hey all! An experimental version of notifications (for Android) is being worked on in #1000! It works completely without a notification server by having Thunder make a periodic poll. Unfortunately this won't work on iOS and has various limitations depending on Android manufacturer, but it appears like the solutions mentioned in LemmyNet/lemmy#2631 have similar issues, so this is at least a start on our part. 😊

K4LCIFER commented 6 months ago

Hey all! An experimental version of notifications (for Android) is being worked on in #1000! It works completely without a notification server by having Thunder make a periodic poll. Unfortunately this won't work on iOS and has various limitations depending on Android manufacturer, but it appears like the solutions mentioned in LemmyNet/lemmy#2631 have similar issues, so this is at least a start on our part. 😊

I think it would still be a very good idea to have unified push supported. It isn't only push notifications that it adds. It also synchronizes the polling of all apps that supports it (this enables the device to remain sleeping for longer without being interrupted), and it supports the transition away from proprietary services like Google's, and Apple's push notifications.

micahmo commented 6 months ago

@K4LCIFER and @Tealk, can you give a brief overview of how we could integrate UnifiedPush with Thunder?

K4LCIFER commented 6 months ago

@K4LCIFER and @Tealk, can you give a brief overview of how we could integrate UnifiedPush with Thunder?

* Would users self-host the server?

* Could we integrate the listener directly into Thunder, or would it be a separate app?

It is explained well in the documentation (or, at least, far better than I could summarize :stuck_out_tongue_winking_eye: ).

Would users self-host the server?

It is not necessary, but it is possible.

Could we integrate the listener directly into Thunder, or would it be a separate app?

A dedicated app (e.g. Ntfy) is responsible for retrieving notifications. This single source is where the potential gains in battery life arises.

P.S. For more information, there exists a decently long thread with input from the devs.

Tealk commented 6 months ago
  • Would users self-host the server?

UnifiedPush is designed to be used with self-hosted servers, but it can also be used with third-party servers. With https://ntfy.rollenspiel.monster we offer such a service.

  • Could we integrate the listener directly into Thunder, or would it be a separate app?

See @K4LCIFER answer

micahmo commented 6 months ago

Thanks both for the explanations!

One more question: what would be the ask of Thunder devs here?

Also does any of this provide benefit for iOS? Because that's really where #1000 is lacking.

Sorry for all the questions, I'm just trying to wrap my head around what this would look like if we supported it!

Tealk commented 6 months ago
  • On the server side, there's discussion in the Lemmy issue of integrating UnifiedPush with the Lemmy backend.

Are you sure they want to integrate a server? Or just the function for UnifiedPush to receive notifications?

  • On the client side, would we integrate Ntfy with Thunder? For example, can we make the tap action navigate to Thunder instead of opening the Ntfy app?

the tap action?

It's more about getting a notification when something lands in your inbox Screenshot_20240109-170058

micahmo commented 6 months ago

Are you sure they want to integrate a server? Or just the function for UnifiedPush to receive notifications?

I am not really sure, which is why I am asking these questions, and trying to nail down exactly what would be asked of us from the Thunder side of things. Pardon my ignorance! 😊

the tap action?

Yes, I would want to tap on the notification to show the message it in Thunder, and maybe even have quick actions for Mark as Read, etc. Do you know if Ntfy always handles these actions, or whether it's possible to trigger an action in another app?

It's more about getting a notification when something lands in your inbox

You should check out the video recording in #1000 and see if it's what you had in mind! It's local notifications, not based on UnifiedPush, but it sounds like what you might want. 😊

hjiangsu commented 6 months ago

and it supports the transition away from proprietary services like Google's, and Apple's push notifications.

I'm not too familiar myself with UnifiedPush, but from a quick look, I was not able to find information on how this would work on iOS devices. It seems to mainly be targeting Android devices so there will most likely be two separate implementations for the different platforms (Android/iOS).

This being said, I'm completely open to having UnifiedPush as a solution for Android devices, along with what is being implemented at the moment with local notifications. Like @micahmo, I'm not too familiar with how it works but it does seem like there is a package which might help simplify our implementation with UnifiedPush: https://pub.dev/packages/unifiedpush


For now, this is what I'm envisioning:

Android:

iOS:

Tealk commented 6 months ago

ou should check out the video recording in #1000 and see if it's what you had in mind! It's local notifications, not based on UnifiedPush, but it sounds like what you might want. 😊

Yes, the function looks the way I imagine it.

Do you know if Ntfy always handles these actions, or whether it's possible to trigger an action in another app?

Yes that is possible, element, fluffychat and also a few mastodon apps support UnifiedPush and the actions you describe there are possible.


This is currently not possible on iOS, let's see what happens if apple now has to allow more stores, then this could also work in the future.

K4LCIFER commented 6 months ago

@micahmo On the client side, would we integrate Ntfy with Thunder? For example, can we make the tap action navigate to Thunder instead of opening the Ntfy app?

The notification appears on your device as if it originated from the end user application -- the push distributor (e.g. Ntfy) forwards them to the end-user application.


@micahmo On the server side, there's discussion in the Lemmy issue of integrating UnifiedPush with the Lemmy backend. I suppose the alternative, if they don't do that, would be to create instructions for people to set up their own UnifiedPush server that somehow polled Lemmy, retrieved the relevant information, and packaged it up into a notification.

This is where my knowledge of the protocol is a bit lacking (and, in all honesty, so is the official Unified Push documentation) -- I'm not entirely sure what is required of the Lemmy servers.


@micahmo Also does any of this provide benefit for iOS?

It is not compatible with iOS, as iOS does not allow applications to run in the background. The distributor app must be able to run in the background in order to fetch notifications. From UnifiedPush's FAQ:

Will UnifiedPush ever work on iOS?

iOS doesn’t support running services in the background, so running a UnifiedPush distributor won’t be possible without jailbreaking or Apple’s approval for the foreseeable future. If someone has a solution, share that in the chat.


@micahmo Yes, I would want to tap on the notification to show the message it in Thunder, and maybe even have quick actions for Mark as Read, etc. Do you know if Ntfy always handles these actions, or whether it's possible to trigger an action in another app?

As far as I am aware, the notification is always displayed on the device as if it had originated from the end-user application rather than the distributor app.

Fxsch commented 1 month ago

From what I understand, the UnifiedPush app on your phone simply gets a message from the UnifiedPush server that a certain app has a new notification and it then wakes that app up and tells it to poll for new notifications. I'm not 100% sure that that's how it works but it makes sense since the notifications aren't coming from the UnifiedPush app but from the actual app that got that notification.

Also, there's apps like Moshidon for Mastodon or Molly for Singal that support UnifiedPush, even though it's not supported on the server side. What they do is, they use a server (or rather, a simple container) that periodically checks the server (in this case, the Mastodon instance or the Signal server) for new notifications via the API and if there are any, it tells the UnifiedPush server, which then tells the UnifiedPush app on the phone. In Molly you have to set that server up yourself while Moshidon provides one for everyone to use.

hjiangsu commented 1 month ago

the UnifiedPush app on your phone simply gets a message from the UnifiedPush server that a certain app has a new notification and it then wakes that app up and tells it to poll for new notifications.

This is pretty on-point! The one correction here is that the UnifiedPush server can send a payload which the app can then use to figure out the rest (e.g., retrieve the specific notification, open up a specific page, etc)

What they do is, they use a server (or rather, a simple container) that periodically checks the server (in this case, the Mastodon instance or the Signal server) for new notifications via the API and if there are any, it tells the UnifiedPush server, which then tells the UnifiedPush app on the phone.

This is what we're essentially working on with push notification support. This is still very much a WIP but there's a repo that contains the server code which polls for new notifications via the Lemmy API using the auth token. If you're curious, this is the repo: https://github.com/thunder-app/thunder_server. This is by no means complete and should not be ran (unless you're a developer and understand the implications of it)

Doing this however, is a bit risky because the server has to store the auth token in order to perform actions as a given user, which can have fairly big security implications. In addition, the auth token doesn't have any scopes attached to it, so it acts as a master key and can basically perform anything and everything the user can.

Support for this should be ideally done at the instance-side (Lemmy), and it looks like this is planned for the next major release (0.20.0): https://github.com/LemmyNet/lemmy/milestone/24. If this is implemented on Lemmy's side, then adding support for push notifications should be much easier and more secure (depending on how it's implemented)