From d2d01c08dfb3d385dc05f87afc936f6b225c566f Mon Sep 17 00:00:00 2001 From: jonnyandrew Date: Tue, 2 May 2023 15:04:47 +0000 Subject: [PATCH] Allow custom push gateway to use non-default port (#374) --- .../unifiedpush/UnifiedPushGatewayResolver.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/push/providers/unifiedpush/UnifiedPushGatewayResolver.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/push/providers/unifiedpush/UnifiedPushGatewayResolver.kt index 9a1e1785a4..ff243ade21 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/push/providers/unifiedpush/UnifiedPushGatewayResolver.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/push/providers/unifiedpush/UnifiedPushGatewayResolver.kt @@ -31,17 +31,19 @@ class UnifiedPushGatewayResolver @Inject constructor( suspend fun getGateway(endpoint: String): String? { val gateway = UnifiedPushConfig.default_push_gateway_http_url val url = URL(endpoint) - val custom = "${url.protocol}://${url.host}/_matrix/push/v1/notify" - Timber.i("Testing $custom") + val port = if (url.port != -1) { ":${url.port}" } else { "" } + val customBase = "${url.protocol}://${url.host}${port}" + val customUrl = "$customBase/_matrix/push/v1/notify" + Timber.i("Testing $customUrl") try { return withContext(coroutineDispatchers.io) { - val api = retrofitFactory.create("${url.protocol}://${url.host}") + val api = retrofitFactory.create(customBase) .create(UnifiedPushApi::class.java) try { val discoveryResponse = api.discover() if (discoveryResponse.unifiedpush.gateway == "matrix") { Timber.d("Using custom gateway") - return@withContext custom + return@withContext customUrl } } catch (throwable: Throwable) { Timber.tag("UnifiedPushHelper").e(throwable)