From 1e58767374502cd721b7fd3f0e3b8fe15131fd57 Mon Sep 17 00:00:00 2001 From: Dominic Fischer Date: Mon, 29 Mar 2021 20:02:03 +0100 Subject: [PATCH] Missing file Signed-off-by: Dominic Fischer --- .../troubleshoot/TestPushFromPushGateway.kt | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt index da93d54075..6cf7d68561 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt @@ -24,9 +24,8 @@ import im.vector.app.core.pushers.PushersManager import im.vector.app.core.resources.StringProvider import im.vector.app.features.settings.troubleshoot.TroubleshootTest import im.vector.app.push.fcm.FcmHelper -import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.session.pushers.PushGatewayFailure -import org.matrix.android.sdk.api.util.Cancelable +import kotlinx.coroutines.* import javax.inject.Inject /** @@ -38,29 +37,31 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat private val pushersManager: PushersManager) : TroubleshootTest(R.string.settings_troubleshoot_test_push_loop_title) { - private var action: Cancelable? = null + private var action: Job? = null override fun perform(activityResultLauncher: ActivityResultLauncher) { val fcmToken = FcmHelper.getFcmToken(context) ?: run { status = TestStatus.FAILED return } - action = pushersManager.testPush(fcmToken, object : MatrixCallback { - override fun onFailure(failure: Throwable) { - description = if (failure is PushGatewayFailure.PusherRejected) { - stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed) - } else { - errorFormatter.toHumanReadable(failure) - } - status = TestStatus.FAILED - } - - override fun onSuccess(data: Unit) { - // Wait for the push to be received - description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push) - status = TestStatus.RUNNING - } - }) + action = GlobalScope.launch { + runCatching { pushersManager.testPush(fcmToken) } + .fold( + { + // Wait for the push to be received + description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push) + status = TestStatus.RUNNING + }, + { + description = if (failure is PushGatewayFailure.PusherRejected) { + stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed) + } else { + errorFormatter.toHumanReadable(it) + } + status = TestStatus.FAILED + } + ) + } } override fun onPushReceived() { @@ -69,6 +70,6 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat } override fun cancel() { - action?.cancel() + job?.cancel() } }