mattermost / mattermost-mobile

Next generation iOS and Android apps for Mattermost in React Native
https://about.mattermost.com/
Apache License 2.0
2.2k stars 1.33k forks source link

Push notifications doesn't work #7152

Closed gintonic80 closed 1 year ago

gintonic80 commented 1 year ago

Summary

Push notifications doesn't work with Android or IOS apps. There are no messages (absolutely) in the DEBUG log about any PUSH actions.

Steps to reproduce

Using docker-compose ymls. Mattermost Version: 7.8.0 Database Schema Version: 101 Database: postgres Enable TPNS https://docs.mattermost.com/deploy/mobile-hpns.html Enable Push in user profile settings.

gintonic80 commented 1 year ago

Deviceid field also empty in Sessions table. image

mb706 commented 1 year ago

I am having a similar issue: new sessions created with the Android app version 2.1 do not get a "deviceid" and do not receive push notifications. I have users with version 2.0.1 for whom push notifications still work, but that could also be because their sessions were created with earlier versions of the app. I am therefore not yet sure if this issue exists only since 2.1. I will have more time to investigate this on my end in the coming days, but wanted to report that gintonic80 is not the only one with this problem.

mb706 commented 1 year ago

Update on why this was not working for me: Apparently the way that device ids (Tokens) were retrieved has changed in some way recently (on Google's side), which some ad block firewalls were still blocking.

The React Native Notifications code that retrieves tokens is here: when the Mattermost app is built in debug mode, then the problem is written out to the android log and can be seen with logcat | grep ReactNativeNotifs.

It would be useful if the app could give an indication about the fact that notifications are not registered. Maybe by checking if there is no device id / token after a certain amount of time after calling Notifications.registerRemoteNotifications()?

Sorry @gintonic80 , my issue is probably unrelated to yours.

albearman commented 1 year ago

I have a similar problemI have a similar problem that the app (v 2.1, Android) is not registering for notifications and not getting the deviceToken. But this doesn't happen on all devices: some devices work fine on the same build. So far no dependency has been detected. As soon as we analyze devices with this problem - I'll come back with information.

mb706 commented 1 year ago

I know almost nothing about react native, notifications, or the mattermost mobile code base, but maybe the following is helpful for someone who does:

If others still have problems, maybe it is related to this change in app/init/push_notifications.ts. Before the change, Notifications.registerRemoteNotifications() was always called during startup (unless the app was not logged in), which runs the code that generates the token / deviceid for Android. Since this change, registerRemoteNotifications() only runs when Notifications.isRegisteredForRemoteNotifications() is false. However, as I understand it, isRegisteredForRemoteNofications() only checks whether notification permissions were granted, not whether a token is present. So maybe there are cases where notification permissions were granted but retrieving a token failed on the first try for some reason? Then, as I understand this, the app never tries to get a new tokenm unless the user logs out and logs back in again or something like this.

amyblais commented 1 year ago

Opened https://mattermost.atlassian.net/browse/MM-50942.

spdrcd commented 1 year ago

I have a similar problemI have a similar problem that the app (v 2.1, Android) is not registering for notifications and not getting the deviceToken. But this doesn't happen on all devices: some devices work fine on the same build. So far no dependency has been detected. As soon as we analyze devices with this problem - I'll come back with information.

I have went and downloaded an older version of the app v 2.0.x it seems like it has to do with android version rather than the app version? because my old phone which is on an older version of android has no problem receiving push notification

bitdessert commented 1 year ago

Try deleting 'v2' from the device token settings. The server and the phone may have different token values. I deleted v2 and checked that it works fine. The code after modification is 'storeDeviceToken(${prefix}:${deviceToken});'

gintonic80 commented 1 year ago

Try deleting 'v2' from the device token settings. The server and the phone may have different token values. I deleted v2 and checked that it works fine. The code after modification is 'storeDeviceToken(${prefix}:${deviceToken});'

For example, my devices with v2 mobile app (Android 9) can't register deviceid and i have nothing to change. There is no problem with iOS v2 and Andriod v1.55.1 apps.

spdrcd commented 1 year ago

Just went back to the google playstore, there seems to be a mattermost - beta version availible. push notification seems to be working on that one for my phone. I am on Android 12

BobWs commented 1 year ago

I keep seeing this message on iOS devices, but I do get notifications and badges for new messages! The notifications are slow on arrival but it works.. How to get rid of the error message?

D342791A-4107-4FE9-80BC-6A94114C4D6A B721F7FF-612F-49B8-B7E9-0A2F1599739C

spdrcd commented 1 year ago

I updated to the most recent version on android a few weeks ago, it seems to be working for me on Android now

larkox commented 1 year ago

@BobWs Are you receiving push notifications? This message (maybe the wording is not the best) only refers to push notifications. That is... if you are in the app, and someone mentions you, you will see the mention. But when you close the app, if someone mentions you, do you receive a system notification telling you you have a new message?

If that is the case, then maybe there was something wrong when you logged in the first time (when this is checked). Hopefully, logging out and logging back in should fix the issue.

BobWs commented 1 year ago

Are you receiving push notifications?

It is working now! I reinstalled the mobile apps on my iOS devices and logged in and now it is working, no more error message.👍

spdrcd commented 1 year ago

Are you receiving push notifications?

It is working now! I reinstalled the mobile apps on my iOS devices and logged in and now it is working, no more error message.👍

Congratulations 💯

larkox commented 1 year ago

This seems to be fixed, so I will close it. Feel free to comment if anyone is still seeing issues.

MarcVJ commented 8 months ago

Hello,

We got stability problems with push notifications on mobile devices, using Mattermost Server Team Edition v9.3.0. We have notifications in some cases so it doesn't seem to be the same issue.

We were able to understand what follows :

Configuration :

Those tests are OK : If I am out of conversation A on computer and phone app is closed, I receive notifications on phone and computer. If I display conversation A on any device, I don’t receive notifications on any device.

This causes us trouble : If on the phone I use the upper-left arrow to get out of the conversation, I don’t receive notifications on phone or computer, even if I left the app in background, or if I lock the phone. It seems to work as if I still was displaying the conversation.

image

Two ways we found to avoid this is to select another conversation on the mobile app, or to kill the app in the background. Doing this, we systematically had the notifications.

We were able to reproduce this. We will explain this to the users, but it is not very practical to do.

Would that be possible to fix this ?

Feel free to test if you have the same behavior.

Note that on one of our Android devices, there also is a back button on the system on bottom of screen, and if used, it behave differently, really gets out of conversation A and we have notifications. This is not possible on iPhone : d711122160161e07ab11f6ea30a3d3cd597818f2

Regards,