From 9649e190efcba57195b70ca19316cf31664f4ea4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Jun 2019 16:28:27 +0200 Subject: [PATCH] Fix compilation issue after rebase --- .../internal/crypto/tasks/DeleteDeviceTask.kt | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt index 2b7649fdd4..2222c470cc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt @@ -29,7 +29,10 @@ import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import timber.log.Timber +import java.util.concurrent.CountDownLatch internal interface DeleteDeviceTask : Task { data class Params( @@ -50,9 +53,10 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi, // Replay the request with passing the credentials // Parse to get a RegistrationFlowResponse - val registrationFlowResponseAdapter = MoshiProvider.providesMoshi().adapter(RegistrationFlowResponse::class.java) val registrationFlowResponse = try { - registrationFlowResponseAdapter.fromJson(throwable.errorBody) + MoshiProvider.providesMoshi() + .adapter(RegistrationFlowResponse::class.java) + .fromJson(throwable.errorBody) } catch (e: Exception) { null } @@ -68,7 +72,16 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi, Timber.v("## deleteDevice() : supported stages $stages") - deleteDeviceRecursive(registrationFlowResponse.session, params, stages) + val latch = CountDownLatch(1) + var deleteDeviceRecursiveResult: Try = Try.just(Unit) + + GlobalScope.launch { + deleteDeviceRecursiveResult = deleteDeviceRecursive(registrationFlowResponse.session, params, stages) + latch.countDown() + } + + latch.await() + deleteDeviceRecursiveResult } else { throwable.failure() } @@ -80,9 +93,9 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi, } } - private fun deleteDeviceRecursive(authSession: String?, - params: DeleteDeviceTask.Params, - remainingStages: MutableList): Try { + private suspend fun deleteDeviceRecursive(authSession: String?, + params: DeleteDeviceTask.Params, + remainingStages: MutableList): Try { // Pick the first stage val stage = remainingStages.first() @@ -107,7 +120,16 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi, // Try next stage val otherStages = remainingStages.subList(1, remainingStages.size) - deleteDeviceRecursive(authSession, params, otherStages) + val latch = CountDownLatch(1) + var deleteDeviceRecursiveResult: Try = Try.just(Unit) + + GlobalScope.launch { + deleteDeviceRecursiveResult = deleteDeviceRecursive(authSession, params, otherStages) + latch.countDown() + } + + latch.await() + deleteDeviceRecursiveResult } else { // No more stage remaining throwable.failure()