Skip to content

Commit 5cab146

Browse files
committed
Give ability to configure the UnifiedPush default push gateway.
1 parent cf60f94 commit 5cab146

File tree

8 files changed

+59
-3
lines changed

8 files changed

+59
-3
lines changed

features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ interface EnterpriseService {
1919
fun semanticColorsDark(): SemanticColors
2020

2121
fun firebasePushGateway(): String?
22+
fun unifiedPushDefaultPushGateway(): String?
2223
}

features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ class DefaultEnterpriseService @Inject constructor() : EnterpriseService {
2929
override fun semanticColorsDark(): SemanticColors = compoundColorsDark
3030

3131
override fun firebasePushGateway(): String? = null
32+
override fun unifiedPushDefaultPushGateway(): String? = null
3233
}

features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class FakeEnterpriseService(
2020
private val semanticColorsLightResult: () -> SemanticColors = { lambdaError() },
2121
private val semanticColorsDarkResult: () -> SemanticColors = { lambdaError() },
2222
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
23+
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
2324
) : EnterpriseService {
2425
override suspend fun isEnterpriseUser(sessionId: SessionId): Boolean = simulateLongTask {
2526
isEnterpriseUserResult(sessionId)
@@ -41,6 +42,10 @@ class FakeEnterpriseService(
4142
return firebasePushGatewayResult()
4243
}
4344

45+
override fun unifiedPushDefaultPushGateway(): String? {
46+
return unifiedPushDefaultPushGatewayResult()
47+
}
48+
4449
companion object {
4550
const val A_FAKE_HOMESERVER = "a_fake_homeserver"
4651
}

libraries/pushproviders/unifiedpush/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ setupAnvil()
1919

2020
dependencies {
2121
implementation(libs.dagger)
22+
implementation(projects.features.enterprise.api)
2223
implementation(projects.libraries.androidutils)
2324
implementation(projects.libraries.core)
2425
implementation(projects.libraries.matrix.api)
@@ -48,6 +49,7 @@ dependencies {
4849
testImplementation(libs.test.robolectric)
4950
testImplementation(libs.test.truth)
5051
testImplementation(libs.test.turbine)
52+
testImplementation(projects.features.enterprise.test)
5153
testImplementation(projects.libraries.matrix.test)
5254
testImplementation(projects.libraries.push.test)
5355
testImplementation(projects.libraries.pushproviders.test)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
package io.element.android.libraries.pushproviders.unifiedpush
9+
10+
import com.squareup.anvil.annotations.ContributesBinding
11+
import io.element.android.features.enterprise.api.EnterpriseService
12+
import io.element.android.libraries.di.AppScope
13+
import javax.inject.Inject
14+
15+
interface DefaultPushGatewayHttpUrlProvider {
16+
fun provide(): String
17+
}
18+
19+
@ContributesBinding(AppScope::class)
20+
class DefaultDefaultPushGatewayHttpUrlProvider @Inject constructor(
21+
private val enterpriseService: EnterpriseService,
22+
) : DefaultPushGatewayHttpUrlProvider {
23+
override fun provide(): String {
24+
return enterpriseService.unifiedPushDefaultPushGateway() ?: UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
25+
}
26+
}

libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayUrlResolver.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface UnifiedPushGatewayUrlResolver {
2121
@ContributesBinding(AppScope::class)
2222
class DefaultUnifiedPushGatewayUrlResolver @Inject constructor(
2323
private val unifiedPushStore: UnifiedPushStore,
24+
private val defaultPushGatewayHttpUrlProvider: DefaultPushGatewayHttpUrlProvider,
2425
) : UnifiedPushGatewayUrlResolver {
2526
override fun resolve(
2627
gatewayResult: UnifiedPushGatewayResolverResult,
@@ -33,7 +34,7 @@ class DefaultUnifiedPushGatewayUrlResolver @Inject constructor(
3334
}
3435
UnifiedPushGatewayResolverResult.ErrorInvalidUrl,
3536
UnifiedPushGatewayResolverResult.NoMatrixGateway -> {
36-
UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
37+
defaultPushGatewayHttpUrlProvider.provide()
3738
}
3839
is UnifiedPushGatewayResolverResult.Success -> {
3940
gatewayResult.gateway

libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/DefaultUnifiedPushGatewayUrlResolverTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
1818
gatewayResult = UnifiedPushGatewayResolverResult.ErrorInvalidUrl,
1919
instance = "",
2020
)
21-
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL)
21+
assertThat(result).isEqualTo(A_UNIFIED_PUSH_GATEWAY)
2222
}
2323

2424
@Test
@@ -28,7 +28,7 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
2828
gatewayResult = UnifiedPushGatewayResolverResult.NoMatrixGateway,
2929
instance = "",
3030
)
31-
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL)
31+
assertThat(result).isEqualTo(A_UNIFIED_PUSH_GATEWAY)
3232
}
3333

3434
@Test
@@ -77,7 +77,9 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
7777

7878
private fun createDefaultUnifiedPushGatewayUrlResolver(
7979
unifiedPushStore: UnifiedPushStore = FakeUnifiedPushStore(),
80+
defaultPushGatewayHttpUrlProvider: DefaultPushGatewayHttpUrlProvider = FakeDefaultPushGatewayHttpUrlProvider(),
8081
) = DefaultUnifiedPushGatewayUrlResolver(
8182
unifiedPushStore = unifiedPushStore,
83+
defaultPushGatewayHttpUrlProvider = defaultPushGatewayHttpUrlProvider,
8284
)
8385
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
package io.element.android.libraries.pushproviders.unifiedpush
9+
10+
const val A_UNIFIED_PUSH_GATEWAY = "aGateway"
11+
12+
class FakeDefaultPushGatewayHttpUrlProvider(
13+
private val provideResult: () -> String = { A_UNIFIED_PUSH_GATEWAY }
14+
) : DefaultPushGatewayHttpUrlProvider {
15+
override fun provide(): String {
16+
return provideResult()
17+
}
18+
}

0 commit comments

Comments
 (0)