mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Make the code a bit easier to understand (no other change)
This commit is contained in:
parent
fd94536118
commit
c76ced68e0
@ -51,7 +51,7 @@ class DeactivateAccountTest : InstrumentedTest {
|
||||
// Deactivate the account
|
||||
commonTestHelper.runBlockingTest {
|
||||
session.deactivateAccount(
|
||||
object : UserInteractiveAuthInterceptor {
|
||||
userInteractiveAuthInterceptor = object : UserInteractiveAuthInterceptor {
|
||||
override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation<UIABaseAuth>) {
|
||||
promise.resume(
|
||||
UserPasswordAuth(
|
||||
@ -61,7 +61,9 @@ class DeactivateAccountTest : InstrumentedTest {
|
||||
)
|
||||
)
|
||||
}
|
||||
}, false)
|
||||
},
|
||||
eraseAllData = false
|
||||
)
|
||||
}
|
||||
|
||||
// Try to login on the previous account, it will fail (M_USER_DEACTIVATED)
|
||||
|
@ -16,14 +16,25 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.auth.registration
|
||||
|
||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
|
||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import timber.log.Timber
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
internal suspend fun handleUIA(failure: Throwable, interceptor: UserInteractiveAuthInterceptor, retryBlock: suspend (UIABaseAuth) -> Unit): Boolean {
|
||||
/**
|
||||
* Handle a UIA challenge
|
||||
*
|
||||
* @param failure the failure to handle
|
||||
* @param interceptor see doc in [UserInteractiveAuthInterceptor]
|
||||
* @param retryBlock called at the end of the process, in this block generally retry executing the task, with
|
||||
* provided authUpdate
|
||||
* @return true if UIA is handled without error
|
||||
*/
|
||||
internal suspend fun handleUIA(failure: Throwable,
|
||||
interceptor: UserInteractiveAuthInterceptor,
|
||||
retryBlock: suspend (UIABaseAuth) -> Unit): Boolean {
|
||||
Timber.d("## UIA: check error ${failure.message}")
|
||||
val flowResponse = failure.toRegistrationFlowResponse()
|
||||
?: return false.also {
|
||||
@ -38,16 +49,16 @@ internal suspend fun handleUIA(failure: Throwable, interceptor: UserInteractiveA
|
||||
suspendCoroutine<UIABaseAuth> { continuation ->
|
||||
interceptor.performStage(flowResponse, (failure as? Failure.ServerError)?.error?.code, continuation)
|
||||
}
|
||||
} catch (failure: Throwable) {
|
||||
Timber.w(failure, "## UIA: failed to participate")
|
||||
} catch (failure2: Throwable) {
|
||||
Timber.w(failure2, "## UIA: failed to participate")
|
||||
return false
|
||||
}
|
||||
|
||||
Timber.d("## UIA: updated auth $authUpdate")
|
||||
Timber.d("## UIA: updated auth")
|
||||
return try {
|
||||
retryBlock(authUpdate)
|
||||
true
|
||||
} catch (failure: Throwable) {
|
||||
handleUIA(failure, interceptor, retryBlock)
|
||||
} catch (failure3: Throwable) {
|
||||
handleUIA(failure3, interceptor, retryBlock)
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +47,13 @@ internal class DefaultDeleteDeviceTask @Inject constructor(
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (params.userInteractiveAuthInterceptor == null
|
||||
|| !handleUIA(throwable, params.userInteractiveAuthInterceptor) { auth ->
|
||||
execute(params.copy(userAuthParam = auth))
|
||||
|| !handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable
|
||||
|
@ -126,9 +126,14 @@ internal class DefaultInitializeCrossSigningTask @Inject constructor(
|
||||
uploadSigningKeysTask.execute(uploadSigningKeysParams)
|
||||
} catch (failure: Throwable) {
|
||||
if (params.interactiveAuthInterceptor == null
|
||||
|| !handleUIA(failure, params.interactiveAuthInterceptor) { authUpdate ->
|
||||
|| !handleUIA(
|
||||
failure = failure,
|
||||
interceptor = params.interactiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
uploadSigningKeysTask.execute(uploadSigningKeysParams.copy(userAuthParam = authUpdate))
|
||||
}) {
|
||||
}
|
||||
)
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw failure
|
||||
}
|
||||
|
@ -16,10 +16,9 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.account
|
||||
|
||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.internal.auth.registration.handleUIA
|
||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.cleanup.CleanupSession
|
||||
@ -39,7 +38,6 @@ internal interface DeactivateAccountTask : Task<DeactivateAccountTask.Params, Un
|
||||
internal class DefaultDeactivateAccountTask @Inject constructor(
|
||||
private val accountAPI: AccountAPI,
|
||||
private val globalErrorReceiver: GlobalErrorReceiver,
|
||||
@UserId private val userId: String,
|
||||
private val identityDisconnectTask: IdentityDisconnectTask,
|
||||
private val cleanupSession: CleanupSession
|
||||
) : DeactivateAccountTask {
|
||||
@ -52,9 +50,13 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
|
||||
apiCall = accountAPI.deactivate(deactivateAccountParams)
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (!handleUIA(throwable, params.userInteractiveAuthInterceptor) { auth ->
|
||||
execute(params.copy(userAuthParam = auth))
|
||||
if (!handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable
|
||||
|
@ -71,9 +71,13 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (params.userInteractiveAuthInterceptor == null
|
||||
|| !handleUIA(throwable, params.userInteractiveAuthInterceptor) { auth ->
|
||||
execute(params.copy(userAuthParam = auth))
|
||||
|| !handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable.toRegistrationFlowResponse()
|
||||
|
Loading…
Reference in New Issue
Block a user