Use foldToCallback() whenever it's possible

This commit is contained in:
Benoit Marty 2019-06-14 10:39:10 +02:00
parent b682f3e982
commit 38b1d24953
3 changed files with 12 additions and 17 deletions

View file

@ -26,6 +26,7 @@ import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.auth.data.PasswordLoginParams
import im.vector.matrix.android.api.auth.data.SessionParams
import im.vector.matrix.android.internal.auth.data.ThreePidMedium
import im.vector.matrix.android.internal.extensions.foldToCallback
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.DefaultSession
import im.vector.matrix.android.internal.util.CancelableCoroutine
@ -57,7 +58,7 @@ internal class DefaultAuthenticator(private val retrofitBuilder: Retrofit.Builde
val job = GlobalScope.launch(coroutineDispatchers.main) {
val sessionOrFailure = authenticate(homeServerConnectionConfig, login, password)
sessionOrFailure.fold({ callback.onFailure(it) }, { callback.onSuccess(it) })
sessionOrFailure.foldToCallback(callback)
}
return CancelableCoroutine(job)

View file

@ -598,10 +598,7 @@ internal class CryptoManager(
val result = withContext(coroutineDispatchers.crypto) {
internalDecryptEvent(event, timeline)
}
result.fold(
{ callback.onFailure(it) },
{ callback.onSuccess(it) }
)
result.foldToCallback(callback)
}
}
@ -1060,10 +1057,7 @@ internal class CryptoManager(
CoroutineScope(coroutineDispatchers.crypto).launch {
deviceListManager
.downloadKeys(userIds, forceDownload)
.fold(
{ callback.onFailure(it) },
{ callback.onSuccess(it) }
)
.foldToCallback(callback)
}
}
@ -1073,9 +1067,9 @@ internal class CryptoManager(
.executeBy(taskExecutor)
}
/* ==========================================================================================
* DEBUG INFO
* ========================================================================================== */
/* ==========================================================================================
* DEBUG INFO
* ========================================================================================== */
override fun toString(): String {
return "CryptoManager of " + credentials.userId + " (" + credentials.deviceId + ")"

View file

@ -18,6 +18,8 @@ package im.vector.matrix.android.internal.task
import arrow.core.Try
import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.internal.extensions.foldToCallback
import im.vector.matrix.android.internal.extensions.onError
import im.vector.matrix.android.internal.util.CancelableCoroutine
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import kotlinx.coroutines.GlobalScope
@ -38,12 +40,10 @@ internal class TaskExecutor(private val coroutineDispatchers: MatrixCoroutineDis
task.execute(task.params)
}
}
resultOrFailure.fold({
resultOrFailure.onError {
Timber.d(it, "Task failed")
task.callback.onFailure(it)
}, {
task.callback.onSuccess(it)
})
}
.foldToCallback(task.callback)
}
return CancelableCoroutine(job)
}