Give ability to configure the UnifiedPush default push gateway.

This commit is contained in:
Benoit Marty 2025-03-12 17:10:33 +01:00
parent cd48d051a8
commit b30e1095c9
8 changed files with 59 additions and 3 deletions

View file

@ -19,4 +19,5 @@ interface EnterpriseService {
fun semanticColorsDark(): SemanticColors fun semanticColorsDark(): SemanticColors
fun firebasePushGateway(): String? fun firebasePushGateway(): String?
fun unifiedPushDefaultPushGateway(): String?
} }

View file

@ -29,4 +29,5 @@ class DefaultEnterpriseService @Inject constructor() : EnterpriseService {
override fun semanticColorsDark(): SemanticColors = compoundColorsDark override fun semanticColorsDark(): SemanticColors = compoundColorsDark
override fun firebasePushGateway(): String? = null override fun firebasePushGateway(): String? = null
override fun unifiedPushDefaultPushGateway(): String? = null
} }

View file

@ -20,6 +20,7 @@ class FakeEnterpriseService(
private val semanticColorsLightResult: () -> SemanticColors = { lambdaError() }, private val semanticColorsLightResult: () -> SemanticColors = { lambdaError() },
private val semanticColorsDarkResult: () -> SemanticColors = { lambdaError() }, private val semanticColorsDarkResult: () -> SemanticColors = { lambdaError() },
private val firebasePushGatewayResult: () -> String? = { lambdaError() }, private val firebasePushGatewayResult: () -> String? = { lambdaError() },
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
) : EnterpriseService { ) : EnterpriseService {
override suspend fun isEnterpriseUser(sessionId: SessionId): Boolean = simulateLongTask { override suspend fun isEnterpriseUser(sessionId: SessionId): Boolean = simulateLongTask {
isEnterpriseUserResult(sessionId) isEnterpriseUserResult(sessionId)
@ -41,6 +42,10 @@ class FakeEnterpriseService(
return firebasePushGatewayResult() return firebasePushGatewayResult()
} }
override fun unifiedPushDefaultPushGateway(): String? {
return unifiedPushDefaultPushGatewayResult()
}
companion object { companion object {
const val A_FAKE_HOMESERVER = "a_fake_homeserver" const val A_FAKE_HOMESERVER = "a_fake_homeserver"
} }

View file

@ -19,6 +19,7 @@ setupAnvil()
dependencies { dependencies {
implementation(libs.dagger) implementation(libs.dagger)
implementation(projects.features.enterprise.api)
implementation(projects.libraries.androidutils) implementation(projects.libraries.androidutils)
implementation(projects.libraries.core) implementation(projects.libraries.core)
implementation(projects.libraries.matrix.api) implementation(projects.libraries.matrix.api)
@ -48,6 +49,7 @@ dependencies {
testImplementation(libs.test.robolectric) testImplementation(libs.test.robolectric)
testImplementation(libs.test.truth) testImplementation(libs.test.truth)
testImplementation(libs.test.turbine) testImplementation(libs.test.turbine)
testImplementation(projects.features.enterprise.test)
testImplementation(projects.libraries.matrix.test) testImplementation(projects.libraries.matrix.test)
testImplementation(projects.libraries.push.test) testImplementation(projects.libraries.push.test)
testImplementation(projects.libraries.pushproviders.test) testImplementation(projects.libraries.pushproviders.test)

View file

@ -0,0 +1,26 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.pushproviders.unifiedpush
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.enterprise.api.EnterpriseService
import io.element.android.libraries.di.AppScope
import javax.inject.Inject
interface DefaultPushGatewayHttpUrlProvider {
fun provide(): String
}
@ContributesBinding(AppScope::class)
class DefaultDefaultPushGatewayHttpUrlProvider @Inject constructor(
private val enterpriseService: EnterpriseService,
) : DefaultPushGatewayHttpUrlProvider {
override fun provide(): String {
return enterpriseService.unifiedPushDefaultPushGateway() ?: UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
}
}

View file

@ -21,6 +21,7 @@ interface UnifiedPushGatewayUrlResolver {
@ContributesBinding(AppScope::class) @ContributesBinding(AppScope::class)
class DefaultUnifiedPushGatewayUrlResolver @Inject constructor( class DefaultUnifiedPushGatewayUrlResolver @Inject constructor(
private val unifiedPushStore: UnifiedPushStore, private val unifiedPushStore: UnifiedPushStore,
private val defaultPushGatewayHttpUrlProvider: DefaultPushGatewayHttpUrlProvider,
) : UnifiedPushGatewayUrlResolver { ) : UnifiedPushGatewayUrlResolver {
override fun resolve( override fun resolve(
gatewayResult: UnifiedPushGatewayResolverResult, gatewayResult: UnifiedPushGatewayResolverResult,
@ -33,7 +34,7 @@ class DefaultUnifiedPushGatewayUrlResolver @Inject constructor(
} }
UnifiedPushGatewayResolverResult.ErrorInvalidUrl, UnifiedPushGatewayResolverResult.ErrorInvalidUrl,
UnifiedPushGatewayResolverResult.NoMatrixGateway -> { UnifiedPushGatewayResolverResult.NoMatrixGateway -> {
UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL defaultPushGatewayHttpUrlProvider.provide()
} }
is UnifiedPushGatewayResolverResult.Success -> { is UnifiedPushGatewayResolverResult.Success -> {
gatewayResult.gateway gatewayResult.gateway

View file

@ -18,7 +18,7 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
gatewayResult = UnifiedPushGatewayResolverResult.ErrorInvalidUrl, gatewayResult = UnifiedPushGatewayResolverResult.ErrorInvalidUrl,
instance = "", instance = "",
) )
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL) assertThat(result).isEqualTo(A_UNIFIED_PUSH_GATEWAY)
} }
@Test @Test
@ -28,7 +28,7 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
gatewayResult = UnifiedPushGatewayResolverResult.NoMatrixGateway, gatewayResult = UnifiedPushGatewayResolverResult.NoMatrixGateway,
instance = "", instance = "",
) )
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL) assertThat(result).isEqualTo(A_UNIFIED_PUSH_GATEWAY)
} }
@Test @Test
@ -77,7 +77,9 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
private fun createDefaultUnifiedPushGatewayUrlResolver( private fun createDefaultUnifiedPushGatewayUrlResolver(
unifiedPushStore: UnifiedPushStore = FakeUnifiedPushStore(), unifiedPushStore: UnifiedPushStore = FakeUnifiedPushStore(),
defaultPushGatewayHttpUrlProvider: DefaultPushGatewayHttpUrlProvider = FakeDefaultPushGatewayHttpUrlProvider(),
) = DefaultUnifiedPushGatewayUrlResolver( ) = DefaultUnifiedPushGatewayUrlResolver(
unifiedPushStore = unifiedPushStore, unifiedPushStore = unifiedPushStore,
defaultPushGatewayHttpUrlProvider = defaultPushGatewayHttpUrlProvider,
) )
} }

View file

@ -0,0 +1,18 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.pushproviders.unifiedpush
const val A_UNIFIED_PUSH_GATEWAY = "aGateway"
class FakeDefaultPushGatewayHttpUrlProvider(
private val provideResult: () -> String = { A_UNIFIED_PUSH_GATEWAY }
) : DefaultPushGatewayHttpUrlProvider {
override fun provide(): String {
return provideResult()
}
}