From 86eceb3cbc5f28fdfc95d9a91e76a75215ec7ed0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 22 May 2024 09:25:57 +0200 Subject: [PATCH] UnifiedPushGatewayResolver.getGateway cannot return null. --- .../unifiedpush/UnifiedPushGatewayResolver.kt | 2 +- .../VectorUnifiedPushMessagingReceiver.kt | 34 +++++++------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt index 74ae4cd5aa..1077bf970e 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt @@ -26,7 +26,7 @@ class UnifiedPushGatewayResolver @Inject constructor( private val unifiedPushApiFactory: UnifiedPushApiFactory, private val coroutineDispatchers: CoroutineDispatchers, ) { - suspend fun getGateway(endpoint: String): String? { + suspend fun getGateway(endpoint: String): String { val gateway = UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL try { val url = URL(endpoint) 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 c47aabae37..8aa41bc250 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 @@ -76,29 +76,19 @@ class VectorUnifiedPushMessagingReceiver : MessagingReceiver() { coroutineScope.launch { val gateway = unifiedPushGatewayResolver.getGateway(endpoint) unifiedPushStore.storePushGateway(gateway, instance) - if (gateway == null) { - Timber.tag(loggerTag.value).w("No gateway found for endpoint $endpoint") - endpointRegistrationHandler.registrationDone( - RegistrationResult( - clientSecret = instance, - result = Result.failure(IllegalStateException("No gateway found for endpoint $endpoint")), - ) + val result = newGatewayHandler.handle(endpoint, gateway, instance) + .onFailure { + Timber.tag(loggerTag.value).e(it, "Failed to handle new gateway") + } + .onSuccess { + unifiedPushStore.storeUpEndpoint(endpoint, instance) + } + endpointRegistrationHandler.registrationDone( + RegistrationResult( + clientSecret = instance, + result = result, ) - } else { - val result = newGatewayHandler.handle(endpoint, gateway, instance) - .onFailure { - Timber.tag(loggerTag.value).e(it, "Failed to handle new gateway") - } - .onSuccess { - unifiedPushStore.storeUpEndpoint(endpoint, instance) - } - endpointRegistrationHandler.registrationDone( - RegistrationResult( - clientSecret = instance, - result = result, - ) - ) - } + ) } guardServiceStarter.stop() }