Update pusher with FCM new token only if using FCM

This commit is contained in:
sim 2022-09-08 11:46:34 +02:00
parent 48498020a0
commit f65074b3c5
2 changed files with 15 additions and 3 deletions

View file

@ -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))
}
}

View file

@ -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? {