From be50f803145455aa37d25fc95478c67348c12771 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 24 Mar 2020 19:02:57 +0000 Subject: [PATCH] Wait for SSSS upgrade to complete and show a spinner while it completes --- src/DeviceListener.js | 2 +- .../views/toasts/SetupEncryptionToast.js | 38 ++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/DeviceListener.js b/src/DeviceListener.js index 7878a1a670..0151a45c18 100644 --- a/src/DeviceListener.js +++ b/src/DeviceListener.js @@ -169,7 +169,7 @@ export default class DeviceListener { key: THIS_DEVICE_TOAST_KEY, title: _t("Encryption upgrade available"), icon: "verification_warning", - props: {kind: 'upgrade_encryption'}, + props: {kind: 'upgrade_ssss'}, component: sdk.getComponent("toasts.SetupEncryptionToast"), }); } else { diff --git a/src/components/views/toasts/SetupEncryptionToast.js b/src/components/views/toasts/SetupEncryptionToast.js index 9016e4c6d7..f25d8fd506 100644 --- a/src/components/views/toasts/SetupEncryptionToast.js +++ b/src/components/views/toasts/SetupEncryptionToast.js @@ -16,6 +16,8 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; +import Modal from '../../../Modal'; +import { MatrixClientPeg } from '../../../MatrixClientPeg'; import * as sdk from "../../../index"; import { _t } from '../../../languageHandler'; import DeviceListener from '../../../DeviceListener'; @@ -24,21 +26,52 @@ import { accessSecretStorage } from '../../../CrossSigningManager'; export default class SetupEncryptionToast extends React.PureComponent { static propTypes = { toastKey: PropTypes.string.isRequired, - kind: PropTypes.oneOf(['set_up_encryption', 'verify_this_session', 'upgrade_encryption']).isRequired, + kind: PropTypes.oneOf([ + 'set_up_encryption', + 'verify_this_session', + 'upgrade_encryption', + 'upgrade_ssss', + ]).isRequired, }; _onLaterClick = () => { DeviceListener.sharedInstance().dismissEncryptionSetup(); }; + async _waitForCompletion() { + if (this.props.kind === 'upgrade_ssss') { + return new Promise(resolve => { + const recheck = async () => { + const needsUpgrade = await MatrixClientPeg.get().secretStorageKeyNeedsUpgrade(); + if (!needsUpgrade) { + MatrixClientPeg.get().removeListener('accountData', recheck); + resolve(); + } + }; + MatrixClientPeg.get().on('accountData', recheck); + recheck(); + }); + } else { + return; + } + } + _onSetupClick = async () => { - accessSecretStorage(); + const Spinner = sdk.getComponent("elements.Spinner"); + const modal = Modal.createDialog(Spinner, null, 'mx_Dialog_spinner'); + try { + await accessSecretStorage(); + await this._waitForCompletion(); + } finally { + modal.close(); + } }; getDescription() { switch (this.props.kind) { case 'set_up_encryption': case 'upgrade_encryption': + case 'upgrade_ssss': return _t('Verify yourself & others to keep your chats safe'); case 'verify_this_session': return _t('Other users may not trust it'); @@ -49,6 +82,7 @@ export default class SetupEncryptionToast extends React.PureComponent { switch (this.props.kind) { case 'set_up_encryption': case 'upgrade_encryption': + case 'upgrade_ssss': return _t('Upgrade'); case 'verify_this_session': return _t('Verify');