Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 9038ea7

Browse files
committed
Only warn user when changing password in Settings if they have other devices
1 parent 853e0e9 commit 9038ea7

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/components/views/settings/ChangePassword.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ enum Phase {
4141
}
4242

4343
interface IProps {
44-
onFinished?: (outcome: { didSetEmail?: boolean, didLogoutAllDevices: boolean }) => void;
44+
onFinished?: (outcome: {
45+
didSetEmail?: boolean;
46+
/** Was one or more other devices logged out whilst changing the password */
47+
didLogoutOutOtherDevices: boolean;
48+
}) => void;
4549
onError?: (error: {error: string}) => void;
4650
rowClassName?: string;
4751
buttonClassName?: string;
@@ -87,9 +91,9 @@ export default class ChangePassword extends React.Component<IProps, IState> {
8791

8892
// if the server supports it then don't sign user out of all devices
8993
const serverSupportsControlOfDevicesLogout = await cli.doesServerSupportLogoutDevices();
90-
const logoutDevices = serverSupportsControlOfDevicesLogout ? false : undefined;
94+
const userHasOtherDevices = (await cli.getDevices()).devices.length > 1;
9195

92-
if (!serverSupportsControlOfDevicesLogout && this.props.confirm) {
96+
if (userHasOtherDevices && !serverSupportsControlOfDevicesLogout && this.props.confirm) {
9397
// warn about logging out all devices
9498
const { finished } = Modal.createTrackedDialog<[boolean]>('Change Password', '', QuestionDialog, {
9599
title: _t("Warning!"),
@@ -124,14 +128,15 @@ export default class ChangePassword extends React.Component<IProps, IState> {
124128
if (!confirmed) return;
125129
}
126130

127-
this.changePassword(cli, oldPassword, newPassword, logoutDevices);
131+
this.changePassword(cli, oldPassword, newPassword, serverSupportsControlOfDevicesLogout, userHasOtherDevices);
128132
}
129133

130134
private changePassword(
131135
cli: MatrixClient,
132136
oldPassword: string,
133137
newPassword: string,
134-
logoutDevices: boolean | undefined,
138+
serverSupportsControlOfDevicesLogout: boolean,
139+
userHasOtherDevices: boolean,
135140
): void {
136141
const authDict = {
137142
type: 'm.login.password',
@@ -149,19 +154,21 @@ export default class ChangePassword extends React.Component<IProps, IState> {
149154
phase: Phase.Uploading,
150155
});
151156

157+
const logoutDevices = serverSupportsControlOfDevicesLogout ? false : undefined;
158+
152159
// undefined or true mean all devices signed out
153-
const didLogoutAllDevices = logoutDevices !== false;
160+
const didLogoutOutOtherDevices = !serverSupportsControlOfDevicesLogout && userHasOtherDevices;
154161

155162
cli.setPassword(authDict, newPassword, logoutDevices).then(() => {
156163
if (this.props.shouldAskForEmail) {
157164
return this.optionallySetEmail().then((confirmed) => {
158165
this.props.onFinished({
159166
didSetEmail: confirmed,
160-
didLogoutAllDevices,
167+
didLogoutOutOtherDevices,
161168
});
162169
});
163170
} else {
164-
this.props.onFinished({ didLogoutAllDevices });
171+
this.props.onFinished({ didLogoutOutOtherDevices });
165172
}
166173
}, (err) => {
167174
this.props.onError(err);

src/components/views/settings/tabs/user/GeneralUserSettingsTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
260260
});
261261
};
262262

263-
private onPasswordChanged = ({ didLogoutAllDevices }: { didLogoutAllDevices: boolean }): void => {
263+
private onPasswordChanged = ({ didLogoutOutOtherDevices }: { didLogoutOutOtherDevices: boolean }): void => {
264264
let description = _t("Your password was successfully changed.");
265-
if (didLogoutAllDevices) {
265+
if (didLogoutOutOtherDevices) {
266266
description += " " + _t(
267267
"You will not receive push notifications on other devices until you sign back in to them.",
268268
);

0 commit comments

Comments
 (0)