From dc572af9db727a133761eafee70265dc3217ed02 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 7 May 2024 11:23:13 +0200 Subject: [PATCH] Ensure UnifiedPush endpoint is registered. --- .../VectorUnifiedPushMessagingReceiver.kt | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/VectorUnifiedPushMessagingReceiver.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/VectorUnifiedPushMessagingReceiver.kt index c87d915fdb..e4b9624a1e 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/VectorUnifiedPushMessagingReceiver.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/VectorUnifiedPushMessagingReceiver.kt @@ -69,25 +69,19 @@ class VectorUnifiedPushMessagingReceiver : MessagingReceiver() { * You should send the endpoint to your application server and sync for missing notifications. */ override fun onNewEndpoint(context: Context, endpoint: String, instance: String) { - Timber.tag(loggerTag.value).i("onNewEndpoint: adding $endpoint") - // If the endpoint has changed - // or the gateway has changed - if (unifiedPushStore.getEndpoint(instance) != endpoint) { - coroutineScope.launch { - val gateway = unifiedPushGatewayResolver.getGateway(endpoint) - unifiedPushStore.storePushGateway(gateway, instance) - gateway?.let { pushGateway -> - newGatewayHandler.handle(endpoint, pushGateway, instance) - .onFailure { - Timber.tag(loggerTag.value).e("Failed to handle new gateway") - } - .onSuccess { - unifiedPushStore.storeUpEndpoint(endpoint, instance) - } - } + Timber.tag(loggerTag.value).i("onNewEndpoint: $endpoint") + coroutineScope.launch { + val gateway = unifiedPushGatewayResolver.getGateway(endpoint) + unifiedPushStore.storePushGateway(gateway, instance) + gateway?.let { pushGateway -> + newGatewayHandler.handle(endpoint, pushGateway, instance) + .onFailure { + Timber.tag(loggerTag.value).e(it, "Failed to handle new gateway") + } + .onSuccess { + unifiedPushStore.storeUpEndpoint(endpoint, instance) + } } - } else { - Timber.tag(loggerTag.value).i("onNewEndpoint: skipped") } guardServiceStarter.stop() }