Give ability to configure the UnifiedPush default push gateway.
This commit is contained in:
parent
cf60f943a8
commit
5cab146eed
8 changed files with 59 additions and 3 deletions
|
|
@ -19,4 +19,5 @@ interface EnterpriseService {
|
|||
fun semanticColorsDark(): SemanticColors
|
||||
|
||||
fun firebasePushGateway(): String?
|
||||
fun unifiedPushDefaultPushGateway(): String?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@ class DefaultEnterpriseService @Inject constructor() : EnterpriseService {
|
|||
override fun semanticColorsDark(): SemanticColors = compoundColorsDark
|
||||
|
||||
override fun firebasePushGateway(): String? = null
|
||||
override fun unifiedPushDefaultPushGateway(): String? = null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class FakeEnterpriseService(
|
|||
private val semanticColorsLightResult: () -> SemanticColors = { lambdaError() },
|
||||
private val semanticColorsDarkResult: () -> SemanticColors = { lambdaError() },
|
||||
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
||||
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
||||
) : EnterpriseService {
|
||||
override suspend fun isEnterpriseUser(sessionId: SessionId): Boolean = simulateLongTask {
|
||||
isEnterpriseUserResult(sessionId)
|
||||
|
|
@ -41,6 +42,10 @@ class FakeEnterpriseService(
|
|||
return firebasePushGatewayResult()
|
||||
}
|
||||
|
||||
override fun unifiedPushDefaultPushGateway(): String? {
|
||||
return unifiedPushDefaultPushGatewayResult()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val A_FAKE_HOMESERVER = "a_fake_homeserver"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ setupAnvil()
|
|||
|
||||
dependencies {
|
||||
implementation(libs.dagger)
|
||||
implementation(projects.features.enterprise.api)
|
||||
implementation(projects.libraries.androidutils)
|
||||
implementation(projects.libraries.core)
|
||||
implementation(projects.libraries.matrix.api)
|
||||
|
|
@ -48,6 +49,7 @@ dependencies {
|
|||
testImplementation(libs.test.robolectric)
|
||||
testImplementation(libs.test.truth)
|
||||
testImplementation(libs.test.turbine)
|
||||
testImplementation(projects.features.enterprise.test)
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
testImplementation(projects.libraries.push.test)
|
||||
testImplementation(projects.libraries.pushproviders.test)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ interface UnifiedPushGatewayUrlResolver {
|
|||
@ContributesBinding(AppScope::class)
|
||||
class DefaultUnifiedPushGatewayUrlResolver @Inject constructor(
|
||||
private val unifiedPushStore: UnifiedPushStore,
|
||||
private val defaultPushGatewayHttpUrlProvider: DefaultPushGatewayHttpUrlProvider,
|
||||
) : UnifiedPushGatewayUrlResolver {
|
||||
override fun resolve(
|
||||
gatewayResult: UnifiedPushGatewayResolverResult,
|
||||
|
|
@ -33,7 +34,7 @@ class DefaultUnifiedPushGatewayUrlResolver @Inject constructor(
|
|||
}
|
||||
UnifiedPushGatewayResolverResult.ErrorInvalidUrl,
|
||||
UnifiedPushGatewayResolverResult.NoMatrixGateway -> {
|
||||
UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
|
||||
defaultPushGatewayHttpUrlProvider.provide()
|
||||
}
|
||||
is UnifiedPushGatewayResolverResult.Success -> {
|
||||
gatewayResult.gateway
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
|
|||
gatewayResult = UnifiedPushGatewayResolverResult.ErrorInvalidUrl,
|
||||
instance = "",
|
||||
)
|
||||
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL)
|
||||
assertThat(result).isEqualTo(A_UNIFIED_PUSH_GATEWAY)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -28,7 +28,7 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
|
|||
gatewayResult = UnifiedPushGatewayResolverResult.NoMatrixGateway,
|
||||
instance = "",
|
||||
)
|
||||
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL)
|
||||
assertThat(result).isEqualTo(A_UNIFIED_PUSH_GATEWAY)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -77,7 +77,9 @@ class DefaultUnifiedPushGatewayUrlResolverTest {
|
|||
|
||||
private fun createDefaultUnifiedPushGatewayUrlResolver(
|
||||
unifiedPushStore: UnifiedPushStore = FakeUnifiedPushStore(),
|
||||
defaultPushGatewayHttpUrlProvider: DefaultPushGatewayHttpUrlProvider = FakeDefaultPushGatewayHttpUrlProvider(),
|
||||
) = DefaultUnifiedPushGatewayUrlResolver(
|
||||
unifiedPushStore = unifiedPushStore,
|
||||
defaultPushGatewayHttpUrlProvider = defaultPushGatewayHttpUrlProvider,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue