From 48498020a0c8b602058cf9028a957914c97ee828 Mon Sep 17 00:00:00 2001 From: sim Date: Thu, 8 Sep 2022 11:23:15 +0200 Subject: [PATCH] Ensure FCM always have the good gateway --- .../main/java/im/vector/app/core/pushers/PushersManager.kt | 3 +-- .../java/im/vector/app/core/pushers/UnifiedPushHelper.kt | 5 +++++ .../java/im/vector/app/core/pushers/UnifiedPushStore.kt | 4 +--- .../im/vector/app/core/pushers/VectorMessagingReceiver.kt | 2 +- .../settings/troubleshoot/TestUnifiedPushGateway.kt | 6 +++--- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt index 98412497fc..c77f454ab0 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt @@ -29,7 +29,6 @@ import kotlin.math.abs private const val DEFAULT_PUSHER_FILE_TAG = "mobile" class PushersManager @Inject constructor( - private val unifiedPushStore: UnifiedPushStore, private val unifiedPushHelper: UnifiedPushHelper, private val activeSessionHolder: ActiveSessionHolder, private val localeProvider: LocaleProvider, @@ -40,7 +39,7 @@ class PushersManager @Inject constructor( val currentSession = activeSessionHolder.getActiveSession() currentSession.pushersService().testPush( - unifiedPushStore.getPushGateway(), + unifiedPushHelper.getPushGateway() ?: return, stringProvider.getString(R.string.pusher_app_id), unifiedPushHelper.getEndpointOrToken().orEmpty(), TEST_EVENT_ID 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 bc8dc70668..99987ddb6c 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 @@ -266,4 +266,9 @@ class UnifiedPushHelper @Inject constructor( return if (isEmbeddedDistributor()) fcmHelper.getFcmToken() else unifiedPushStore.getEndpoint() } + + fun getPushGateway(): String? { + return if (isEmbeddedDistributor()) context.getString(R.string.pusher_http_url) + else unifiedPushStore.getPushGateway() + } } diff --git a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushStore.kt b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushStore.kt index 86247cd749..d9c6bf3159 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushStore.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushStore.kt @@ -18,7 +18,6 @@ package im.vector.app.core.pushers import android.content.Context import androidx.core.content.edit -import im.vector.app.R import im.vector.app.core.di.DefaultSharedPreferences import javax.inject.Inject @@ -53,9 +52,8 @@ class UnifiedPushStore @Inject constructor( * * @return the Push Gateway or null if not defined */ - fun getPushGateway(): String { + fun getPushGateway(): String? { return defaultPrefs.getString(PREFS_PUSH_GATEWAY, null) - ?: context.getString(R.string.pusher_http_url) } /** diff --git a/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt b/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt index 4ee317bce7..1aa9c3e891 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt @@ -69,7 +69,7 @@ class VectorMessagingReceiver : MessagingReceiver() { unifiedPushStore.storeUpEndpoint(endpoint) coroutineScope.launch { unifiedPushHelper.storeCustomOrDefaultGateway(endpoint) { - unifiedPushStore.getPushGateway().let { + unifiedPushHelper.getPushGateway()?.let { pushersManager.enqueueRegisterPusher(endpoint, it) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestUnifiedPushGateway.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestUnifiedPushGateway.kt index 38f14951b4..19a4fd188f 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestUnifiedPushGateway.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestUnifiedPushGateway.kt @@ -19,19 +19,19 @@ package im.vector.app.features.settings.troubleshoot import android.content.Intent import androidx.activity.result.ActivityResultLauncher import im.vector.app.R -import im.vector.app.core.pushers.UnifiedPushStore +import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.core.resources.StringProvider import javax.inject.Inject class TestUnifiedPushGateway @Inject constructor( - private val unifiedPushStore: UnifiedPushStore, + private val unifiedPushHelper: UnifiedPushHelper, private val stringProvider: StringProvider ) : TroubleshootTest(R.string.settings_troubleshoot_test_current_gateway_title) { override fun perform(activityResultLauncher: ActivityResultLauncher) { description = stringProvider.getString( R.string.settings_troubleshoot_test_current_gateway, - unifiedPushStore.getPushGateway() + unifiedPushHelper.getPushGateway() ) status = TestStatus.SUCCESS }