Missing file

Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
This commit is contained in:
Dominic Fischer 2021-03-29 20:02:03 +01:00
parent 7fbe485603
commit 1e58767374
1 changed files with 21 additions and 20 deletions

View File

@ -24,9 +24,8 @@ import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.settings.troubleshoot.TroubleshootTest import im.vector.app.features.settings.troubleshoot.TroubleshootTest
import im.vector.app.push.fcm.FcmHelper 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.session.pushers.PushGatewayFailure
import org.matrix.android.sdk.api.util.Cancelable import kotlinx.coroutines.*
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -38,29 +37,31 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat
private val pushersManager: PushersManager) private val pushersManager: PushersManager)
: TroubleshootTest(R.string.settings_troubleshoot_test_push_loop_title) { : TroubleshootTest(R.string.settings_troubleshoot_test_push_loop_title) {
private var action: Cancelable? = null private var action: Job? = null
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) { override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
val fcmToken = FcmHelper.getFcmToken(context) ?: run { val fcmToken = FcmHelper.getFcmToken(context) ?: run {
status = TestStatus.FAILED status = TestStatus.FAILED
return return
} }
action = pushersManager.testPush(fcmToken, object : MatrixCallback<Unit> { action = GlobalScope.launch {
override fun onFailure(failure: Throwable) { runCatching { pushersManager.testPush(fcmToken) }
description = if (failure is PushGatewayFailure.PusherRejected) { .fold(
stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed) {
} else { // Wait for the push to be received
errorFormatter.toHumanReadable(failure) description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push)
} status = TestStatus.RUNNING
status = TestStatus.FAILED },
} {
description = if (failure is PushGatewayFailure.PusherRejected) {
override fun onSuccess(data: Unit) { stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed)
// Wait for the push to be received } else {
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push) errorFormatter.toHumanReadable(it)
status = TestStatus.RUNNING }
} status = TestStatus.FAILED
}) }
)
}
} }
override fun onPushReceived() { override fun onPushReceived() {
@ -69,6 +70,6 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat
} }
override fun cancel() { override fun cancel() {
action?.cancel() job?.cancel()
} }
} }