From aafec49abfb3d8c41935ca3e8e14f83191efc352 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 2 Aug 2016 18:40:12 +0100 Subject: [PATCH 01/11] WIP for deactivaing account UI https://github.com/vector-im/vector-web/issues/1775 --- src/component-index.js | 1 + src/components/structures/UserSettings.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/component-index.js b/src/component-index.js index 19a016aec8..95293c2990 100644 --- a/src/component-index.js +++ b/src/component-index.js @@ -44,6 +44,7 @@ module.exports.components['views.avatars.RoomAvatar'] = require('./components/vi module.exports.components['views.create_room.CreateRoomButton'] = require('./components/views/create_room/CreateRoomButton'); module.exports.components['views.create_room.Presets'] = require('./components/views/create_room/Presets'); module.exports.components['views.create_room.RoomAlias'] = require('./components/views/create_room/RoomAlias'); +module.exports.components['views.dialogs.DeactivateAccountDialog'] = require('./components/views/dialogs/DeactivateAccountDialog'); module.exports.components['views.dialogs.ErrorDialog'] = require('./components/views/dialogs/ErrorDialog'); module.exports.components['views.dialogs.LogoutPrompt'] = require('./components/views/dialogs/LogoutPrompt'); module.exports.components['views.dialogs.NeedToRegisterDialog'] = require('./components/views/dialogs/NeedToRegisterDialog'); diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 6555668ff4..6714604c1d 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -262,6 +262,11 @@ module.exports = React.createClass({ }); }, + _onDeactivateAccountClicked: function() { + const DeactivateAccountDialog = sdk.getComponent("dialogs.DeactivateAccountDialog"); + Modal.createDialog(DeactivateAccountDialog, {}); + }, + _renderUserInterfaceSettings: function() { var client = MatrixClientPeg.get(); @@ -379,6 +384,17 @@ module.exports = React.createClass({ ) }, + _renderDeactivateAccount: function() { + return
+

Labs

