diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt index d2474f3750..1552083517 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt @@ -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) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt index 6c46a5b9cc..2b80ea41e5 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt @@ -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 + ")" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt index 986fe81bee..263c381d33 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt @@ -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) }