From 308a6b419e666c19af9dd3a67ccaee7b11c3dbc2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Aug 2018 16:56:02 +0200 Subject: [PATCH 01/13] allow a setting controller to validate and revert a change (asynchronously) --- src/components/structures/UserSettings.js | 6 +++--- src/settings/SettingsStore.js | 20 ++++++++++++++----- src/settings/controllers/SettingController.js | 4 ++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index d02d8b23e5..701247bd8b 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -844,8 +844,8 @@ module.exports = React.createClass({ SettingsStore.getLabsFeatures().forEach((featureId) => { // TODO: this ought to be a separate component so that we don't need // to rebind the onChange each time we render - const onChange = (e) => { - SettingsStore.setFeatureEnabled(featureId, e.target.checked); + const onChange = async (e) => { + await SettingsStore.setFeatureEnabled(featureId, e.target.checked); this.forceUpdate(); }; @@ -855,7 +855,7 @@ module.exports = React.createClass({ type="checkbox" id={featureId} name={featureId} - defaultChecked={SettingsStore.isFeatureEnabled(featureId)} + checked={SettingsStore.isFeatureEnabled(featureId)} onChange={onChange} /> diff --git a/src/settings/SettingsStore.js b/src/settings/SettingsStore.js index a1b88fb0c2..1da882577f 100644 --- a/src/settings/SettingsStore.js +++ b/src/settings/SettingsStore.js @@ -260,7 +260,7 @@ export default class SettingsStore { * @param {*} value The new value of the setting, may be null. * @return {Promise} Resolves when the setting has been changed. */ - static setValue(settingName, roomId, level, value) { + static async setValue(settingName, roomId, level, value) { // Verify that the setting is actually a setting if (!SETTINGS[settingName]) { throw new Error("Setting '" + settingName + "' does not appear to be a setting."); @@ -275,11 +275,21 @@ export default class SettingsStore { throw new Error("User cannot set " + settingName + " at " + level + " in " + roomId); } - return handler.setValue(settingName, roomId, value).then(() => { - const controller = SETTINGS[settingName].controller; - if (!controller) return; + const controller = SETTINGS[settingName].controller; + if (controller) { + const changeAllowed = await controller.canChangeTo(level, roomId, value); + if (!changeAllowed) { + return false; + } + } + + await handler.setValue(settingName, roomId, value); + + if (controller) { controller.onChange(level, roomId, value); - }); + } + + return true; } /** diff --git a/src/settings/controllers/SettingController.js b/src/settings/controllers/SettingController.js index 0ebe0042e6..6b09c4fc53 100644 --- a/src/settings/controllers/SettingController.js +++ b/src/settings/controllers/SettingController.js @@ -39,6 +39,10 @@ export default class SettingController { return null; // no override } + canChangeTo(level, roomId, newValue) { + return Promise.resolve(true); + } + /** * Called when the setting value has been changed. * @param {string} level The level at which the setting has been modified. From 028f09e5d15a223f87d564318dee98ee9b43db4f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Aug 2018 18:39:55 +0200 Subject: [PATCH 02/13] lazy loading settings controller to show dialog and export e2e keys --- .../controllers/LazyLoadingController.js | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/settings/controllers/LazyLoadingController.js diff --git a/src/settings/controllers/LazyLoadingController.js b/src/settings/controllers/LazyLoadingController.js new file mode 100644 index 0000000000..506a1c7f2b --- /dev/null +++ b/src/settings/controllers/LazyLoadingController.js @@ -0,0 +1,66 @@ +/* +Copyright 2018 New Vector + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import SettingsStore from "../SettingsStore"; +import SettingController from "./SettingController"; +import Modal from "../../Modal"; +import sdk from "../../index"; +import MatrixClientPeg from "../../MatrixClientPeg"; +import dis from "../../dispatcher"; +import { _t } from "../../languageHandler"; + +export default class LazyLoadingController extends SettingController { + onChange(level, roomId, newValue) { + dis.dispatch({action: 'flush_storage_reload'}); + } + + canChangeTo(level, roomId, newValue) { + return new Promise((resolve) => this._showReloadDialog(resolve)); + } + + _showReloadDialog(onFinished) { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + Modal.createDialog(QuestionDialog, { + title: _t("Turn on/off lazy load members"), + description: +
+ { _t("To enable or disable the lazy loading of members, " + + "the current synced state needs to be cleared out. " + + "This also includes your end-to-end encryption keys, " + + "so to keep being able to decrypt all your existing encrypted messages, " + + "you'll need to export your E2E room keys and import them again afterwards.") } +
, + button: _t("Clear sync state and reload"), + extraButtons: [ + , + ], + onFinished, + }); + } + + _onExportE2eKeysClicked() { + Modal.createTrackedDialogAsync('Export E2E Keys', '', (cb) => { + require.ensure(['../../async-components/views/dialogs/ExportE2eKeysDialog'], () => { + cb(require('../../async-components/views/dialogs/ExportE2eKeysDialog')); + }, "e2e-export"); + }, { + matrixClient: MatrixClientPeg.get(), + }); + } +} From a02e1aa2b240c2f0d25018207e76e7106661649d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Aug 2018 18:41:18 +0200 Subject: [PATCH 03/13] add action/method to flush storage and reload the session --- src/Lifecycle.js | 29 +++++++++++++++++++++++++ src/components/structures/MatrixChat.js | 8 +++++++ 2 files changed, 37 insertions(+) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index f32f105889..4d62e6bb46 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -499,3 +499,32 @@ export function stopMatrixClient() { MatrixClientPeg.unset(); } } +/** + * Clears indexeddb storage and reloads the session + * localStorage is preserved. + */ +export async function flushStorageAndReload() { + // gather the credentials from localStorage as + // MatrixClient.credentials only contains the userId + // (gets cleared somewhere probably) + // this just does the reverse of _persistCredentialsToLocalStorage + const credentials = { + homeserverUrl: localStorage.getItem("mx_hs_url"), + identityServerUrl: localStorage.getItem("mx_is_url"), + userId: localStorage.getItem("mx_user_id"), + accessToken: localStorage.getItem("mx_access_token"), + guest: JSON.parse(localStorage.getItem("mx_is_guest")), + deviceId: localStorage.getItem("mx_device_id"), + }; + // stop the client so it's not running anymore + stopMatrixClient(); + // create a temporary client to clear out the persistent stores. + const cli = createMatrixClient({ + // we'll never make any requests, so can pass a bogus HS URL + baseUrl: "", + }); + // clear indexeddb + await cli.clearStores(); + // start the session again without clearing storage + _doSetLoggedIn(credentials, false); +} \ No newline at end of file diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index e0bbf50d5a..dc2c1cb90b 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -479,6 +479,14 @@ export default React.createClass({ case 'logout': Lifecycle.logout(); break; + case 'flush_storage_reload': + // flushStorageAndReload will dispatch actions + // which we can't do in a dispatch handler + // so yield first + setTimeout(() => { + Lifecycle.flushStorageAndReload(); + }, 0); + break; case 'start_registration': this._startRegistration(payload.params || {}); break; From 3731431e59387423c0c019fd638d8d280c6f2018 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Aug 2018 18:41:41 +0200 Subject: [PATCH 04/13] use LL controller in setting --- src/settings/Settings.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/settings/Settings.js b/src/settings/Settings.js index d76c1fd8e8..76e002adac 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -21,7 +21,7 @@ import { NotificationBodyEnabledController, NotificationsEnabledController, } from "./controllers/NotificationControllers"; - +import LazyLoadingController from "./controllers/LazyLoadingController"; // These are just a bunch of helper arrays to avoid copy/pasting a bunch of times const LEVELS_ROOM_SETTINGS = ['device', 'room-device', 'room-account', 'account', 'config']; @@ -87,6 +87,8 @@ export const SETTINGS = { isFeature: true, displayName: _td("Increase performance by loading room members on first view"), supportedLevels: LEVELS_FEATURE, + controller: new LazyLoadingController(), + default: false, }, "MessageComposerInput.dontSuggestEmoji": { supportedLevels: LEVELS_ACCOUNT_SETTINGS, From 28292c338873c4eb91aacd3b68ff80c7a23e28d5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 11:14:30 +0200 Subject: [PATCH 05/13] implement PR feedback, move LL dialog to UserSettings --- src/components/structures/UserSettings.js | 35 +++++++++++++++++- src/settings/SettingsStore.js | 11 +----- .../controllers/LazyLoadingController.js | 37 ------------------- src/settings/controllers/SettingController.js | 5 --- 4 files changed, 35 insertions(+), 53 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 701247bd8b..a5ba4ff0fa 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -845,7 +845,15 @@ module.exports = React.createClass({ // TODO: this ought to be a separate component so that we don't need // to rebind the onChange each time we render const onChange = async (e) => { - await SettingsStore.setFeatureEnabled(featureId, e.target.checked); + const checked = e.target.checked; + if (featureId === "feature_lazyloading") { + const confirmed = await this._onLazyLoadChanging(); + if (!confirmed) { + e.preventDefault(); + return; + } + } + await SettingsStore.setFeatureEnabled(featureId, checked); this.forceUpdate(); }; @@ -878,6 +886,31 @@ module.exports = React.createClass({ ); }, + _onLazyLoadChanging: function() { + return new Promise((resolve) => { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + Modal.createDialog(QuestionDialog, { + title: _t("Turn on/off lazy load members"), + description: +
+ { _t("To enable or disable the lazy loading of members, " + + "the current synced state needs to be cleared out. " + + "This also includes your end-to-end encryption keys, " + + "so to keep being able to decrypt all your existing encrypted messages, " + + "you'll need to export your E2E room keys and import them again afterwards.") } +
, + button: _t("Clear sync state and reload"), + extraButtons: [ + , + ], + onFinished: resolve, + }); + }); + }, + _renderDeactivateAccount: function() { return

{ _t("Deactivate Account") }

diff --git a/src/settings/SettingsStore.js b/src/settings/SettingsStore.js index 1da882577f..76dd89a7f7 100644 --- a/src/settings/SettingsStore.js +++ b/src/settings/SettingsStore.js @@ -275,21 +275,12 @@ export default class SettingsStore { throw new Error("User cannot set " + settingName + " at " + level + " in " + roomId); } - const controller = SETTINGS[settingName].controller; - if (controller) { - const changeAllowed = await controller.canChangeTo(level, roomId, value); - if (!changeAllowed) { - return false; - } - } - await handler.setValue(settingName, roomId, value); + const controller = SETTINGS[settingName].controller; if (controller) { controller.onChange(level, roomId, value); } - - return true; } /** diff --git a/src/settings/controllers/LazyLoadingController.js b/src/settings/controllers/LazyLoadingController.js index 506a1c7f2b..5d592ad6f8 100644 --- a/src/settings/controllers/LazyLoadingController.js +++ b/src/settings/controllers/LazyLoadingController.js @@ -26,41 +26,4 @@ export default class LazyLoadingController extends SettingController { onChange(level, roomId, newValue) { dis.dispatch({action: 'flush_storage_reload'}); } - - canChangeTo(level, roomId, newValue) { - return new Promise((resolve) => this._showReloadDialog(resolve)); - } - - _showReloadDialog(onFinished) { - const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); - Modal.createDialog(QuestionDialog, { - title: _t("Turn on/off lazy load members"), - description: -
- { _t("To enable or disable the lazy loading of members, " + - "the current synced state needs to be cleared out. " + - "This also includes your end-to-end encryption keys, " + - "so to keep being able to decrypt all your existing encrypted messages, " + - "you'll need to export your E2E room keys and import them again afterwards.") } -
, - button: _t("Clear sync state and reload"), - extraButtons: [ - , - ], - onFinished, - }); - } - - _onExportE2eKeysClicked() { - Modal.createTrackedDialogAsync('Export E2E Keys', '', (cb) => { - require.ensure(['../../async-components/views/dialogs/ExportE2eKeysDialog'], () => { - cb(require('../../async-components/views/dialogs/ExportE2eKeysDialog')); - }, "e2e-export"); - }, { - matrixClient: MatrixClientPeg.get(), - }); - } } diff --git a/src/settings/controllers/SettingController.js b/src/settings/controllers/SettingController.js index 6b09c4fc53..9dcb6259b5 100644 --- a/src/settings/controllers/SettingController.js +++ b/src/settings/controllers/SettingController.js @@ -38,11 +38,6 @@ export default class SettingController { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) { return null; // no override } - - canChangeTo(level, roomId, newValue) { - return Promise.resolve(true); - } - /** * Called when the setting value has been changed. * @param {string} level The level at which the setting has been modified. From 09ad138306ae89b032ff32313c6874b652de252e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 11:16:29 +0200 Subject: [PATCH 06/13] remove unused imports --- src/settings/controllers/LazyLoadingController.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/settings/controllers/LazyLoadingController.js b/src/settings/controllers/LazyLoadingController.js index 5d592ad6f8..334111ef7c 100644 --- a/src/settings/controllers/LazyLoadingController.js +++ b/src/settings/controllers/LazyLoadingController.js @@ -14,13 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import SettingsStore from "../SettingsStore"; import SettingController from "./SettingController"; -import Modal from "../../Modal"; -import sdk from "../../index"; -import MatrixClientPeg from "../../MatrixClientPeg"; import dis from "../../dispatcher"; -import { _t } from "../../languageHandler"; export default class LazyLoadingController extends SettingController { onChange(level, roomId, newValue) { From 2f9aaeca465063364d182d1568c1ce2de80625bc Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 11:17:04 +0200 Subject: [PATCH 07/13] undo whitespace change --- src/settings/controllers/SettingController.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/settings/controllers/SettingController.js b/src/settings/controllers/SettingController.js index 9dcb6259b5..0ebe0042e6 100644 --- a/src/settings/controllers/SettingController.js +++ b/src/settings/controllers/SettingController.js @@ -38,6 +38,7 @@ export default class SettingController { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) { return null; // no override } + /** * Called when the setting value has been changed. * @param {string} level The level at which the setting has been modified. From 94c424d3bb495f271a7ba00a4538b09dfb3e37bc Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 11:24:32 +0200 Subject: [PATCH 08/13] translations --- src/i18n/strings/en_EN.json | 6 +++++- src/settings/Settings.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 9acde2b80c..f1f056f58e 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1216,5 +1216,9 @@ "Import": "Import", "Failed to set direct chat tag": "Failed to set direct chat tag", "Failed to remove tag %(tagName)s from room": "Failed to remove tag %(tagName)s from room", - "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room" + "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room", + "Increase performance by only loading room members on first view": "Increase performance by only loading room members on first view", + "Turn on/off lazy load members": "Turn on/off lazy load members", + "To enable or disable the lazy loading of members, the current synced state needs to be cleared out. This also includes your end-to-end encryption keys, so to keep being able to decrypt all your existing encrypted messages, you'll need to export your E2E room keys and import them again afterwards.": "To enable or disable the lazy loading of members, the current synced state needs to be cleared out. This also includes your end-to-end encryption keys, so to keep being able to decrypt all your existing encrypted messages, you'll need to export your E2E room keys and import them again afterwards.", + "Clear sync state and reload": "Clear sync state and reload" } diff --git a/src/settings/Settings.js b/src/settings/Settings.js index 76e002adac..0594c63eb9 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -85,7 +85,7 @@ export const SETTINGS = { }, "feature_lazyloading": { isFeature: true, - displayName: _td("Increase performance by loading room members on first view"), + displayName: _td("Increase performance by only loading room members on first view"), supportedLevels: LEVELS_FEATURE, controller: new LazyLoadingController(), default: false, From 84b74247e625cc7bbab36db7caca38a18db403b4 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 16:19:44 +0200 Subject: [PATCH 09/13] check if server supports lazy loading before enabling --- src/components/structures/UserSettings.js | 28 +++++++++++++++++++---- src/i18n/strings/en_EN.json | 4 +++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index a5ba4ff0fa..157540f183 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -847,7 +847,7 @@ module.exports = React.createClass({ const onChange = async (e) => { const checked = e.target.checked; if (featureId === "feature_lazyloading") { - const confirmed = await this._onLazyLoadChanging(); + const confirmed = await this._onLazyLoadChanging(checked); if (!confirmed) { e.preventDefault(); return; @@ -886,9 +886,28 @@ module.exports = React.createClass({ ); }, - _onLazyLoadChanging: function() { - return new Promise((resolve) => { - const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + _onLazyLoadChanging: async function(enabling) { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + // don't prevent turning LL off when not supported + if (enabling) { + const supported = await MatrixClientPeg.get().doesServerSupportLazyLoading(); + if (!supported) { + await new Promise((resolve) => { + Modal.createDialog(QuestionDialog, { + title: _t("Lazy loading members not supported"), + description: +
+ { _t("Lazy loading is not supported by your " + + "current homeserver.") } +
, + button: _t("OK"), + onFinished: resolve, + }); + }); + return false; + } + } + const confirmed = await new Promise((resolve) => { Modal.createDialog(QuestionDialog, { title: _t("Turn on/off lazy load members"), description: @@ -909,6 +928,7 @@ module.exports = React.createClass({ onFinished: resolve, }); }); + return confirmed; }, _renderDeactivateAccount: function() { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index f1f056f58e..eb05ff36e7 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1220,5 +1220,7 @@ "Increase performance by only loading room members on first view": "Increase performance by only loading room members on first view", "Turn on/off lazy load members": "Turn on/off lazy load members", "To enable or disable the lazy loading of members, the current synced state needs to be cleared out. This also includes your end-to-end encryption keys, so to keep being able to decrypt all your existing encrypted messages, you'll need to export your E2E room keys and import them again afterwards.": "To enable or disable the lazy loading of members, the current synced state needs to be cleared out. This also includes your end-to-end encryption keys, so to keep being able to decrypt all your existing encrypted messages, you'll need to export your E2E room keys and import them again afterwards.", - "Clear sync state and reload": "Clear sync state and reload" + "Clear sync state and reload": "Clear sync state and reload", + "Lazy loading members not supported": "Lazy load members not supported", + "Lazy loading is not supported by your current homeserver.": "Lazy loading is not supported by your current homeserver." } From 3e9d1342e83aab8cb7c0b8b1d8558f8aa9192004 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 16:51:37 +0200 Subject: [PATCH 10/13] fix lint --- src/Lifecycle.js | 2 +- src/settings/SettingsStore.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 4d62e6bb46..4ae651d3bb 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -527,4 +527,4 @@ export async function flushStorageAndReload() { await cli.clearStores(); // start the session again without clearing storage _doSetLoggedIn(credentials, false); -} \ No newline at end of file +} diff --git a/src/settings/SettingsStore.js b/src/settings/SettingsStore.js index 76dd89a7f7..f17d47401e 100644 --- a/src/settings/SettingsStore.js +++ b/src/settings/SettingsStore.js @@ -248,7 +248,7 @@ export default class SettingsStore { if (actualValue !== undefined && actualValue !== null) return actualValue; return calculatedValue; } - + /* eslint-disable valid-jsdoc */ /** * Sets the value for a setting. The room ID is optional if the setting is not being * set for a particular room, otherwise it should be supplied. The value may be null @@ -260,6 +260,7 @@ export default class SettingsStore { * @param {*} value The new value of the setting, may be null. * @return {Promise} Resolves when the setting has been changed. */ + /* eslint-enable valid-jsdoc */ static async setValue(settingName, roomId, level, value) { // Verify that the setting is actually a setting if (!SETTINGS[settingName]) { From 08f322753dddf4cf408c24cdddde31250786359d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 16:53:16 +0200 Subject: [PATCH 11/13] explain exception --- src/settings/SettingsStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings/SettingsStore.js b/src/settings/SettingsStore.js index f17d47401e..cb6d83e884 100644 --- a/src/settings/SettingsStore.js +++ b/src/settings/SettingsStore.js @@ -248,7 +248,7 @@ export default class SettingsStore { if (actualValue !== undefined && actualValue !== null) return actualValue; return calculatedValue; } - /* eslint-disable valid-jsdoc */ + /* eslint-disable valid-jsdoc */ //https://github.com/eslint/eslint/issues/7307 /** * Sets the value for a setting. The room ID is optional if the setting is not being * set for a particular room, otherwise it should be supplied. The value may be null From 7dc92fe91729dea9782533747df4532cf79948f2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 13 Aug 2018 17:24:27 +0200 Subject: [PATCH 12/13] Avoid clearing e2e encryption keys, also avoid warning --- src/components/structures/UserSettings.js | 25 ++----------------- src/i18n/strings/en_EN.json | 3 --- .../controllers/LazyLoadingController.js | 11 +++++--- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 157540f183..f4dc92aca4 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -887,12 +887,12 @@ module.exports = React.createClass({ }, _onLazyLoadChanging: async function(enabling) { - const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); // don't prevent turning LL off when not supported if (enabling) { const supported = await MatrixClientPeg.get().doesServerSupportLazyLoading(); if (!supported) { await new Promise((resolve) => { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); Modal.createDialog(QuestionDialog, { title: _t("Lazy loading members not supported"), description: @@ -907,28 +907,7 @@ module.exports = React.createClass({ return false; } } - const confirmed = await new Promise((resolve) => { - Modal.createDialog(QuestionDialog, { - title: _t("Turn on/off lazy load members"), - description: -
- { _t("To enable or disable the lazy loading of members, " + - "the current synced state needs to be cleared out. " + - "This also includes your end-to-end encryption keys, " + - "so to keep being able to decrypt all your existing encrypted messages, " + - "you'll need to export your E2E room keys and import them again afterwards.") } -
, - button: _t("Clear sync state and reload"), - extraButtons: [ - , - ], - onFinished: resolve, - }); - }); - return confirmed; + return true; }, _renderDeactivateAccount: function() { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index eb05ff36e7..2926f4c87c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1218,9 +1218,6 @@ "Failed to remove tag %(tagName)s from room": "Failed to remove tag %(tagName)s from room", "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room", "Increase performance by only loading room members on first view": "Increase performance by only loading room members on first view", - "Turn on/off lazy load members": "Turn on/off lazy load members", - "To enable or disable the lazy loading of members, the current synced state needs to be cleared out. This also includes your end-to-end encryption keys, so to keep being able to decrypt all your existing encrypted messages, you'll need to export your E2E room keys and import them again afterwards.": "To enable or disable the lazy loading of members, the current synced state needs to be cleared out. This also includes your end-to-end encryption keys, so to keep being able to decrypt all your existing encrypted messages, you'll need to export your E2E room keys and import them again afterwards.", - "Clear sync state and reload": "Clear sync state and reload", "Lazy loading members not supported": "Lazy load members not supported", "Lazy loading is not supported by your current homeserver.": "Lazy loading is not supported by your current homeserver." } diff --git a/src/settings/controllers/LazyLoadingController.js b/src/settings/controllers/LazyLoadingController.js index 334111ef7c..90f095c9ca 100644 --- a/src/settings/controllers/LazyLoadingController.js +++ b/src/settings/controllers/LazyLoadingController.js @@ -15,10 +15,15 @@ limitations under the License. */ import SettingController from "./SettingController"; -import dis from "../../dispatcher"; +import MatrixClientPeg from "../../MatrixClientPeg"; +import PlatformPeg from "../../PlatformPeg"; export default class LazyLoadingController extends SettingController { - onChange(level, roomId, newValue) { - dis.dispatch({action: 'flush_storage_reload'}); + async onChange(level, roomId, newValue) { + if (!PlatformPeg.get()) return; + + MatrixClientPeg.get().stopClient(); + await MatrixClientPeg.get().store.deleteAllData(); + PlatformPeg.get().reload(); } } From a86ca952b3cac2370e4fd7cc5f370d93a34a8318 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 14 Aug 2018 09:38:43 +0200 Subject: [PATCH 13/13] forgot to remove this --- src/Lifecycle.js | 29 ------------------------- src/components/structures/MatrixChat.js | 8 ------- 2 files changed, 37 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 4ae651d3bb..f32f105889 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -499,32 +499,3 @@ export function stopMatrixClient() { MatrixClientPeg.unset(); } } -/** - * Clears indexeddb storage and reloads the session - * localStorage is preserved. - */ -export async function flushStorageAndReload() { - // gather the credentials from localStorage as - // MatrixClient.credentials only contains the userId - // (gets cleared somewhere probably) - // this just does the reverse of _persistCredentialsToLocalStorage - const credentials = { - homeserverUrl: localStorage.getItem("mx_hs_url"), - identityServerUrl: localStorage.getItem("mx_is_url"), - userId: localStorage.getItem("mx_user_id"), - accessToken: localStorage.getItem("mx_access_token"), - guest: JSON.parse(localStorage.getItem("mx_is_guest")), - deviceId: localStorage.getItem("mx_device_id"), - }; - // stop the client so it's not running anymore - stopMatrixClient(); - // create a temporary client to clear out the persistent stores. - const cli = createMatrixClient({ - // we'll never make any requests, so can pass a bogus HS URL - baseUrl: "", - }); - // clear indexeddb - await cli.clearStores(); - // start the session again without clearing storage - _doSetLoggedIn(credentials, false); -} diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index dc2c1cb90b..e0bbf50d5a 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -479,14 +479,6 @@ export default React.createClass({ case 'logout': Lifecycle.logout(); break; - case 'flush_storage_reload': - // flushStorageAndReload will dispatch actions - // which we can't do in a dispatch handler - // so yield first - setTimeout(() => { - Lifecycle.flushStorageAndReload(); - }, 0); - break; case 'start_registration': this._startRegistration(payload.params || {}); break;