mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 10:32:34 +00:00
Allow custom push gateway to use non-default port (#374)
This commit is contained in:
+6
-4
@@ -31,17 +31,19 @@ class UnifiedPushGatewayResolver @Inject constructor(
|
|||||||
suspend fun getGateway(endpoint: String): String? {
|
suspend fun getGateway(endpoint: String): String? {
|
||||||
val gateway = UnifiedPushConfig.default_push_gateway_http_url
|
val gateway = UnifiedPushConfig.default_push_gateway_http_url
|
||||||
val url = URL(endpoint)
|
val url = URL(endpoint)
|
||||||
val custom = "${url.protocol}://${url.host}/_matrix/push/v1/notify"
|
val port = if (url.port != -1) { ":${url.port}" } else { "" }
|
||||||
Timber.i("Testing $custom")
|
val customBase = "${url.protocol}://${url.host}${port}"
|
||||||
|
val customUrl = "$customBase/_matrix/push/v1/notify"
|
||||||
|
Timber.i("Testing $customUrl")
|
||||||
try {
|
try {
|
||||||
return withContext(coroutineDispatchers.io) {
|
return withContext(coroutineDispatchers.io) {
|
||||||
val api = retrofitFactory.create("${url.protocol}://${url.host}")
|
val api = retrofitFactory.create(customBase)
|
||||||
.create(UnifiedPushApi::class.java)
|
.create(UnifiedPushApi::class.java)
|
||||||
try {
|
try {
|
||||||
val discoveryResponse = api.discover()
|
val discoveryResponse = api.discover()
|
||||||
if (discoveryResponse.unifiedpush.gateway == "matrix") {
|
if (discoveryResponse.unifiedpush.gateway == "matrix") {
|
||||||
Timber.d("Using custom gateway")
|
Timber.d("Using custom gateway")
|
||||||
return@withContext custom
|
return@withContext customUrl
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
Timber.tag("UnifiedPushHelper").e(throwable)
|
Timber.tag("UnifiedPushHelper").e(throwable)
|
||||||
|
|||||||
Reference in New Issue
Block a user