+
+ +
+
; + }, + render: function() { var self = this; var Loader = sdk.getComponent("elements.Spinner"); @@ -548,6 +564,8 @@ module.exports = React.createClass({ + {this._renderDeactivateAccount()} + ); From 54c10a5d89b9957727d9f926cf70884dc98236ff Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 2 Aug 2016 18:42:02 +0100 Subject: [PATCH 02/11] Get name of section right --- src/components/structures/UserSettings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 6714604c1d..7fb617d690 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -386,7 +386,7 @@ module.exports = React.createClass({ _renderDeactivateAccount: function() { return
-

Labs

+

Deactivate Account

+ } + + return ( +
+
+ Deactivate Account +
+
+ This will make your account permanently unusable. You will not be able to re-register the same user ID.
+
+ This action is irreversible.
+
+ To continue, please enter your password.
+
+ Password:
+ {this._passwordField = e;}} + className={passwordBoxClass} + /> + {error} +
+
+ + + {cancelButton} +
+
+ ); + } +} + +DeactivateAccountDialog.propTypes = { + onFinished: React.PropTypes.func.isRequired, +}; From f47ac87775568b41334ccd503869ea7fa81a373c Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 11:34:31 +0100 Subject: [PATCH 04/11] Don't show deactivate button for guests --- src/components/structures/UserSettings.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 7fb617d690..89146229fa 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -385,6 +385,9 @@ module.exports = React.createClass({ }, _renderDeactivateAccount: function() { + // We can't deactivate a guest account. + if (MatrixClientPeg.get().isGuest()) return null; + return

Deactivate Account

From ffa97a4095b1764c847c238998a0b0d08c9a9dc6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 11:47:29 +0100 Subject: [PATCH 05/11] Log out when account is deactivated --- src/Lifecycle.js | 10 +++++----- .../views/dialogs/DeactivateAccountDialog.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 163e6e9463..b50e96b298 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -46,11 +46,11 @@ function logout() { // logout doesn't work for guest sessions // Also we sometimes want to re-log in a guest session // if we abort the login - _onLoggedOut(); + onLoggedOut(); return; } - return MatrixClientPeg.get().logout().then(_onLoggedOut, + return MatrixClientPeg.get().logout().then(onLoggedOut, (err) => { // Just throwing an error here is going to be very unhelpful // if you're trying to log out because your server's down and @@ -60,7 +60,7 @@ function logout() { // tokens expire (and if you really think you've been compromised, // change your password). console.log("Failed to call logout API: token will not be invalidated"); - _onLoggedOut(); + onLoggedOut(); } ); } @@ -87,7 +87,7 @@ function startMatrixClient() { MatrixClientPeg.get().startClient(MatrixClientPeg.opts); } -function _onLoggedOut() { +function onLoggedOut() { if (window.localStorage) { const hsUrl = window.localStorage.getItem("mx_hs_url"); const isUrl = window.localStorage.getItem("mx_is_url"); @@ -114,5 +114,5 @@ function _stopMatrixClient() { } module.exports = { - setLoggedIn, logout, startMatrixClient + setLoggedIn, logout, startMatrixClient, onLoggedOut }; diff --git a/src/components/views/dialogs/DeactivateAccountDialog.js b/src/components/views/dialogs/DeactivateAccountDialog.js index 0470703307..e60f66737c 100644 --- a/src/components/views/dialogs/DeactivateAccountDialog.js +++ b/src/components/views/dialogs/DeactivateAccountDialog.js @@ -53,8 +53,8 @@ export default class DeactivateAccountDialog extends React.Component { user: MatrixClientPeg.get().credentials.userId, password: this._passwordField.value, }).done(() => { - - // XXX blocked behind PR + Lifecycle.onLoggedOut(); + this.props.onFinished(false); }, (err) => { let errStr = 'Unknown error'; // https://matrix.org/jira/browse/SYN-744 From 2d936a2850c4b3064e9de1cb333f32de056938f8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 18:23:38 +0100 Subject: [PATCH 06/11] Don't leave isRoomPublished as undefined As this causes react to consider the component uncontrolled and then warn when we change it to controlled --- src/components/views/rooms/RoomSettings.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index b12c6e4aa2..8269c539f1 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -70,7 +70,9 @@ module.exports = React.createClass({ // is also called from the saving code so we must return the correct value here // if we have it (although this could race if the user saves before we load whether // the room is published or not). - isRoomPublished: this._originalIsRoomPublished, + // Default to false if it's undefined, otherwise react complains about changing + // components from uncontrolled to controlled + isRoomPublished: this._originalIsRoomPublished || false, }; }, From f4e40696bcf290873358bdd50e5493ba64798fab Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 3 Aug 2016 21:17:54 +0100 Subject: [PATCH 07/11] Bump emojione to 2.2.3 Because @aviraldg says it's better. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ddd9ffd9f5..4808a33891 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "draft-js-export-html": "^0.2.2", "draft-js-export-markdown": "^0.2.0", "draft-js-import-markdown": "^0.1.6", - "emojione": "^2.2.2", + "emojione": "^2.2.3", "favico.js": "^0.3.10", "filesize": "^3.1.2", "flux": "^2.0.3", From 24cc4f52bfb0156d061b876c479bbe0a57168e88 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 3 Aug 2016 21:36:52 +0100 Subject: [PATCH 08/11] Downgrade emojione to 2.2.3 ... because @aviraldg says > 2.2.3 is broken :/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4808a33891..57cc61aab7 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "draft-js-export-html": "^0.2.2", "draft-js-export-markdown": "^0.2.0", "draft-js-import-markdown": "^0.1.6", - "emojione": "^2.2.3", + "emojione": "2.2.3", "favico.js": "^0.3.10", "filesize": "^3.1.2", "flux": "^2.0.3", From e144da75e390b064ac95a59be29a0c318caea095 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 4 Aug 2016 10:49:34 +0100 Subject: [PATCH 09/11] Comment onLoggedOut & consistent comment style --- src/Lifecycle.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 4393c29d37..23bf5f60a5 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -79,6 +79,10 @@ function startMatrixClient() { MatrixClientPeg.start(); } +/* + * Stops a running client and all related services, used after + * a session has been logged out / ended. + */ function onLoggedOut() { if (window.localStorage) { const hsUrl = window.localStorage.getItem("mx_hs_url"); @@ -95,7 +99,9 @@ function onLoggedOut() { dis.dispatch({action: 'on_logged_out'}); } -// stop all the background processes related to the current client +/** + * Stop all the background processes related to the current client + */ function _stopMatrixClient() { Notifier.stop(); UserActivity.stop(); From c017e8dcf4cefc40ef42432b10dff9b9b8e1096c Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 4 Aug 2016 10:51:31 +0100 Subject: [PATCH 10/11] Initialise _passwordField & delete stale comment --- src/components/views/dialogs/DeactivateAccountDialog.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/views/dialogs/DeactivateAccountDialog.js b/src/components/views/dialogs/DeactivateAccountDialog.js index e60f66737c..1c6de7ab40 100644 --- a/src/components/views/dialogs/DeactivateAccountDialog.js +++ b/src/components/views/dialogs/DeactivateAccountDialog.js @@ -25,7 +25,7 @@ export default class DeactivateAccountDialog extends React.Component { constructor(props, context) { super(props, context); - this._passwordField; + this._passwordField = null; this._onOk = this._onOk.bind(this); this._onCancel = this._onCancel.bind(this); @@ -85,8 +85,6 @@ export default class DeactivateAccountDialog extends React.Component { passwordBoxClass = 'error'; } - // I would use a spinner here but that causes the button to be rendered - // slightly higher than the other one const okLabel = this.state.busy ? : 'Deactivate Account'; const okEnabled = this.state.confirmButtonEnabled && !this.state.busy; From f7fda68e26e60998dc9ed154830d893fc48d49b9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 4 Aug 2016 10:53:07 +0100 Subject: [PATCH 11/11] Use p tags instead of brs --- .../views/dialogs/DeactivateAccountDialog.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/views/dialogs/DeactivateAccountDialog.js b/src/components/views/dialogs/DeactivateAccountDialog.js index 1c6de7ab40..926e4059d2 100644 --- a/src/components/views/dialogs/DeactivateAccountDialog.js +++ b/src/components/views/dialogs/DeactivateAccountDialog.js @@ -101,13 +101,13 @@ export default class DeactivateAccountDialog extends React.Component { Deactivate Account
- This will make your account permanently unusable. You will not be able to re-register the same user ID.
-
- This action is irreversible.
-
- To continue, please enter your password.
-
- Password:
+

This will make your account permanently unusable. You will not be able to re-register the same user ID.

+ +

This action is irreversible.

+ +

To continue, please enter your password.

+ +

Password: