mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Use foldToCallback() whenever it's possible
This commit is contained in:
parent
b682f3e982
commit
38b1d24953
3 changed files with 12 additions and 17 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 + ")"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue