zulip / zulip-mobile

Zulip mobile apps for Android and iOS.
https://zulip.com/apps/
Apache License 2.0
1.27k stars 640 forks source link

Notifications don't work on Android without Google services #3838

Open gnprice opened 4 years ago

gnprice commented 4 years ago

This will take considerable work to change, and the number of people it affects is small, so it's not something we'll fix soon. But here's an issue to put the fact on record, in the hopes that it saves people some debugging in the future.

For the mobile app to learn when it should show a notification, we rely on FCM (Firebase Cloud Messaging, formerly known as GCM / Google Cloud Messaging) on Android, and APNs on iOS. These centralize the work of polling a server for updates across all the apps on a device, which is essential for getting prompt notifications without a lot of drain on the battery.

One consequence is that on a device with neither of those services available -- which means an Android device without Google Play Services -- we don't show notifications at all. The app works just fine when you launch it and use it in the foreground; it just never shows a notification.

This turned out to be the cause of the report in #3835 that notifications weren't working.

To make notifications work on a device without FCM or APNs, we'd need to have the app run in the background and poll for updates itself. (Of course we'd only do that when it wasn't possible to use those services.) As I wrote in a chat thread:

This won't be simple to implement, unfortunately. The Zulip server does provide a nice stream of events for long-polling, which is what the app uses for all kinds of data when it's active (and what any other client, like the webapp, also relies on.) But that's rather a firehose, with lots of information that you want when the app is in the foreground but that doesn't produce a notification.

The much-lower-volume stream of information that's needed for notifications isn't published in that form, and instead is just posted to FCM and/or to Apple's APNs. And the client also relies on the server to filter down to that stream, in particular to apply the user's preferences for which messages they want to get notifications for -- e.g. to turn them off entirely, or to get notified for every message on a given stream.

So there'd be substantial work on both server and client that'd need to happen to build this alternative channel. Most likely the easiest and cleanest way to do it would be to make a new event type a client can subscribe to in the Zulip events system, which would correspond to exactly the information the server would post to FCM or APNs.

See also other remarks in that thread.

Amolith commented 4 years ago

I understand that it won't happen for a while but I just want to put it out there that I would like to see native FCM-less mobile notifications!

Amolith commented 4 years ago

Well it has the potential to happen sooner than expected :blush: Zulip could add an option to configure a self-hosted OpenPush instance for push notifications in addition to FCM. The spec is almost finished, a Python server is done, and a library and reference implementation are in the works. It was presented at FOSDEM and, in my opinion, has a lot of promise.

gnprice commented 4 years ago

Very interesting! Thanks @Amolith for the update. I agree that that looks like a plausible approach.

cyphase commented 3 years ago

Copied from this CZO message that I just sent:

In the past I've mentioned a simple daemon I wrote to forward Zulip notifications – or more precisely, real-time events – to my Android phone via a Gotify server. I never got around to publishing it — now I have!

Here it is.

I originally wrote it because I don't have GCM/FCM on my phone for push notifications, and I'd used Gotify previously for other things. It's also useful if you want to receive notifications for things that Zulip doesn't give notifications about, e.g. message edits, reactions, presence updates, typing notifications, etc.

For now I've just committed the exact code I've been running untouched since May 2019, minus the hardcoded Gotify URL. I'll do a bit of maintenance and polishing when I get a chance.

It's very specific to my use case right now, so if anyone wants to generalize it or do anything else, I'm happy to accept contributions! Don't worry about staying within the very narrow bounds of the name; if someone wants to add another notification target, have at it. apprise is a thing..

Po84210 commented 3 years ago

FCM is not available here in China. We really need this to get Zulip notifications work on Android.

karmanyaahm commented 2 years ago

https://unifiedpush.org is a set of specifications and libraries that is currently being used by other FOSS communication apps like FluffyChat (Matrix), Fedilab (Mastodon), TRIFA (Tox). While, I'm personally not familiar with Zulip, UnifiedPush caters to a similar audience as OpenPush, so I think it might be relevant here. UP also offers FCM fallback, so the app just needs to use one library (for Android).

Po84210 commented 2 years ago

Using UnifiedPush is a good idea. Really hope it can be implemented soon.

gnprice commented 2 years ago

We'v heard another recommendation of this at https://github.com/zulip/zulip-mobile/issues/1270#issuecomment-954483474:

PS, for the subject of this issue [i.e. F-Droid]: you might consider switching to UnifiedPush for cloud messaging. That would leave the user the choice of the backend. While your PlayStore build could even default to the FCM backend, F-Droid users could pick the Gotify backend (Gotify-UP is available at F-Droid), which in my tests worked fine. The UP project is still young, but there are already apps using it (out of my head I remember two of them: Fedilab in its latest version, and the Matrix client FluffyChat).

amitlakhanpal commented 2 years ago

Casting a vote in favor of the UnifiedPush suggestion, for what it is worth, based on a recent experience trying and failing to set up push notifications to an account logged in to the Android mobile app (latest version installed from the apk on Github) being run on GrapheneOS, even with Google Play Services installed. Thanks to @alexmv we can see the server side of things is working fine, but for some reason something on the mobile device's end isn't catching on that it needs to show a notification.

Granted this is a fairly niche setup, but perhaps there is an argument to be made in general for reducing dependencies on less open projects.

Otherwise Zulip is amazing, many thanks to all the people who have worked and are working on it!

Update: Seems the notifications do work on the latest version of GrapheneOS with Google Play Services running in their usual way - undercutting somewhat the argument for UnifiedPush but wanted to leave this info to encourage anybody who may come across similar issues in the future

johnabs commented 2 years ago

Can I ask on this: can a zulip bot be a temporary hack to make this work with something like ntfy?

devurandom commented 1 year ago

In case you need more recent transition examples: Tusky (Mastodon) and Element (Matrix) recently started to offer UnifiedPush support.

At least Element provides it in both their Google Play and F-Droid versions and allows you to switch at runtime (Settings > Notifications > Other > Notification method) – the F-Droid version providing the choice between the installed UnifiedPush distributors and "background sync" / polling, but not native FCM. Tusky just selects a notification method once automatically – if at the time UnifiedPush is available, it uses that, otherwise it falls back to polling.

You can bundle your application with a UnifiedPush FCM distributor for Google Play, so that the default for those users will work well independently of whether they set up UP or not.

chrisbobbe commented 1 year ago

We've had another recommendation of UnifiedPush at https://chat.zulip.org/#narrow/stream/48-mobile/topic/Push.20Notifications.20on.20Mobile.20.28Android.29/near/1497946.

abc commented 1 year ago

Definitely need this, does anyone have a decent workaround until this is done? Not getting notifications from Zulip on my phone because of this.

cyphase commented 1 year ago

@abc See my comment above.

chrisbobbe commented 1 year ago

We've had another request for UnifiedPush at https://chat.zulip.org/#narrow/stream/48-mobile/topic/Push.20Notifications.20on.20Mobile.20.28Android.29/near/1521723.

adrienneteicher commented 1 year ago

I run Calyxos which uses microG to replace Google's proprietary libraries, while still allowing "apps developed for Google Cloud to Device Messaging (C2DM) to use the compatible Google Cloud Messaging service" developed by the microG team. So on my phone I have no problem getting notifications from apps like Uber or WhatsApp. I don't think it normally requires app developers to do anything to specifically support microG. Yet Zulip is not happy with microG and throws this error:

{ "realm": "XXXX", "email": "XXXX)", "isSelfHosted": false, "platform": { "OS": "android", "Version": 33 }, "nativeApplicationVersion": "27.201", "nativeState": { "systemSettingsEnabled": true, "googlePlayServicesAvailability": null }, "problems": [ "TokenNotAcked" ], "isLoggedIn": true, "devicePushToken": null, "ackedPushToken": null, "serverData": { "zulipVersion": "6.0-1074-g16c7aa8f5f", "zulipFeatureLevel": 167, "pushNotificationsEnabled": true, "offlineNotification": true, "onlineNotification": true, "streamNotification": true } }

Maybe microG an easier thing to support than an alternative push system?

chrisbobbe commented 1 year ago

@adrienneteicher, thanks for the report. Did you install Zulip from the APKs we publish, or from somewhere else?

adrienneteicher commented 1 year ago

Installed from f-droid.

Thanks!

22 Mar 2023 17:57:32 Chris Bobbe @.***>:

@adrienneteicher[https://github.com/adrienneteicher], thanks for the report. Did you install Zulip from the APKs we publish[https://github.com/zulip/zulip-mobile/releases], or from somewhere else?

— Reply to this email directly, view it on GitHub[https://github.com/zulip/zulip-mobile/issues/3838#issuecomment-1479933502], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AGYIPIHY5DSKLNKC5QZQP2LW5MVPXANCNFSM4KK6VEUA]. You are receiving this because you were mentioned.[Tracking image][https://github.com/notifications/beacon/AGYIPIBYC2FXEK6PHD7EFBDW5MVPXA5CNFSM4KK6VEUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOLA274PQ.gif]

chrisbobbe commented 1 year ago

We're aware that the F-Droid builds remove notification support, in a way that would still affect you with your setup.

I don't think it normally requires app developers to do anything to specifically support microG.

Interesting! If you're willing, I recommend installing our APK; it sounds like that should fix notifications. If you still have trouble, please file a new issue or email support@zulip.com.

adrienneteicher commented 1 year ago

Thanks Chris,

I tried the apk from github and I can see that zulip has registered itself for GCM in the microG settings, so that probably did it!

I'll wait until I get some messages tomorrow and let you know

22 Mar 2023 18:38:23 Chris Bobbe @.***>:

We're aware that the F-Droid builds remove notification support, in a way that would still affect you with your setup.

I don't think it normally requires app developers to do anything to specifically support microG.

Interesting! If you're willing, I recommend installing our APK[https://github.com/zulip/zulip-mobile/releases]; it sounds like that should fix notifications. If you still have trouble, please file a new issue or email @.***

— Reply to this email directly, view it on GitHub[https://github.com/zulip/zulip-mobile/issues/3838#issuecomment-1479995378], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AGYIPIDH4GY23ODWLPXAKF3W5M2I5ANCNFSM4KK6VEUA]. You are receiving this because you were mentioned.[Tracking image][https://github.com/notifications/beacon/AGYIPIBFOEN3F75TYE3NDTDW5M2I5A5CNFSM4KK6VEUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOLA3O74Q.gif]

adrienneteicher commented 1 year ago

Hi. That worked!

Thank you very much. Might I suggest clarifying the error message around notifications for the f-droid build so that users can solve this problem for themselves.

gnprice commented 1 year ago

Might I suggest clarifying the error message around notifications for the f-droid build so that users can solve this problem for themselves.

Definitely agreed. I've now filed #5693 for that.

calidancer commented 1 year ago

We're aware that the F-Droid builds remove notification support, in a way that would still affect you with your setup.

I don't think it normally requires app developers to do anything to specifically support microG.

Interesting! If you're willing, I recommend installing our APK; it sounds like that should fix notifications. If you still have trouble, please file a new issue or email support@zulip.com.

Hi @chrisbobbe, I used a self hosted version of Zulip in my own cloud for six months and everything was good. Today, after many tests, I officially moved away from Google and eventually got the first family set of De-Googled mobile phones (I have /e/ OS). Zulip notifications didn't work and I was very wrecking my ahead until I found your post. After downloading the latest version of the Zulip .apk from Github I can see that Zulip is now appearing in the list of registered apps that use push notifications in the MicroG Cloud Messaging and boom... Zulip notifications are back.

THANK YOU SOOOOOOOOOOOOOOOO MUCH!! You saved my ass!! Excuse my language!!!!!!!!

Birdibird commented 1 year ago

For me that doesn't make a difference, because I use a fully ungoogled gsi (LeOS) with a MicroG that doesn't connect to google, so push through google doesn't work of course (and that's how I want it!). So, unified push would be a great solution to be independent of google. Matrix clients on Android are using it eg as already mentioned above.