From 384f07adb2b6d11f0fbcc518494040fe6fc73ce6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 12 Aug 2019 14:36:48 +0100 Subject: [PATCH 01/26] Disconnect from IS button --- src/components/views/settings/SetIdServer.js | 48 ++++++++++++++++++++ src/i18n/strings/en_EN.json | 4 ++ 2 files changed, 52 insertions(+) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 466ac01dd0..8f7f30a2e1 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -22,6 +22,7 @@ import sdk from '../../../index'; import MatrixClientPeg from "../../../MatrixClientPeg"; import SdkConfig from "../../../SdkConfig"; import Field from "../elements/Field"; +import Modal from '../../../Modal'; /** * If a url has no path component, etc. abbreviate it to just the hostname @@ -148,7 +149,39 @@ export default class SetIdServer extends React.Component { }); }; + _onDisconnectClicked = () => { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + Modal.createTrackedDialog('ID Server Disconnect Warning', '', QuestionDialog, { + title: _t("Disconnect ID Server"), + description: +
+ {_t( + "Disconnect from the ID Server ?", {}, + {idserver: sub => {abbreviateUrl(this.state.currentClientIdServer)}}, + )}, +
, + button: _t("Disconnect"), + onFinished: (confirmed) => { + if (confirmed) { + this._disconnectIdServer(); + } + }, + }); + }; + + _disconnectIdServer = () => { + MatrixClientPeg.get().setIdentityServerUrl(null); + localStorage.removeItem("mx_is_url"); + this.setState({ + busy: false, + error: null, + currentClientIdServer: MatrixClientPeg.get().getIdentityServerUrl(), + idServer: '', + }); + }; + render() { + const AccessibleButton = sdk.getComponent('views.elements.AccessibleButton'); const idServerUrl = this.state.currentClientIdServer; let sectionTitle; let bodyText; @@ -169,6 +202,20 @@ export default class SetIdServer extends React.Component { ); } + let discoSection; + if (idServerUrl) { + discoSection =
+ {_t( + "Disconnecting from your identity server will mean you " + + "won’t be discoverable by other users and you won’t be " + + "able to invite others by email or phone.", + )} + + {_t("Disconnect")} + +
; + } + return (
@@ -187,6 +234,7 @@ export default class SetIdServer extends React.Component { type="submit" value={_t("Change")} disabled={!this._idServerChangeEnabled()} /> + {discoSection} ); } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 61d9fbc49e..9c4bcef197 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -541,10 +541,14 @@ "Could not connect to ID Server": "Could not connect to ID Server", "Not a valid ID Server (status code %(code)s)": "Not a valid ID Server (status code %(code)s)", "Checking Server": "Checking Server", + "Disconnect ID Server": "Disconnect ID Server", + "Disconnect from the ID Server %(idserver)s?": "Disconnect from the ID Server %(idserver)s?", + "Disconnect": "Disconnect", "Identity Server (%(server)s)": "Identity Server (%(server)s)", "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.", "Identity Server": "Identity Server", "You are not currently using an Identity Server. To discover and be discoverable by existing contacts you know, add one below": "You are not currently using an Identity Server. To discover and be discoverable by existing contacts you know, add one below", + "Disconnecting from your identity server will mean you won’t be discoverable by other users and you won’t be able to invite others by email or phone.": "Disconnecting from your identity server will mean you won’t be discoverable by other users and you won’t be able to invite others by email or phone.", "Change": "Change", "Flair": "Flair", "Failed to change password. Is your password correct?": "Failed to change password. Is your password correct?", From 115e4c0370699be9b4cb2a68739e6b954721505f Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 12 Aug 2019 14:40:11 +0100 Subject: [PATCH 02/26] Remove IS access token too --- src/components/views/settings/SetIdServer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 0bb92d75e4..73b8514327 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -172,6 +172,7 @@ export default class SetIdServer extends React.Component { _disconnectIdServer = () => { MatrixClientPeg.get().setIdentityServerUrl(null); + localStorage.removeItem("mx_is_access_token", fullUrl); localStorage.removeItem("mx_is_url"); this.setState({ busy: false, From 0b51a5f45260a3b9172d1df10d14b9158c884bd0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 12 Aug 2019 14:45:15 +0100 Subject: [PATCH 03/26] c+p fail --- src/components/views/settings/SetIdServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 73b8514327..b95a7f5ae5 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -172,7 +172,7 @@ export default class SetIdServer extends React.Component { _disconnectIdServer = () => { MatrixClientPeg.get().setIdentityServerUrl(null); - localStorage.removeItem("mx_is_access_token", fullUrl); + localStorage.removeItem("mx_is_access_token"); localStorage.removeItem("mx_is_url"); this.setState({ busy: false, From b694a56689325b7eed5a2a2f8eb8bf2510a1ee15 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 12 Aug 2019 14:48:02 +0100 Subject: [PATCH 04/26] i18n --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 9c4bcef197..577048bd18 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -542,7 +542,7 @@ "Not a valid ID Server (status code %(code)s)": "Not a valid ID Server (status code %(code)s)", "Checking Server": "Checking Server", "Disconnect ID Server": "Disconnect ID Server", - "Disconnect from the ID Server %(idserver)s?": "Disconnect from the ID Server %(idserver)s?", + "Disconnect from the ID Server ?": "Disconnect from the ID Server ?", "Disconnect": "Disconnect", "Identity Server (%(server)s)": "Identity Server (%(server)s)", "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.", From c732ae3aa99375f455f91af907c84cbcf69f1f1e Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 10:46:42 +0100 Subject: [PATCH 05/26] Correct license header Co-Authored-By: J. Ryan Stinnett --- res/css/views/settings/_SetIdServer.scss | 2 +- src/components/views/settings/SetIdServer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/res/css/views/settings/_SetIdServer.scss b/res/css/views/settings/_SetIdServer.scss index c6fcfc8af5..cc58a61073 100644 --- a/res/css/views/settings/_SetIdServer.scss +++ b/res/css/views/settings/_SetIdServer.scss @@ -1,5 +1,5 @@ /* -Copyright 2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index a87fe034a1..85f655a88f 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -1,5 +1,5 @@ /* -Copyright 2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 934b711936651647549675bd427460f6c9d34fda Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 10:48:56 +0100 Subject: [PATCH 06/26] write Identity Server out in full to be less confusing Co-Authored-By: J. Ryan Stinnett --- src/components/views/settings/SetIdServer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 85f655a88f..5fa3e612da 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -61,7 +61,7 @@ function unabbreviateUrl(u) { * @param {string} isUrl The url to check * @returns {string} null if url passes all checks, otherwise i18ned error string */ -async function checkIsUrl(isUrl) { +async function checkIdentityServerUrl(url) { const parsedUrl = url.parse(isUrl); if (parsedUrl.protocol !== 'https:') return _t("Identity Server URL must be HTTPS"); @@ -75,9 +75,9 @@ async function checkIsUrl(isUrl) { { method: "GET", url: isUrl + '/_matrix/identity/api/v1' }, (err, response, body) => { if (err) { - resolve(_t("Could not connect to ID Server")); + resolve(_t("Could not connect to Identity Server")); } else if (response.status < 200 || response.status >= 300) { - resolve(_t("Not a valid ID Server (status code %(code)s)", {code: response.status})); + resolve(_t("Not a valid Identity Server (status code %(code)s)", {code: response.status})); } else { resolve(null); } From c36c3a9b3366cb4128b86480161707827cd93424 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 10:51:26 +0100 Subject: [PATCH 07/26] other general grammar Co-Authored-By: J. Ryan Stinnett --- src/components/views/settings/SetIdServer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 5fa3e612da..b20f6930e5 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -114,7 +114,7 @@ export default class SetIdServer extends React.Component { const InlineSpinner = sdk.getComponent('views.elements.InlineSpinner'); return
- { _t("Checking Server") } + { _t("Checking server") }
; } else if (this.state.error) { return this.state.error; @@ -164,9 +164,9 @@ export default class SetIdServer extends React.Component { } else { sectionTitle = _t("Identity Server"); bodyText = _t( - "You are not currently using an Identity Server. " + + "You are not currently using an identity server. " + "To discover and be discoverable by existing contacts you know, " + - "add one below", + "add one below.", ); } From 860a9dbc820bb25c3a768657496ccfb9bc8ace3e Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 11:01:04 +0100 Subject: [PATCH 08/26] s/tooltip/tooltipContent/ --- src/components/views/elements/Field.js | 9 ++++----- src/components/views/settings/SetIdServer.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/views/elements/Field.js b/src/components/views/elements/Field.js index 084ec1bd6a..8272b36639 100644 --- a/src/components/views/elements/Field.js +++ b/src/components/views/elements/Field.js @@ -48,7 +48,7 @@ export default class Field extends React.PureComponent { onValidate: PropTypes.func, // If specified, contents will appear as a tooltip on the element and // validation feedback tooltips will be suppressed. - tooltip: PropTypes.node, + tooltipContent: PropTypes.node, // All other props pass through to the . }; @@ -137,8 +137,7 @@ export default class Field extends React.PureComponent { }, VALIDATION_THROTTLE_MS); render() { - const { element, prefix, onValidate, children, ...inputProps } = this.props; - delete inputProps.tooltip; // needs to be removed from props but we don't need it here + const { element, prefix, onValidate, children, tooltipContent, ...inputProps } = this.props; const inputElement = element || "input"; @@ -170,11 +169,11 @@ export default class Field extends React.PureComponent { // Handle displaying feedback on validity const Tooltip = sdk.getComponent("elements.Tooltip"); let fieldTooltip; - if (this.props.tooltip || this.state.feedback) { + if (tooltipContent || this.state.feedback) { fieldTooltip = ; } diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index b20f6930e5..9fa67379d0 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -182,7 +182,7 @@ export default class SetIdServer extends React.Component { id="mx_SetIdServer_idServer" type="text" value={this.state.idServer} autoComplete="off" onChange={this._onIdentityServerChanged} - tooltip={this._getTooltip()} + tooltipContent={this._getTooltip()} /> Date: Tue, 13 Aug 2019 11:05:41 +0100 Subject: [PATCH 09/26] link to doc issue --- src/components/views/settings/SetIdServer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 9fa67379d0..a9762b6e50 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -72,6 +72,7 @@ async function checkIdentityServerUrl(url) { request( // also XXX: we don't really know whether to hit /v1 or /v2 for this: we // probably want a /versions endpoint like the C/S API. + // https://github.com/matrix-org/matrix-doc/issues/1665 { method: "GET", url: isUrl + '/_matrix/identity/api/v1' }, (err, response, body) => { if (err) { From e07c22a78d1024e678ddc7ab3900490145256d83 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 12:53:14 +0100 Subject: [PATCH 10/26] Make mixin for fields in settings that need to be the same width and make that width narrower so we can fit a tooltip in the left hand side (they were a little too wide anyway for the kind of data being entered, even on a narrow window). --- res/css/_common.scss | 4 ++++ res/css/views/settings/_ProfileSettings.scss | 4 ++++ res/css/views/settings/_SetIdServer.scss | 2 +- .../views/settings/tabs/user/_GeneralUserSettingsTab.scss | 8 ++++---- .../settings/tabs/user/_PreferencesUserSettingsTab.scss | 2 +- .../views/settings/tabs/user/_VoiceUserSettingsTab.scss | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/res/css/_common.scss b/res/css/_common.scss index 517ced43fb..1b7c8ec938 100644 --- a/res/css/_common.scss +++ b/res/css/_common.scss @@ -559,3 +559,7 @@ input[type=text]:focus, input[type=password]:focus, textarea:focus { .mx_Username_color8 { color: $username-variant8-color; } + +@define-mixin mx_Settings_fullWidthField { + margin-right: 200px; +} diff --git a/res/css/views/settings/_ProfileSettings.scss b/res/css/views/settings/_ProfileSettings.scss index 3e97a0ff6d..161cd7fa7a 100644 --- a/res/css/views/settings/_ProfileSettings.scss +++ b/res/css/views/settings/_ProfileSettings.scss @@ -30,6 +30,10 @@ limitations under the License. margin-top: 0; } +.mx_ProfileSettings_controls .mx_Field { + margin-right: 100px; +} + .mx_ProfileSettings_hostingSignup { margin-left: 20px; diff --git a/res/css/views/settings/_SetIdServer.scss b/res/css/views/settings/_SetIdServer.scss index cc58a61073..55ad6eef02 100644 --- a/res/css/views/settings/_SetIdServer.scss +++ b/res/css/views/settings/_SetIdServer.scss @@ -15,5 +15,5 @@ limitations under the License. */ .mx_SetIdServer .mx_Field_input { - width: 300px; + @mixin mx_Settings_fullWidthField; } diff --git a/res/css/views/settings/tabs/user/_GeneralUserSettingsTab.scss b/res/css/views/settings/tabs/user/_GeneralUserSettingsTab.scss index 091c98ffb8..16467165cf 100644 --- a/res/css/views/settings/tabs/user/_GeneralUserSettingsTab.scss +++ b/res/css/views/settings/tabs/user/_GeneralUserSettingsTab.scss @@ -16,15 +16,15 @@ limitations under the License. .mx_GeneralUserSettingsTab_changePassword .mx_Field, .mx_GeneralUserSettingsTab_themeSection .mx_Field { - margin-right: 100px; // Align with the other fields on the page + @mixin mx_Settings_fullWidthField; } .mx_GeneralUserSettingsTab_changePassword .mx_Field:first-child { margin-top: 0; } -.mx_GeneralUserSettingsTab_accountSection > .mx_EmailAddresses, -.mx_GeneralUserSettingsTab_accountSection > .mx_PhoneNumbers, +.mx_GeneralUserSettingsTab_accountSection .mx_EmailAddresses, +.mx_GeneralUserSettingsTab_accountSection .mx_PhoneNumbers, .mx_GeneralUserSettingsTab_languageInput { - margin-right: 100px; // Align with the other fields on the page + @mixin mx_Settings_fullWidthField; } diff --git a/res/css/views/settings/tabs/user/_PreferencesUserSettingsTab.scss b/res/css/views/settings/tabs/user/_PreferencesUserSettingsTab.scss index b3430f47af..d003e175d9 100644 --- a/res/css/views/settings/tabs/user/_PreferencesUserSettingsTab.scss +++ b/res/css/views/settings/tabs/user/_PreferencesUserSettingsTab.scss @@ -15,5 +15,5 @@ limitations under the License. */ .mx_PreferencesUserSettingsTab .mx_Field { - margin-right: 100px; // Align with the rest of the controls + @mixin mx_Settings_fullWidthField; } diff --git a/res/css/views/settings/tabs/user/_VoiceUserSettingsTab.scss b/res/css/views/settings/tabs/user/_VoiceUserSettingsTab.scss index 36c8cfd896..69d57bdba1 100644 --- a/res/css/views/settings/tabs/user/_VoiceUserSettingsTab.scss +++ b/res/css/views/settings/tabs/user/_VoiceUserSettingsTab.scss @@ -15,7 +15,7 @@ limitations under the License. */ .mx_VoiceUserSettingsTab .mx_Field { - margin-right: 100px; // align with the rest of the fields + @mixin mx_Settings_fullWidthField; } .mx_VoiceUserSettingsTab_missingMediaPermissions { From 02504b995924e29b3749d75775a301763aa903c7 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 12:59:34 +0100 Subject: [PATCH 11/26] make it work again --- src/components/views/settings/SetIdServer.js | 10 +++++----- src/i18n/strings/en_EN.json | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index a9762b6e50..70140d4b6a 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -58,11 +58,11 @@ function unabbreviateUrl(u) { /** * Check an IS URL is valid, including liveness check * - * @param {string} isUrl The url to check + * @param {string} u The url to check * @returns {string} null if url passes all checks, otherwise i18ned error string */ -async function checkIdentityServerUrl(url) { - const parsedUrl = url.parse(isUrl); +async function checkIdentityServerUrl(u) { + const parsedUrl = url.parse(u); if (parsedUrl.protocol !== 'https:') return _t("Identity Server URL must be HTTPS"); @@ -73,7 +73,7 @@ async function checkIdentityServerUrl(url) { // also XXX: we don't really know whether to hit /v1 or /v2 for this: we // probably want a /versions endpoint like the C/S API. // https://github.com/matrix-org/matrix-doc/issues/1665 - { method: "GET", url: isUrl + '/_matrix/identity/api/v1' }, + { method: "GET", url: u + '/_matrix/identity/api/v1' }, (err, response, body) => { if (err) { resolve(_t("Could not connect to Identity Server")); @@ -133,7 +133,7 @@ export default class SetIdServer extends React.Component { const fullUrl = unabbreviateUrl(this.state.idServer); - const errStr = await checkIsUrl(fullUrl); + const errStr = await checkIdentityServerUrl(fullUrl); let newFormValue = this.state.idServer; if (!errStr) { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 154871a977..5576ee6122 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -540,13 +540,13 @@ "Display Name": "Display Name", "Save": "Save", "Identity Server URL must be HTTPS": "Identity Server URL must be HTTPS", - "Could not connect to ID Server": "Could not connect to ID Server", - "Not a valid ID Server (status code %(code)s)": "Not a valid ID Server (status code %(code)s)", - "Checking Server": "Checking Server", + "Could not connect to Identity Server": "Could not connect to Identity Server", + "Not a valid Identity Server (status code %(code)s)": "Not a valid Identity Server (status code %(code)s)", + "Checking server": "Checking server", "Identity Server (%(server)s)": "Identity Server (%(server)s)", "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.", "Identity Server": "Identity Server", - "You are not currently using an Identity Server. To discover and be discoverable by existing contacts you know, add one below": "You are not currently using an Identity Server. To discover and be discoverable by existing contacts you know, add one below", + "You are not currently using an identity server. To discover and be discoverable by existing contacts you know, add one below.": "You are not currently using an identity server. To discover and be discoverable by existing contacts you know, add one below.", "Change": "Change", "Flair": "Flair", "Failed to change password. Is your password correct?": "Failed to change password. Is your password correct?", From 050766e7bb73fba8fd7f6a2705ba82fa0e9448d2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 15:19:39 +0100 Subject: [PATCH 12/26] selector ordering --- res/css/views/settings/_ProfileSettings.scss | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/res/css/views/settings/_ProfileSettings.scss b/res/css/views/settings/_ProfileSettings.scss index 161cd7fa7a..afac75986f 100644 --- a/res/css/views/settings/_ProfileSettings.scss +++ b/res/css/views/settings/_ProfileSettings.scss @@ -26,14 +26,14 @@ limitations under the License. height: 4em; } -.mx_ProfileSettings_controls .mx_Field:first-child { - margin-top: 0; -} - .mx_ProfileSettings_controls .mx_Field { margin-right: 100px; } +.mx_ProfileSettings_controls .mx_Field:first-child { + margin-top: 0; +} + .mx_ProfileSettings_hostingSignup { margin-left: 20px; From 7a9246533d0084d954709ebbadfe1cfffc156c1b Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 15:40:03 +0100 Subject: [PATCH 13/26] Hack to ignore @define-mixin as per bug in comment --- .stylelintrc.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.stylelintrc.js b/.stylelintrc.js index 97e1ec8023..f028c76cc0 100644 --- a/.stylelintrc.js +++ b/.stylelintrc.js @@ -15,6 +15,9 @@ module.exports = { "number-leading-zero": null, "selector-list-comma-newline-after": null, "at-rule-no-unknown": null, - "scss/at-rule-no-unknown": true, + "scss/at-rule-no-unknown": [true, { + // https://github.com/vector-im/riot-web/issues/10544 + "ignoreAtRules": ["define-mixin"], + }], } } From 31fd36efba4eb9afca36e388ebf06a89dadac4a5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 16:20:30 +0100 Subject: [PATCH 14/26] use accessiblebutton --- src/components/views/settings/SetIdServer.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 70140d4b6a..72a47bd2ae 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -128,7 +128,9 @@ export default class SetIdServer extends React.Component { return !!this.state.idServer && !this.state.busy; }; - _saveIdServer = async () => { + _saveIdServer = async (e) => { + e.preventDefault(); + this.setState({busy: true}); const fullUrl = unabbreviateUrl(this.state.idServer); @@ -171,6 +173,7 @@ export default class SetIdServer extends React.Component { ); } + const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); return (
@@ -185,10 +188,10 @@ export default class SetIdServer extends React.Component { onChange={this._onIdentityServerChanged} tooltipContent={this._getTooltip()} /> - + onClick={this._saveIdServer} + >{_t("Change")} ); } From 2539da0dfa26ed9f11f825cfcde856f6f00ab7d7 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 16:37:56 +0100 Subject: [PATCH 15/26] Use fetch instead of browser-request --- src/components/views/settings/SetIdServer.js | 29 ++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 72a47bd2ae..5cc63ea261 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -68,23 +68,18 @@ async function checkIdentityServerUrl(u) { // XXX: duplicated logic from js-sdk but it's quite tied up in the validation logic in the // js-sdk so probably as easy to duplicate it than to separate it out so we can reuse it - return new Promise((resolve) => { - request( - // also XXX: we don't really know whether to hit /v1 or /v2 for this: we - // probably want a /versions endpoint like the C/S API. - // https://github.com/matrix-org/matrix-doc/issues/1665 - { method: "GET", url: u + '/_matrix/identity/api/v1' }, - (err, response, body) => { - if (err) { - resolve(_t("Could not connect to Identity Server")); - } else if (response.status < 200 || response.status >= 300) { - resolve(_t("Not a valid Identity Server (status code %(code)s)", {code: response.status})); - } else { - resolve(null); - } - }, - ); - }); + try { + const response = await fetch(u + '/_matrix/identity/api/v1'); + if (response.ok) { + return null; + } else if (response.status < 200 || response.status >= 300) { + return _t("Not a valid Identity Server (status code %(code)s)", {code: response.status}); + } else { + return _t("Could not connect to Identity Server"); + } + } catch (e) { + return _t("Could not connect to Identity Server"); + } } export default class SetIdServer extends React.Component { From 596ff93049881211d94ffd312d3b1b880d3371d4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 16:38:46 +0100 Subject: [PATCH 16/26] unused import --- src/components/views/settings/SetIdServer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 5cc63ea261..9012c4893b 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import request from 'browser-request'; import url from 'url'; import React from 'react'; import {_t} from "../../../languageHandler"; From c80c8dcf244d661102ecdadb4c306c7e45d599b9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 17:55:10 +0100 Subject: [PATCH 17/26] prefill id server box with default if there isn't one --- src/components/views/settings/SetIdServer.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 9012c4893b..f1600358aa 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -85,9 +85,11 @@ export default class SetIdServer extends React.Component { constructor() { super(); - let defaultIdServer = abbreviateUrl(MatrixClientPeg.get().getIdentityServerUrl()); - if (!defaultIdServer) { - defaultIdServer = abbreviateUrl(SdkConfig.get()['validated_server_config']['idServer']) || ''; + let defaultIdServer = ''; + if (!MatrixClientPeg.get().getIdentityServerUrl() && SdkConfig.get()['validated_server_config']['isUrl']) { + // If no ID server is configured but there's one in the config, prepopulate + // the field to help the user. + defaultIdServer = abbreviateUrl(SdkConfig.get()['validated_server_config']['isUrl']); } this.state = { From 7c35107a3736d9f03626a845c386f6e4ecc8df86 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 18:40:27 +0100 Subject: [PATCH 18/26] Update 3pids section visibility when id server set / unset --- src/components/views/settings/SetIdServer.js | 4 +++- .../settings/tabs/user/GeneralUserSettingsTab.js | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index f1600358aa..22b2330f33 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -20,7 +20,7 @@ import {_t} from "../../../languageHandler"; import sdk from '../../../index'; import MatrixClientPeg from "../../../MatrixClientPeg"; import SdkConfig from "../../../SdkConfig"; -import Field from "../elements/Field"; +import dis from "../../../dispatcher"; /** * If a url has no path component, etc. abbreviate it to just the hostname @@ -138,6 +138,7 @@ export default class SetIdServer extends React.Component { MatrixClientPeg.get().setIdentityServerUrl(fullUrl); localStorage.removeItem("mx_is_access_token"); localStorage.setItem("mx_is_url", fullUrl); + dis.dispatch({action: 'id_server_changed'}); newFormValue = ''; } this.setState({ @@ -170,6 +171,7 @@ export default class SetIdServer extends React.Component { } const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); + const Field = sdk.getComponent('elements.Field'); return (
diff --git a/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js b/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js index 7e0d9f686f..b3c7aadd7b 100644 --- a/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js @@ -45,9 +45,22 @@ export default class GeneralUserSettingsTab extends React.Component { this.state = { language: languageHandler.getCurrentLanguage(), theme: SettingsStore.getValueAt(SettingLevel.ACCOUNT, "theme"), + haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl()), }; + + this.dispatcherRef = dis.register(this._onAction); } + componentWillUnmount() { + dis.unregister(this.dispatcherRef); + } + + _onAction = (payload) => { + if (payload.action === 'id_server_changed') { + this.setState({haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl())}); + } + }; + _onLanguageChange = (newLanguage) => { if (this.state.language === newLanguage) return; @@ -124,7 +137,7 @@ export default class GeneralUserSettingsTab extends React.Component { onFinished={this._onPasswordChanged} /> ); - const threepidSection = MatrixClientPeg.get().getIdentityServerUrl() ?
+ const threepidSection = this.state.haveIdServer ?
{_t("Email addresses")} From f88349530af0a479d5a66b371955a59effcf8d68 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 13 Aug 2019 18:41:18 +0100 Subject: [PATCH 19/26] rerun i18n --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 5576ee6122..9639ac0cd9 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -540,8 +540,8 @@ "Display Name": "Display Name", "Save": "Save", "Identity Server URL must be HTTPS": "Identity Server URL must be HTTPS", - "Could not connect to Identity Server": "Could not connect to Identity Server", "Not a valid Identity Server (status code %(code)s)": "Not a valid Identity Server (status code %(code)s)", + "Could not connect to Identity Server": "Could not connect to Identity Server", "Checking server": "Checking server", "Identity Server (%(server)s)": "Identity Server (%(server)s)", "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.", From b0420c106eab05f8fe8a8615d2c3430d87f3a29c Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 14 Aug 2019 10:06:05 +0100 Subject: [PATCH 20/26] Prepopulate client default on disconnect --- src/components/views/settings/SetIdServer.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 96382d9cb4..ad11b20967 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -174,11 +174,19 @@ export default class SetIdServer extends React.Component { MatrixClientPeg.get().setIdentityServerUrl(null); localStorage.removeItem("mx_is_access_token"); localStorage.removeItem("mx_is_url"); + + let newFieldVal = ''; + if (SdkConfig.get()['validated_server_config']['isUrl']) { + // Prepopulate the client's default so the user at least has some idea of + // a valid value they might enter + newFieldVal = abbreviateUrl(SdkConfig.get()['validated_server_config']['isUrl']); + } + this.setState({ busy: false, error: null, currentClientIdServer: MatrixClientPeg.get().getIdentityServerUrl(), - idServer: '', + idServer: newFieldVal, }); }; From 0d560108b6c6a759758d8b50db411afca3a68405 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 14 Aug 2019 10:07:50 +0100 Subject: [PATCH 21/26] Kill smart quotes Co-Authored-By: Travis Ralston --- src/components/views/settings/SetIdServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index ad11b20967..907add6b2d 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -218,7 +218,7 @@ export default class SetIdServer extends React.Component { discoSection =
{_t( "Disconnecting from your identity server will mean you " + - "won’t be discoverable by other users and you won’t be " + + "won't be discoverable by other users and you won't be " + "able to invite others by email or phone.", )} From 85497610e333c28831817930f808ca16cbc3c50e Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 14 Aug 2019 10:08:15 +0100 Subject: [PATCH 22/26] Spell out identity server Co-Authored-By: J. Ryan Stinnett --- src/components/views/settings/SetIdServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 907add6b2d..334c9dfbfb 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -152,7 +152,7 @@ export default class SetIdServer extends React.Component { _onDisconnectClicked = () => { const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); - Modal.createTrackedDialog('ID Server Disconnect Warning', '', QuestionDialog, { + Modal.createTrackedDialog('Identity Server Disconnect Warning', '', QuestionDialog, { title: _t("Disconnect ID Server"), description:
From 3c3b530e1e9569751d069516620556a09515e364 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 14 Aug 2019 10:08:30 +0100 Subject: [PATCH 23/26] Spell out identity server Co-Authored-By: J. Ryan Stinnett --- src/components/views/settings/SetIdServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 334c9dfbfb..05e87c3e00 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -153,7 +153,7 @@ export default class SetIdServer extends React.Component { _onDisconnectClicked = () => { const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); Modal.createTrackedDialog('Identity Server Disconnect Warning', '', QuestionDialog, { - title: _t("Disconnect ID Server"), + title: _t("Disconnect Identity Server"), description:
{_t( From be7956db61ea059565924e2ed8ac0ee412cd13a3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 14 Aug 2019 10:08:43 +0100 Subject: [PATCH 24/26] Spell out identity server Co-Authored-By: J. Ryan Stinnett --- src/components/views/settings/SetIdServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 05e87c3e00..6c6b8faab2 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -157,7 +157,7 @@ export default class SetIdServer extends React.Component { description:
{_t( - "Disconnect from the ID Server ?", {}, + "Disconnect from the identity server ?", {}, {idserver: sub => {abbreviateUrl(this.state.currentClientIdServer)}}, )},
, From c74da125b255df6aed316a4045ab045f29030904 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 14 Aug 2019 10:12:39 +0100 Subject: [PATCH 25/26] i18n --- src/components/views/settings/SetIdServer.js | 2 +- src/i18n/strings/en_EN.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index 6c6b8faab2..398e578e8d 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -157,7 +157,7 @@ export default class SetIdServer extends React.Component { description:
{_t( - "Disconnect from the identity server ?", {}, + "Disconnect from the identity server ?", {}, {idserver: sub => {abbreviateUrl(this.state.currentClientIdServer)}}, )},
, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 3d5ee588ef..e5ecc2bf19 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -543,14 +543,14 @@ "Not a valid Identity Server (status code %(code)s)": "Not a valid Identity Server (status code %(code)s)", "Could not connect to Identity Server": "Could not connect to Identity Server", "Checking server": "Checking server", - "Disconnect ID Server": "Disconnect ID Server", - "Disconnect from the ID Server ?": "Disconnect from the ID Server ?", + "Disconnect Identity Server": "Disconnect Identity Server", + "Disconnect from the identity server ?": "Disconnect from the identity server ?", "Disconnect": "Disconnect", "Identity Server (%(server)s)": "Identity Server (%(server)s)", "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.", "Identity Server": "Identity Server", "You are not currently using an identity server. To discover and be discoverable by existing contacts you know, add one below.": "You are not currently using an identity server. To discover and be discoverable by existing contacts you know, add one below.", - "Disconnecting from your identity server will mean you won’t be discoverable by other users and you won’t be able to invite others by email or phone.": "Disconnecting from your identity server will mean you won’t be discoverable by other users and you won’t be able to invite others by email or phone.", + "Disconnecting from your identity server will mean you won't be discoverable by other users and you won't be able to invite others by email or phone.": "Disconnecting from your identity server will mean you won't be discoverable by other users and you won't be able to invite others by email or phone.", "Change": "Change", "Flair": "Flair", "Failed to change password. Is your password correct?": "Failed to change password. Is your password correct?", From e668b2f8bd7eb888e4794f4d2f0388c1eab0be18 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 14 Aug 2019 12:29:48 +0100 Subject: [PATCH 26/26] delint languageHandler Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/languageHandler.js | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index e7f6ee1f84..c129f801a1 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -50,7 +50,6 @@ src/components/views/settings/Notifications.js src/GroupAddressPicker.js src/HtmlUtils.js src/ImageUtils.js -src/languageHandler.js src/linkify-matrix.js src/Markdown.js src/MatrixClientPeg.js diff --git a/src/languageHandler.js b/src/languageHandler.js index c1a426383b..474cd2b3cd 100644 --- a/src/languageHandler.js +++ b/src/languageHandler.js @@ -2,6 +2,7 @@ Copyright 2017 MTRNord and Cooperative EITA Copyright 2017 Vector Creations Ltd. Copyright 2019 The Matrix.org Foundation C.I.C. +Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -102,7 +103,7 @@ function safeCounterpartTranslate(text, options) { * @return a React component if any non-strings were used in substitutions, otherwise a string */ export function _t(text, variables, tags) { - // Don't do subsitutions in counterpart. We handle it ourselves so we can replace with React components + // Don't do substitutions in counterpart. We handle it ourselves so we can replace with React components // However, still pass the variables to counterpart so that it can choose the correct plural if count is given // It is enough to pass the count variable, but in the future counterpart might make use of other information too const args = Object.assign({ interpolate: false }, variables); @@ -289,7 +290,7 @@ export function setLanguage(preferredLangs) { console.log("set language to " + langToUse); // Set 'en' as fallback language: - if (langToUse != "en") { + if (langToUse !== "en") { return getLanguage(i18nFolder + availLangs['en'].fileName); } }).then((langData) => { @@ -329,13 +330,13 @@ export function getLanguagesFromBrowser() { */ export function getNormalizedLanguageKeys(language) { const languageKeys = []; - const normalizedLanguage = this.normalizeLanguageKey(language); + const normalizedLanguage = normalizeLanguageKey(language); const languageParts = normalizedLanguage.split('-'); - if (languageParts.length == 2 && languageParts[0] == languageParts[1]) { + if (languageParts.length === 2 && languageParts[0] === languageParts[1]) { languageKeys.push(languageParts[0]); } else { languageKeys.push(normalizedLanguage); - if (languageParts.length == 2) { + if (languageParts.length === 2) { languageKeys.push(languageParts[0]); } } @@ -345,6 +346,9 @@ export function getNormalizedLanguageKeys(language) { /** * Returns a language string with underscores replaced with * hyphens, and lowercased. + * + * @param {string} language The language string to be normalized + * @returns {string} The normalized language string */ export function normalizeLanguageKey(language) { return language.toLowerCase().replace("_", "-"); @@ -373,8 +377,8 @@ export function pickBestLanguage(langs) { } { - // Failing that, a different dialect of the same lnguage - const closeLangIndex = normalisedLangs.find((l) => l.substr(0,2) === currentLang.substr(0,2)); + // Failing that, a different dialect of the same language + const closeLangIndex = normalisedLangs.find((l) => l.substr(0, 2) === currentLang.substr(0, 2)); if (closeLangIndex > -1) return langs[closeLangIndex]; }