From f65074b3c572d45fdeb6a3723672f9d7099bbf11 Mon Sep 17 00:00:00 2001 From: sim Date: Thu, 8 Sep 2022 11:46:34 +0200 Subject: [PATCH] Update pusher with FCM new token only if using FCM --- .../java/im/vector/app/push/fcm/FirebaseReceiver.kt | 8 +++++++- .../im/vector/app/core/pushers/UnifiedPushHelper.kt | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/vector/src/gplay/java/im/vector/app/push/fcm/FirebaseReceiver.kt b/vector/src/gplay/java/im/vector/app/push/fcm/FirebaseReceiver.kt index 92473caa1e..0b4d1f1f43 100644 --- a/vector/src/gplay/java/im/vector/app/push/fcm/FirebaseReceiver.kt +++ b/vector/src/gplay/java/im/vector/app/push/fcm/FirebaseReceiver.kt @@ -23,6 +23,7 @@ import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.pushers.PushersManager +import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.core.pushers.VectorMessagingHelper import im.vector.app.features.settings.VectorPreferences import org.json.JSONObject @@ -36,11 +37,16 @@ class FirebaseReceiver : FirebaseMessagingService() { @Inject lateinit var activeSessionHolder: ActiveSessionHolder @Inject lateinit var pushersManager: PushersManager @Inject lateinit var vectorMessagingHelper: VectorMessagingHelper + @Inject lateinit var unifiedPushHelper: UnifiedPushHelper override fun onNewToken(token: String) { Timber.d("New Firebase token") fcmHelper.storeFcmToken(token) - if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) { + if ( + vectorPreferences.areNotificationEnabledForDevice() && + activeSessionHolder.hasActiveSession() && + unifiedPushHelper.isEmbeddedDistributor() + ) { pushersManager.enqueueRegisterPusher(token, getString(R.string.pusher_http_url)) } } diff --git a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt index 99987ddb6c..b5ec8a0d15 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt @@ -240,11 +240,17 @@ class UnifiedPushHelper @Inject constructor( } fun isEmbeddedDistributor(): Boolean { - return UnifiedPush.getDistributor(context) == context.packageName && fcmHelper.isFirebaseAvailable() + return isInternalDistributor() && fcmHelper.isFirebaseAvailable() } fun isBackgroundSync(): Boolean { - return UnifiedPush.getDistributor(context) == context.packageName && !fcmHelper.isFirebaseAvailable() + return isInternalDistributor() && !fcmHelper.isFirebaseAvailable() + } + + private fun isInternalDistributor(): Boolean { + return UnifiedPush.getDistributor(context).isEmpty() || + UnifiedPush.getDistributor(context) == context.packageName + } fun getPrivacyFriendlyUpEndpoint(): String? {