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
|
|
@ -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