Fix username recovery UX bugs.

This commit is contained in:
Cody Henthorne 2024-02-21 14:06:34 -05:00 committed by Greyson Parrelli
parent 755fafb0b6
commit d5cf8d36b3
3 changed files with 9 additions and 5 deletions

View file

@ -120,8 +120,6 @@ class AppSettingsActivity : DSLSettingsActivity(), DonationPaymentComponent {
override fun onWillFinish() {
if (wasConfigurationUpdated) {
setResult(MainActivity.RESULT_CONFIG_CHANGED)
} else {
setResult(RESULT_OK)
}
}

View file

@ -141,7 +141,7 @@ public class UsernameEditFragment extends LoggingFragment {
}
private void promptOrSubmitUsername() {
if (args.getMode() == UsernameEditMode.RECOVERY) {
if (viewModel.isSameUsernameRecovery()) {
new MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.UsernameEditFragment_recovery_dialog_confirmation)
.setPositiveButton(android.R.string.ok, ((dialog, which) -> {

View file

@ -35,8 +35,6 @@ import java.util.concurrent.TimeUnit
* Usernames are made up of two discrete components, a nickname and a discriminator. They are formatted thusly:
*
* [nickname].[discriminator]
*
* The nickname is user-controlled, whereas the discriminator is controlled by the server.
*/
internal class UsernameEditViewModel private constructor(private val mode: UsernameEditMode) : ViewModel() {
private val events: PublishSubject<Event> = PublishSubject.create()
@ -71,6 +69,7 @@ internal class UsernameEditViewModel private constructor(private val mode: Usern
if (mode == UsernameEditMode.RECOVERY) {
onNicknameUpdated(SignalStore.account().username?.split(Usernames.DELIMITER)?.first() ?: "")
onDiscriminatorUpdated(SignalStore.account().username?.split(Usernames.DELIMITER)?.last() ?: "")
}
}
@ -129,6 +128,13 @@ internal class UsernameEditViewModel private constructor(private val mode: Usern
events.onNext(Event.SKIPPED)
}
fun isSameUsernameRecovery(): Boolean {
val usernameState = uiState.state.usernameState
return mode == UsernameEditMode.RECOVERY &&
usernameState is UsernameState.Reserved &&
usernameState.requireUsername().username.lowercase() == SignalStore.account().username?.lowercase()
}
/**
* @param userConfirmedResetOk True if the user is submitting this after confirming that they're ok with resetting their username via [Event.NEEDS_CONFIRM_RESET].
*/