Also fix the problem of cleanup too early (or done several times in case of bad password) for DefaultFinalizeAddingThreePidTask

This commit is contained in:
Benoit Marty 2021-02-18 19:23:31 +01:00
parent 2271ddacf8
commit 544c1e4a6a

View file

@ -26,7 +26,6 @@ import org.matrix.android.sdk.api.auth.UIABaseAuth
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
import org.matrix.android.sdk.internal.di.SessionDatabase
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.task.Task
@ -47,11 +46,12 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
private val profileAPI: ProfileAPI,
@SessionDatabase private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper,
@UserId private val userId: String,
private val globalErrorReceiver: GlobalErrorReceiver) : FinalizeAddingThreePidTask() {
override suspend fun execute(params: Params) {
if (params.userWantsToCancel.not()) {
val canCleanup = if (params.userWantsToCancel) {
true
} else {
// Get the required pending data
val pendingThreePids = monarchy.fetchAllMappedSync(
{ it.where(PendingThreePidEntity::class.java) },
@ -69,6 +69,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
)
apiCall = profileAPI.finalizeAddThreePid(body)
}
true
} catch (throwable: Throwable) {
if (params.userInteractiveAuthInterceptor == null
|| !handleUIA(
@ -83,12 +84,16 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
throw throwable.toRegistrationFlowResponse()
?.let { Failure.RegistrationFlowError(it) }
?: throwable
} else {
false
}
}
}
if (canCleanup) {
cleanupDatabase(params)
}
}
private suspend fun cleanupDatabase(params: Params) {
// Delete the pending three pid