Fix compilation issue after rebase

This commit is contained in:
Benoit Marty 2019-06-17 16:28:27 +02:00
parent 1547045165
commit 9649e190ef

View file

@ -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.di.MoshiProvider
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.CountDownLatch
internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> { internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
data class Params( data class Params(
@ -50,9 +53,10 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi,
// Replay the request with passing the credentials // Replay the request with passing the credentials
// Parse to get a RegistrationFlowResponse // Parse to get a RegistrationFlowResponse
val registrationFlowResponseAdapter = MoshiProvider.providesMoshi().adapter(RegistrationFlowResponse::class.java)
val registrationFlowResponse = try { val registrationFlowResponse = try {
registrationFlowResponseAdapter.fromJson(throwable.errorBody) MoshiProvider.providesMoshi()
.adapter(RegistrationFlowResponse::class.java)
.fromJson(throwable.errorBody)
} catch (e: Exception) { } catch (e: Exception) {
null null
} }
@ -68,7 +72,16 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi,
Timber.v("## deleteDevice() : supported stages $stages") Timber.v("## deleteDevice() : supported stages $stages")
deleteDeviceRecursive(registrationFlowResponse.session, params, stages) val latch = CountDownLatch(1)
var deleteDeviceRecursiveResult: Try<Unit> = Try.just(Unit)
GlobalScope.launch {
deleteDeviceRecursiveResult = deleteDeviceRecursive(registrationFlowResponse.session, params, stages)
latch.countDown()
}
latch.await()
deleteDeviceRecursiveResult
} else { } else {
throwable.failure() throwable.failure()
} }
@ -80,9 +93,9 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi,
} }
} }
private fun deleteDeviceRecursive(authSession: String?, private suspend fun deleteDeviceRecursive(authSession: String?,
params: DeleteDeviceTask.Params, params: DeleteDeviceTask.Params,
remainingStages: MutableList<String>): Try<Unit> { remainingStages: MutableList<String>): Try<Unit> {
// Pick the first stage // Pick the first stage
val stage = remainingStages.first() val stage = remainingStages.first()
@ -107,7 +120,16 @@ internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi,
// Try next stage // Try next stage
val otherStages = remainingStages.subList(1, remainingStages.size) val otherStages = remainingStages.subList(1, remainingStages.size)
deleteDeviceRecursive(authSession, params, otherStages) val latch = CountDownLatch(1)
var deleteDeviceRecursiveResult: Try<Unit> = Try.just(Unit)
GlobalScope.launch {
deleteDeviceRecursiveResult = deleteDeviceRecursive(authSession, params, otherStages)
latch.countDown()
}
latch.await()
deleteDeviceRecursiveResult
} else { } else {
// No more stage remaining // No more stage remaining
throwable.failure() throwable.failure()