Remove dependency on AppNavigationStateService from DefaultGetCurrentPushProvider

This commit is contained in:
Benoit Marty 2025-10-23 15:03:04 +02:00
parent 2acc6db70f
commit 705b1b08f2
15 changed files with 66 additions and 70 deletions

View file

@ -9,23 +9,15 @@ package io.element.android.libraries.push.impl
import dev.zacsweers.metro.AppScope
import dev.zacsweers.metro.ContributesBinding
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.push.api.GetCurrentPushProvider
import io.element.android.libraries.pushstore.api.UserPushStoreFactory
import io.element.android.services.appnavstate.api.AppNavigationStateService
import io.element.android.services.appnavstate.api.currentSessionId
@ContributesBinding(AppScope::class)
class DefaultGetCurrentPushProvider(
private val pushStoreFactory: UserPushStoreFactory,
private val appNavigationStateService: AppNavigationStateService,
) : GetCurrentPushProvider {
override suspend fun getCurrentPushProvider(): String? {
return appNavigationStateService
.appNavigationState
.value
.navigationState
.currentSessionId()
?.let { pushStoreFactory.getOrCreate(it) }
?.getPushProviderName()
override suspend fun getCurrentPushProvider(sessionId: SessionId): String? {
return pushStoreFactory.getOrCreate(sessionId).getPushProviderName()
}
}

View file

@ -44,8 +44,8 @@ class DefaultPushService(
observeSessions()
}
override suspend fun getCurrentPushProvider(): PushProvider? {
val currentPushProvider = getCurrentPushProvider.getCurrentPushProvider()
override suspend fun getCurrentPushProvider(sessionId: SessionId): PushProvider? {
val currentPushProvider = getCurrentPushProvider.getCurrentPushProvider(sessionId)
return pushProviders.find { it.name == currentPushProvider }
}
@ -97,8 +97,8 @@ class DefaultPushService(
userPushStoreFactory.getOrCreate(sessionId).setIgnoreRegistrationError(ignore)
}
override suspend fun testPush(): Boolean {
val pushProvider = getCurrentPushProvider() ?: return false
override suspend fun testPush(sessionId: SessionId): Boolean {
val pushProvider = getCurrentPushProvider(sessionId) ?: return false
val config = pushProvider.getCurrentUserPushConfig() ?: return false
testPush.execute(config)
return true

View file

@ -37,7 +37,7 @@ class CurrentPushProviderTest(
override suspend fun run(coroutineScope: CoroutineScope) {
delegate.start()
val pushProvider = pushService.getCurrentPushProvider()
val pushProvider = pushService.getCurrentPushProvider(sessionId)
if (pushProvider == null) {
delegate.updateState(
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_failure),

View file

@ -7,9 +7,10 @@
package io.element.android.libraries.push.impl.troubleshoot
import dev.zacsweers.metro.AppScope
import dev.zacsweers.metro.ContributesIntoSet
import dev.zacsweers.metro.Inject
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.push.api.PushService
import io.element.android.libraries.push.api.gateway.PushGatewayFailure
import io.element.android.libraries.push.impl.R
@ -28,9 +29,10 @@ import kotlinx.coroutines.withTimeout
import timber.log.Timber
import kotlin.time.Duration.Companion.seconds
@ContributesIntoSet(AppScope::class)
@ContributesIntoSet(SessionScope::class)
@Inject
class PushLoopbackTest(
private val sessionId: SessionId,
private val pushService: PushService,
private val diagnosticPushHandler: DiagnosticPushHandler,
private val clock: SystemClock,
@ -52,9 +54,9 @@ class PushLoopbackTest(
completable.complete(clock.epochMillis() - startTime)
}
val testPushResult = try {
pushService.testPush()
pushService.testPush(sessionId)
} catch (pusherRejected: PushGatewayFailure.PusherRejected) {
val hasQuickFix = pushService.getCurrentPushProvider()?.canRotateToken() == true
val hasQuickFix = pushService.getCurrentPushProvider(sessionId)?.canRotateToken() == true
delegate.updateState(
description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_1),
status = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = hasQuickFix)
@ -105,7 +107,7 @@ class PushLoopbackTest(
navigator: NotificationTroubleshootNavigator,
) {
delegate.start()
pushService.getCurrentPushProvider()?.rotateToken()
pushService.getCurrentPushProvider(sessionId)?.rotateToken()
run(coroutineScope)
}