Fix injection issue.
This commit is contained in:
parent
22f9e5515c
commit
3e74fa05d7
4 changed files with 82 additions and 5 deletions
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.pushproviders.unifiedpush
|
||||||
|
|
||||||
|
import com.squareup.anvil.annotations.ContributesBinding
|
||||||
|
import io.element.android.libraries.di.AppScope
|
||||||
|
import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig
|
||||||
|
import io.element.android.libraries.pushstore.api.clientsecret.PushClientSecret
|
||||||
|
import io.element.android.services.appnavstate.api.AppNavigationStateService
|
||||||
|
import io.element.android.services.appnavstate.api.currentSessionId
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
interface UnifiedPushCurrentUserPushConfigProvider {
|
||||||
|
suspend fun provide(): CurrentUserPushConfig?
|
||||||
|
}
|
||||||
|
|
||||||
|
@ContributesBinding(AppScope::class)
|
||||||
|
class DefaultUnifiedPushCurrentUserPushConfigProvider @Inject constructor(
|
||||||
|
private val pushClientSecret: PushClientSecret,
|
||||||
|
private val unifiedPushStore: UnifiedPushStore,
|
||||||
|
private val appNavigationStateService: AppNavigationStateService,
|
||||||
|
) : UnifiedPushCurrentUserPushConfigProvider {
|
||||||
|
override suspend fun provide(): CurrentUserPushConfig? {
|
||||||
|
val currentSession = appNavigationStateService.appNavigationState.value.navigationState.currentSessionId() ?: return null
|
||||||
|
val clientSecret = pushClientSecret.getSecretForUser(currentSession)
|
||||||
|
val url = unifiedPushStore.getPushGateway(clientSecret) ?: return null
|
||||||
|
val pushKey = unifiedPushStore.getEndpoint(clientSecret) ?: return null
|
||||||
|
return CurrentUserPushConfig(
|
||||||
|
url = url,
|
||||||
|
pushKey = pushKey,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,9 +19,9 @@ package io.element.android.libraries.pushproviders.unifiedpush.troubleshoot
|
||||||
import com.squareup.anvil.annotations.ContributesMultibinding
|
import com.squareup.anvil.annotations.ContributesMultibinding
|
||||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||||
import io.element.android.libraries.di.AppScope
|
import io.element.android.libraries.di.AppScope
|
||||||
import io.element.android.libraries.pushproviders.api.PushProvider
|
|
||||||
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushApiFactory
|
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushApiFactory
|
||||||
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig
|
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig
|
||||||
|
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushCurrentUserPushConfigProvider
|
||||||
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest
|
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest
|
||||||
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate
|
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate
|
||||||
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
|
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
|
||||||
|
|
@ -35,7 +35,7 @@ import javax.inject.Inject
|
||||||
class UnifiedPushMatrixGatewayTest @Inject constructor(
|
class UnifiedPushMatrixGatewayTest @Inject constructor(
|
||||||
private val unifiedPushApiFactory: UnifiedPushApiFactory,
|
private val unifiedPushApiFactory: UnifiedPushApiFactory,
|
||||||
private val coroutineDispatchers: CoroutineDispatchers,
|
private val coroutineDispatchers: CoroutineDispatchers,
|
||||||
private val pushProvider: PushProvider,
|
private val unifiedPushCurrentUserPushConfigProvider: UnifiedPushCurrentUserPushConfigProvider,
|
||||||
) : NotificationTroubleshootTest {
|
) : NotificationTroubleshootTest {
|
||||||
override val order = 450
|
override val order = 450
|
||||||
private val delegate = NotificationTroubleshootTestDelegate(
|
private val delegate = NotificationTroubleshootTestDelegate(
|
||||||
|
|
@ -52,7 +52,7 @@ class UnifiedPushMatrixGatewayTest @Inject constructor(
|
||||||
|
|
||||||
override suspend fun run(coroutineScope: CoroutineScope) {
|
override suspend fun run(coroutineScope: CoroutineScope) {
|
||||||
delegate.start()
|
delegate.start()
|
||||||
val config = pushProvider.getCurrentUserPushConfig()
|
val config = unifiedPushCurrentUserPushConfigProvider.provide()
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
delegate.updateState(
|
delegate.updateState(
|
||||||
description = "No current push provider",
|
description = "No current push provider",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.pushproviders.unifiedpush.troubleshoot
|
||||||
|
|
||||||
|
import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig
|
||||||
|
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushCurrentUserPushConfigProvider
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
|
|
||||||
|
class FakeUnifiedPushCurrentUserPushConfigProvider(
|
||||||
|
private val currentUserPushConfig: () -> CurrentUserPushConfig? = { lambdaError() },
|
||||||
|
) : UnifiedPushCurrentUserPushConfigProvider {
|
||||||
|
override suspend fun provide(): CurrentUserPushConfig? {
|
||||||
|
return currentUserPushConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,7 +19,6 @@ package io.element.android.libraries.pushproviders.unifiedpush.troubleshoot
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig
|
import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig
|
||||||
import io.element.android.libraries.pushproviders.test.FakePushProvider
|
|
||||||
import io.element.android.libraries.pushproviders.test.aCurrentUserPushConfig
|
import io.element.android.libraries.pushproviders.test.aCurrentUserPushConfig
|
||||||
import io.element.android.libraries.pushproviders.unifiedpush.FakeUnifiedPushApiFactory
|
import io.element.android.libraries.pushproviders.unifiedpush.FakeUnifiedPushApiFactory
|
||||||
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig
|
import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig
|
||||||
|
|
@ -120,7 +119,9 @@ class UnifiedPushMatrixGatewayTestTest {
|
||||||
return UnifiedPushMatrixGatewayTest(
|
return UnifiedPushMatrixGatewayTest(
|
||||||
unifiedPushApiFactory = FakeUnifiedPushApiFactory(discoveryResponse),
|
unifiedPushApiFactory = FakeUnifiedPushApiFactory(discoveryResponse),
|
||||||
coroutineDispatchers = testCoroutineDispatchers(),
|
coroutineDispatchers = testCoroutineDispatchers(),
|
||||||
pushProvider = FakePushProvider(currentUserPushConfig = currentUserPushConfig),
|
unifiedPushCurrentUserPushConfigProvider = FakeUnifiedPushCurrentUserPushConfigProvider(
|
||||||
|
currentUserPushConfig = { currentUserPushConfig }
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue