Feature Request: Receiving Notifications from Talk while App closed
Closed this issue · 9 comments
How is it possible to have something similar to Firebase Cloud Messaging, where when a user receives a chat message on Talk while the app is closed, the user then receives a push notification?
It's pretty hard, because it's a closed off system (neither source nor software freely available), but for the app we developed this initially for we got it working. Basically what you need is push proxy that you control and define that when registering for notifications. I have a reverse engineered version written in go. It's not good, but it works at least.
I suggest you read the nextcloud docs about notifications (which I had to to understand how this works). Be aware that the docs are sometimes misleading (at least I found some incorrect information).
If you want I can publish the push proxy code I've written back then (it's pretty ugly to be honest and only covers our use case).
The current code for the client implementation of notifications lives in https://github.com/jld3103/dart-nextcloud/tree/feature/notifications-v2 . I didn't finish it, because there was a bug in nextcloud that prevented me from writing proper tests, but that is fixed in 21.0.2, so I might finish it up soon.
So I gave you some hints on how it works, but it's a complete mess and not easy to explain. If you have any question please ask, but it's a long time ago since I worked with the push notifications so I might forgot something. At least we had it working once, so I/you/we can take a look at that implementation inside the app (https://github.com/Viktoriaschule/App/commits/feature/nextcloud-talk)
I saw this question on StackOverflow where the first answer pointed out that one might use platform-channels.
Nextcloud have their apps for Talk available for iOS and Android. Both are open source:
Android
iOS
Maybe, through a combination of platform-channels and the above mentioned open source apps for Talk it might be possible to build such a feature.
What do you think @jld3103 ?
I agree that the docs of Nextcloud are sometimes not that well explained...
You could certainly share your code, it might also benefit others as long this feature is not implemented.
So yes you also need to setup some native stuff to pass the message to flutter, but that's the easy part sadly.
What would then be the hard part?
I imagine that you need to somehow make a small part of the app run in the background while the app is closed so that it can trigger push notifications at any point in time.
Maybe, looking closer at the source code of the Firebase Messaging Package could give some ideas on how to achieve it 🤔
Well the hard part was the push proxy. Probably now that the code has been written it's much easier, but you still need to run a server with the push proxy and then configure this package accordingly. On the flutter side you need to pass the message from native to flutter and then decrypt it and what not. Maybe I'm still thinking it's so hard, because I invested a lot of time back then when I reverse engineered implemented all the stuff.
Initially, I thought this plugin did not even support notifications, because I have worked with other plugins with notifications, like flutter_local_notifications.
In this plugin, for example, an initial setup is required before one can use the plugin.
In iOS you have to edit the AppDelegate.swift
file and enable the Push Notifications Capability.
I saw that for firebase_messaging you need to edit the native Android Application
file (as referred here) and even more steps are required for iOS as per this.
So, since none of these additional setup steps were described anywhere for this plugin I assumed that there was no support for push notifications.
But I certainly don't know as much about doing these push notifications as you (@jld3103) do.
I don't know exactly what you mean with push proxy.
Also, you mentioned that you have to set up your own server. So, this means that this is not possible through the server on which Nextcloud is running?
Since you know a lot more about this, could you maybe provide some clearer steps on how to achieve the push notifications?
(Maybe with some resources)
Yes you have to run a server with a program called push proxy. That push proxy is called from the nextcloud instance whenever a push notifications should be sent. It relays that information to other providers like firebase messaging for example. You could also do anything else. In your app you get the firebase notifiction as usual and then have to decrypt it.
If I'm not mistaken, Push notifications as a Nextcloud client device might be very interesting for sending push notifications.
One of the headings mentions Subscribing at the Push Proxy.
Unfortunately it only mentions POST /devices
as a POST request.
When comparing to the previous section Unsubcribing at the Nextcloud server it actually mentions a proper request that you can call:
DELETE /ocs/v2.php/apps/notifications/api/v2/push
So, concerning POST /devices
, do you know what the full request should look like?
Yes that page is very important. You have to subscribe at the nextcloud instance and the push proxy, but only unsubscribe at the nextcloud instance. You can take a look at the branch I posted earlier. It already contains the correct code to do both things.