Skip to content

Commit

Permalink
fix: account settings not restoring on "Cancel"
Browse files Browse the repository at this point in the history
...if the user attempted to set invalid
credentials by pressing "OK" prior to pressing "Cancel"

But there are still cases where invalid credentials are still stored,
see comments.

This means that there are users for whom the "Password and Account"
dialog shows credentials that are actually invalid.
This commit does not address this,
neither does #4032
  • Loading branch information
WofWca committed Jul 17, 2024
1 parent 912c742 commit 8d7f7e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- fix update unread badge on receiving device messages #4020
- fix target chat was not opened on notification click #3983
- fix "Password and Account" dialog not indicating invalid credentials, making it seem that you can change password like this #4032
- fix "Password and Account" not restoring original credentials on "Cancel" sometimes #4033

<a id="1_46_1"></a>

Expand Down
45 changes: 44 additions & 1 deletion src/renderer/components/dialogs/EditAccountAndPasswordDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function EditAccountInner(onClose: DialogProps['onClose']) {

const [userNeverChangedAccountSettings, setUserNeverChangedAccountSettings] =
useState(true)
const [
userNeverAppliedNewAccountSettings,
setUserNeverAppliedNewAccountSettings,
] = useState(true)

const { openDialog } = useDialog()
const openConfirmationDialog = useConfirmationDialog()
Expand Down Expand Up @@ -92,6 +96,7 @@ function EditAccountInner(onClose: DialogProps['onClose']) {
const onSuccess = () => onClose()

const update = () => {
setUserNeverAppliedNewAccountSettings(false)
openDialog(ConfigureProgressDialog, {
credentials: accountSettings,
onSuccess,
Expand Down Expand Up @@ -132,6 +137,44 @@ function EditAccountInner(onClose: DialogProps['onClose']) {
if (update) onClose()
}, [onClose, onUpdate])

const onCacnel = () => {
if (userNeverAppliedNewAccountSettings) {
onClose()
return
}
// This for the case when the user edited credentials, pressed "OK",
// and then we failed to confugure account (see `ConfigureProgressDialog`),
// (which would result in `EditAccountAndPasswordDialog`
// not getting closed).
// In this case, "cancel" should revert back to the credentials that were
// set when the dialog was first opened.
//
// Yes, simply doing
// `await BackendRemote.rpc.batchSetConfig(accountId, initial_settings)`
// is also an option, but let's show the user that the original
// credentials are also not good, if that is the case.
//
// And yes, simply closing Delta Chat without pressing "Cancel",
// or the user closing the dialog wiht "Esc"
// would result this code not gettings invoked, and therefore
// original credentials not getting restored...
openDialog(ConfigureProgressDialog, {
credentials: initial_settings, // Yes, `initial_settings`.
onSuccess: () => {},
onFail: error => {
// This shouldn't happen often, because
// we simply returned to original settings.
// But it could, if, for example, the credentials
// were changed on the server,
// and the user never entered the correct credentials.
openDialog(AlertDialog, { message: error })
},
})
// Close the dialog immediately, no matter the result of the
// `ConfigureProgressDialog`.
onClose()
}

if (accountSettings === null) return null
return (
<>
Expand All @@ -145,7 +188,7 @@ function EditAccountInner(onClose: DialogProps['onClose']) {
)}
</DialogContent>
</DialogBody>
<OkCancelFooterAction onCancel={() => onClose()} onOk={onOk} />
<OkCancelFooterAction onCancel={onCacnel} onOk={onOk} />
</>
)
}

0 comments on commit 8d7f7e0

Please sign in to comment.