Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use firebaseReceiver with FCM #7068

Merged
merged 22 commits into from
Sep 9, 2022

Conversation

p1gp1g
Copy link
Contributor

@p1gp1g p1gp1g commented Sep 7, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Use Firebase-Messaging instead of embedded_fcm_distributor hen using FCM.

Motivation and context

There are issues with notifications with FCM

Screenshots / GIFs

Tests

  • Step 1
  • Step 2
  • Step ...

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

ouchadam and others added 9 commits August 25, 2022 09:05
ATM, it uses the default fallback if cancelled
The forced unregistration always happens in register
function
Signed-off-by: sim <git@sgougeon.fr>
Signed-off-by: sim <git@sgougeon.fr>
@p1gp1g
Copy link
Contributor Author

p1gp1g commented Sep 7, 2022

Should we disable Instantiatable Lint check for vector-app module to fix the workflows ?

diff --git a/vector-app/build.gradle b/vector-app/build.gradle
index a8262fde40..c89fba3440 100644
--- a/vector-app/build.gradle
+++ b/vector-app/build.gradle
@@ -317,7 +317,7 @@ android {

     lintOptions {
         lintConfig file("../tools/lint/lint.xml")
-
+        disable "Instantiatable"
         checkDependencies true
         abortOnError true
     }

@DoM1niC
Copy link

DoM1niC commented Sep 7, 2022

THX for your work :) I will test your changes like your Camera PR, what works amazing here !

Use VectorMessagingHelper to directly call onMessage
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really see why avoiding using android-embedded_fcm_distributor will help to fix the issue with Push arriving to the app but not handled. Can you explain please?
Thanks

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Sep 8, 2022

Now FCM totally bypass UnifiedPush. There were some error with the gateway too. Also, it now always ensure FCM is retrieved (done with a merge of #6936 to add simplicity)

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Sep 8, 2022

I do not really see why avoiding using android-embedded_fcm_distributor will help to fix the issue with Push arriving to the app but not handled. Can you explain please? Thanks

Now, as soon as FirebaseReceiver.onMessageReceived is called, vectorMessagingHelper.onMessage will handle that message like it did before unifiedpush was merged

@bmarty
Copy link
Member

bmarty commented Sep 8, 2022

I am testing the code and it's working fine so far. I will wait to see if I got some issue after a while.

I have found a bug, this is maybe not new, but if I select NTFY several times, I can see several token on the NTFY app. I think some unregistration is missing.

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Sep 8, 2022

I am testing the code and it's working fine so far. I will wait to see if I got some issue after a while.

Good news, I hope no issue will pop :)

I have found a bug, this is maybe not new, but if I select NTFY several times, I can see several token on the NTFY app. I think some unregistration is missing.

I'll check that, I think it is better to handle this in another PR later

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks. The code readability could be improved by doing some renaming.
Still testing it on my side. Thanks!

import javax.inject.Inject

@AndroidEntryPoint
class FirebaseReceiver : FirebaseMessagingService() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to VectorFirebaseMessagingService.

private val loggerTag = LoggerTag("Push", LoggerTag.SYNC)

/**
* Hilt injection happen at super.onReceive().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has to be updated.

* Hilt injection happen at super.onReceive().
*/

class VectorMessagingHelper @Inject constructor(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class will take care of Push received by one of our Push receivers. Maybe rename to VectorPushHandler?

*
* @param message the message
*/
fun onMessage(message: String) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be defined in an interface with this single method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to handle the injections with the interface.

}

val pushData = pushParser.parseData(message, unifiedPushHelper.isEmbeddedDistributor())
?: return Unit.also { Timber.tag(loggerTag.value).w("Invalid received data Json format") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the parsing of the data to the Push receiver, since the model is different depending on the Push solution. So the the parsing can take place in FirebaseReceiver and VectorMessagingReceiver. So onMessage argument can be of type PushData, and the fun onMessage could be rename to handle

@@ -57,27 +39,16 @@ private val loggerTag = LoggerTag("Push", LoggerTag.SYNC)
*/
@AndroidEntryPoint
class VectorMessagingReceiver : MessagingReceiver() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for code clarity rename to VectorUnifiedPushMessagingReceiver

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
My test is still running, I have in parallel the nightly build and the build from this PR, using the same big account, and for now I get Push working on both app.
For the DI of VectorPushHandler I can handle it later.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update with Logs.

After a night, I can see that the nightly build are not receiving push (or they have no effect), and the version from this PR is still receiving it, notification are showing up.

I am going to merge the PR for the coming release.

@bmarty
Copy link
Member

bmarty commented Sep 9, 2022

(I will merge on a branch I own to do some cleanup)

@bmarty bmarty changed the base branch from develop to feature/bma/fix_push September 9, 2022 07:45
@bmarty bmarty merged commit f88039b into element-hq:feature/bma/fix_push Sep 9, 2022
@bmarty bmarty mentioned this pull request Sep 9, 2022
@bahur142
Copy link

I have found a bug, this is maybe not new, but if I select NTFY several times, I can see several token on the NTFY app. I think some unregistration is missing.

I'll check that, I think it is better to handle this in another PR later

Just made a symbolic donation on liberapay for your work on unified push :)

@p1gp1g p1gp1g mentioned this pull request Sep 12, 2022
15 tasks
bmarty added a commit that referenced this pull request Sep 19, 2022
We do not use `android-embedded_fcm_distributor` anymore (since #7068).
The code was compiling this `android-embedded_fcm_distributor` has a dependency on `firebase-messaging`.
bmarty added a commit that referenced this pull request Sep 19, 2022
We do not use `android-embedded_fcm_distributor` anymore (since #7068).
The code was compiling because `android-embedded_fcm_distributor` has a dependency on `firebase-messaging`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants