Improve current push provider test: give info about the distributor.

This commit is contained in:
Benoit Marty 2025-01-02 10:56:57 +01:00
parent 9714abe032
commit 7ce4b47203
6 changed files with 165 additions and 15 deletions

View file

@ -7,10 +7,11 @@
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.push.api.GetCurrentPushProvider
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.impl.R
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate
@ -19,10 +20,11 @@ import io.element.android.services.toolbox.api.strings.StringProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
@ContributesIntoSet(AppScope::class)
@ContributesIntoSet(SessionScope::class)
@Inject
class CurrentPushProviderTest(
private val getCurrentPushProvider: GetCurrentPushProvider,
private val pushService: PushService,
private val sessionId: SessionId,
private val stringProvider: StringProvider,
) : NotificationTroubleshootTest {
override val order = 110
@ -35,17 +37,55 @@ class CurrentPushProviderTest(
override suspend fun run(coroutineScope: CoroutineScope) {
delegate.start()
val provider = getCurrentPushProvider.getCurrentPushProvider()
if (provider != null) {
delegate.updateState(
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_success, provider),
status = NotificationTroubleshootTestState.Status.Success
)
} else {
val pushProvider = pushService.getCurrentPushProvider()
if (pushProvider == null) {
delegate.updateState(
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_failure),
status = NotificationTroubleshootTestState.Status.Failure()
)
} else if (pushProvider.supportMultipleDistributors.not()) {
delegate.updateState(
description = stringProvider.getString(
R.string.troubleshoot_notifications_test_current_push_provider_success,
pushProvider.name
),
status = NotificationTroubleshootTestState.Status.Success
)
} else {
val distributorValue = pushProvider.getCurrentDistributorValue(sessionId)
if (distributorValue == null) {
// No distributors configured
delegate.updateState(
description = stringProvider.getString(
R.string.troubleshoot_notifications_test_current_push_provider_failure_no_distributor,
pushProvider.name
),
status = NotificationTroubleshootTestState.Status.Failure(false)
)
} else {
val distributor = pushProvider.getDistributors().find { it.value == distributorValue }
if (distributor == null) {
// Distributor has been uninstalled?
delegate.updateState(
description = stringProvider.getString(
R.string.troubleshoot_notifications_test_current_push_provider_failure_distributor_not_found,
pushProvider.name,
distributorValue,
distributorValue,
),
status = NotificationTroubleshootTestState.Status.Failure(false)
)
} else {
delegate.updateState(
description = stringProvider.getString(
R.string.troubleshoot_notifications_test_current_push_provider_success_with_distributor,
pushProvider.name,
distributorValue,
),
status = NotificationTroubleshootTestState.Status.Success
)
}
}
}
}