Closed luke- closed 1 year ago
Push notifications were succesfully implemented. DEMO: https://user-images.githubusercontent.com/10835179/220153198-c8af189d-20c6-446f-ab6d-e01e8d1c60ff.mp4
If we opt to use a single channel (e.g. "flutterChannel") to transmit all types of messages between the WebView and the Web application, I recommend devising a structure similar to...
There is another option I'm more in favor of is to define separate channels for different types of communications.
One could be openerChannel
, for registering Device FCM token could be registerDeviceFcmChannel
Currently, the implementation of push notifications is only compatible with Push Service (Beta). If the user decides to use their own Firebase instance for push notifications, it will not work at the moment. However, there may be a workaround. The general procedure would be sending the configuration values from the WebView to the device if the user has defined their own Firebase instance.
Then setting up the Firebase instance manually and overriding the def. values. For the time being, we are using the recommended method with google-service.json.
@PrimozRatej I've just changed the channel messages to
{type: 'showOpener'}
{type: 'hideOpener'}
{type: 'registerFcmDevice', url: 'https://sometest12356.humhub.com/fcm-push/token/update' }
I think one channel should be ok.
I don't get the push notifications working on my phone. I've updated the App to Version 0.1.20 and the firebase device token was successfully stored using the Debug Page.
When triggering a test notification it's not pushed / handled by the mobile app.
Any idea?
Interesting I just tested the flow it works as expected. I get an email, and a push to my phone and on emulator. This is what I have configured inside my User account notifications settings.
PS: Also test it on Google play internet testing track release 38 (0.1.20)
notifications seems to work.
@PrimozRatej:
I have also activated all notifications in the humhub settings.
Steps:
luke
, goto AppTest page, removed all "Registered Devices" Push token from my accountluke
on the mobile appAppTest
page, click "Trigger Javacsript Send to Javascript Channel"AppTest
page one Registered Devices Token is now displayedAppTest
page, wait until E-Mail and Bell shows new NotificationTo Test Push Notification at all, I've logged in on my mobile with Chrome to the sometesthumhub
After some time I receive 3 notifications (Web, Email, PWA (firebase push)) but no Push Notification from App
@luke- It appears that the push notifications are not providing any data, which means we are currently unable to handle the redirection upon tapping on them.
@PrimozRatej For the PWA, the push notification should contains a URL. However, it may be that we have to pass the URL differently for the mobile app.
Should I add a url
attribute here?
https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html#adding-data
Yes that's it 👍
@PrimozRatej I've added that data field
@PrimozRatej The number of push notifications is currently displayed in the app icon. It would be better if the app icon always displayed the number of HumHub notifications. Is that possible?
Ideally we can update these app icon number
vs
Should we open a new issue for it und postpone it to a later milestone? e.g. 0.4?
I think the first two options will be adequate. For push notifications, we can include the current badge count of a user in the notification's data, similar to how we handle URLs. When the app is open, we can listen for changes in the badge number within the WebView and use a flutterChannel to update the badge count. Updating the badge count using FlutterAppBadger.updateBadgeCount(newCount)
is straightforward. However, I do have concerns about the scheduled updates, which may only work when the app is running in the foreground or background and not when it is terminated.
This feature can be implemented within the scope of this milestone. It is a relatively quick addition.
@PrimozRatej Ok great. Lets start with the first two options:
I`ve added to the Firebase Notification the current amount of open notifications:
->withData(['url' => $url, 'notificationCount' => $notificationCount]);
There is now a new flutterChannel
message updateNotificationCount
. I've also added a Test button here:
https://sometestproject12345.humhub.com/mobile-app/index
I was testing a push notification for both of those features, but it appears that they are not functioning. Would you mind examining the issue? I do get an email notification but the push is not sent.
@PrimozRatej Oh yes, I introduced an bug here. The problem is now fixed.
I am unsure if this is FCM specific or a typo, the key that comes with notification count is lowercase notificationcount
. If that's a FCM I would go with notification_count
@PrimozRatej I checked it and the key name wascorrect in CamelCase. So it seems to be FCM limitation. If changed it to "notification_count" as you suggested.
There is no dedicated documentation for push.humhub.com , but basically it just sends notifications via the Firebase SDK. as described here: https://firebase.flutter.dev/docs/messaging/notifications/#via-admin-sdks
To keep it simple I would implement it using following scheme:
1. Register App to Firebase Push Proxy Service
The mobile app will receive a new Javascript channel message analogous to
showOpener
,hideOpener
with the nameregisterFcmDevice
. Maybe we change the message format from a simple string to a object. e.g.Once the a message of type
registerFcmDevices
is received, the App must create aPOST
HTTP request to the url given in the messageurl
and send the Firebase Device token with POST attribute nametoken
. Usually HumHub will trigger this channel message right after thehideOpener
message.2. Handling incoming messages
At the beginning we will send the same notifications as currently for Web/PWA to the Flutter App.
The notification will contain the following values:
title
,body
,imageUrl
,link
.When the notification is received,
body
should be displayed. When clicked, 'link' should be opened in the WebView.