mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Show a more appropriate error when user enter a wrong backup passphrase
This commit is contained in:
parent
8c5ec2c57f
commit
6131c10d31
@ -44,11 +44,11 @@ class BackupToQuadSMigrationTask @Inject constructor(
|
||||
|
||||
sealed class Result {
|
||||
object Success : Result()
|
||||
abstract class Failure(val error: String?) : Result()
|
||||
abstract class Failure(val throwable: Throwable?) : Result()
|
||||
object InvalidRecoverySecret : Failure(null)
|
||||
object NoKeyBackupVersion : Failure(null)
|
||||
object IllegalParams : Failure(null)
|
||||
class ErrorFailure(throwable: Throwable) : Failure(throwable.localizedMessage)
|
||||
class ErrorFailure(throwable: Throwable) : Failure(throwable)
|
||||
}
|
||||
|
||||
data class Params(
|
||||
|
@ -35,6 +35,7 @@ import im.vector.matrix.android.internal.crypto.keysbackup.util.extractCurveKeyF
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth
|
||||
import im.vector.matrix.android.internal.util.awaitCallback
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.error.ErrorFormatter
|
||||
import im.vector.riotx.core.extensions.exhaustive
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.core.platform.WaitingViewData
|
||||
@ -48,6 +49,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: BootstrapViewState,
|
||||
@Assisted val args: BootstrapBottomSheet.Args,
|
||||
private val stringProvider: StringProvider,
|
||||
private val errorFormatter: ErrorFormatter,
|
||||
private val session: Session,
|
||||
private val bootstrapTask: BootstrapCrossSigningTask,
|
||||
private val migrationTask: BackupToQuadSMigrationTask,
|
||||
@ -301,7 +303,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun startMigrationFlow(prevState: BootstrapStep, passphrase: String?, recoveryKey: String?) {
|
||||
private fun startMigrationFlow(previousStep: BootstrapStep, passphrase: String?, recoveryKey: String?) {//TODO Rename param
|
||||
setState {
|
||||
copy(step = BootstrapStep.Initializing)
|
||||
}
|
||||
@ -316,38 +318,37 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
migrationTask.invoke(this, BackupToQuadSMigrationTask.Params(passphrase, recoveryKey, progressListener)) {
|
||||
if (it is BackupToQuadSMigrationTask.Result.Success) {
|
||||
setState {
|
||||
copy(
|
||||
passphrase = passphrase,
|
||||
passphraseRepeat = passphrase,
|
||||
migrationRecoveryKey = recoveryKey
|
||||
)
|
||||
}
|
||||
val userPassword = reAuthHelper.data
|
||||
if (userPassword == null) {
|
||||
when (it) {
|
||||
is BackupToQuadSMigrationTask.Result.Success -> {
|
||||
setState {
|
||||
copy(
|
||||
step = BootstrapStep.AccountPassword(false)
|
||||
passphrase = passphrase,
|
||||
passphraseRepeat = passphrase,
|
||||
migrationRecoveryKey = recoveryKey
|
||||
)
|
||||
}
|
||||
} else {
|
||||
startInitializeFlow(userPassword)
|
||||
val userPassword = reAuthHelper.data
|
||||
if (userPassword == null) {
|
||||
setState {
|
||||
copy(
|
||||
step = BootstrapStep.AccountPassword(false)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
startInitializeFlow(userPassword)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_viewEvents.post(
|
||||
BootstrapViewEvents.ModalError(
|
||||
(it as? BackupToQuadSMigrationTask.Result.Failure)?.error
|
||||
?: stringProvider.getString(R.string.matrix_error
|
||||
)
|
||||
)
|
||||
)
|
||||
setState {
|
||||
copy(
|
||||
step = prevState
|
||||
is BackupToQuadSMigrationTask.Result.Failure -> {
|
||||
_viewEvents.post(
|
||||
BootstrapViewEvents.ModalError(it.toHumanReadable())
|
||||
)
|
||||
setState {
|
||||
copy(
|
||||
step = previousStep
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.exhaustive
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -519,6 +520,16 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
private fun BackupToQuadSMigrationTask.Result.Failure.toHumanReadable(): String {
|
||||
return when (this) {
|
||||
is BackupToQuadSMigrationTask.Result.InvalidRecoverySecret -> stringProvider.getString(R.string.keys_backup_passphrase_error_decrypt)
|
||||
is BackupToQuadSMigrationTask.Result.ErrorFailure -> errorFormatter.toHumanReadable(throwable)
|
||||
// is BackupToQuadSMigrationTask.Result.NoKeyBackupVersion,
|
||||
// is BackupToQuadSMigrationTask.Result.IllegalParams,
|
||||
else -> stringProvider.getString(R.string.unexpected_error)
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// Companion, view model assisted creation
|
||||
// ======================================
|
||||
|
Loading…
Reference in New Issue
Block a user