Re-write as full class component
So we can re-use the functions we pass to propspull/21833/head
parent
522dddbd13
commit
8fbb0607ff
|
@ -47,7 +47,7 @@
|
||||||
"start:init": "babel src -d lib --source-maps --copy-files",
|
"start:init": "babel src -d lib --source-maps --copy-files",
|
||||||
"lint": "eslint src/",
|
"lint": "eslint src/",
|
||||||
"lintall": "eslint src/ test/",
|
"lintall": "eslint src/ test/",
|
||||||
"lintwithexclusions": "eslint --max-warnings 20 --ignore-path .eslintignore.errorfiles src test",
|
"lintwithexclusions": "eslint --max-warnings 16 --ignore-path .eslintignore.errorfiles src test",
|
||||||
"clean": "rimraf lib",
|
"clean": "rimraf lib",
|
||||||
"prepublish": "npm run clean && npm run build && git rev-parse HEAD > git-revision.txt",
|
"prepublish": "npm run clean && npm run build && git rev-parse HEAD > git-revision.txt",
|
||||||
"test": "karma start --single-run=true --browsers ChromeHeadless",
|
"test": "karma start --single-run=true --browsers ChromeHeadless",
|
||||||
|
|
|
@ -22,132 +22,143 @@ import { _t } from '../../../languageHandler';
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
import SettingsStore from "../../../settings/SettingsStore";
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
|
|
||||||
export default (props) => {
|
export default class LogoutDialog extends React.Component {
|
||||||
const onSettingsLinkClick = () => {
|
constructor() {
|
||||||
// close dialog
|
super();
|
||||||
if (props.onFinished) {
|
this._onSettingsLinkClick = this._onSettingsLinkClick.bind(this);
|
||||||
props.onFinished();
|
this._onExportE2eKeysClicked = this._onExportE2eKeysClicked.bind(this);
|
||||||
}
|
this._onFinished = this._onFinished.bind(this);
|
||||||
};
|
this._onSetRecoveryMethodClick = this._onSetRecoveryMethodClick.bind(this);
|
||||||
|
this._onLogoutConfirm = this._onLogoutConfirm.bind(this);
|
||||||
let description;
|
|
||||||
if (SettingsStore.isFeatureEnabled("feature_keybackup")) {
|
|
||||||
description = <div>
|
|
||||||
<p>{_t(
|
|
||||||
"When you log out, you'll lose your secure message history. To prevent " +
|
|
||||||
"this, set up a recovery method.",
|
|
||||||
)}</p>
|
|
||||||
<p>{_t(
|
|
||||||
"Alternatively, advanced users can also manually export encryption keys in " +
|
|
||||||
"<a>Settings</a> before logging out.", {},
|
|
||||||
{
|
|
||||||
a: sub => <a href='#/settings' onClick={onSettingsLinkClick}>{sub}</a>,
|
|
||||||
},
|
|
||||||
)}</p>
|
|
||||||
</div>;
|
|
||||||
} else {
|
|
||||||
description = <div>{_t(
|
|
||||||
"For security, logging out will delete any end-to-end " +
|
|
||||||
"encryption keys from this browser. If you want to be able " +
|
|
||||||
"to decrypt your conversation history from future Riot sessions, " +
|
|
||||||
"please export your room keys for safe-keeping.",
|
|
||||||
)}</div>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const onExportE2eKeysClicked = () => {
|
_onSettingsLinkClick() {
|
||||||
|
// close dialog
|
||||||
|
if (this.props.onFinished) {
|
||||||
|
this.props.onFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onExportE2eKeysClicked() {
|
||||||
Modal.createTrackedDialogAsync('Export E2E Keys', '',
|
Modal.createTrackedDialogAsync('Export E2E Keys', '',
|
||||||
import('../../../async-components/views/dialogs/ExportE2eKeysDialog'),
|
import('../../../async-components/views/dialogs/ExportE2eKeysDialog'),
|
||||||
{
|
{
|
||||||
matrixClient: MatrixClientPeg.get(),
|
matrixClient: MatrixClientPeg.get(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
const onFinished = (confirmed) => {
|
_onFinished(confirmed) {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
dis.dispatch({action: 'logout'});
|
dis.dispatch({action: 'logout'});
|
||||||
}
|
}
|
||||||
// close dialog
|
// close dialog
|
||||||
if (props.onFinished) {
|
if (this.props.onFinished) {
|
||||||
props.onFinished();
|
this.props.onFinished();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const onSetRecoveryMethodClick = () => {
|
_onSetRecoveryMethodClick() {
|
||||||
Modal.createTrackedDialogAsync('Key Backup', 'Key Backup',
|
Modal.createTrackedDialogAsync('Key Backup', 'Key Backup',
|
||||||
import('../../../async-components/views/dialogs/keybackup/CreateKeyBackupDialog'),
|
import('../../../async-components/views/dialogs/keybackup/CreateKeyBackupDialog'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// close dialog
|
// close dialog
|
||||||
if (props.onFinished) {
|
if (this.props.onFinished) {
|
||||||
props.onFinished();
|
this.props.onFinished();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const onLogoutConfirm = () => {
|
_onLogoutConfirm() {
|
||||||
dis.dispatch({action: 'logout'});
|
dis.dispatch({action: 'logout'});
|
||||||
|
|
||||||
// close dialog
|
// close dialog
|
||||||
if (props.onFinished) {
|
if (this.props.onFinished) {
|
||||||
props.onFinished();
|
this.props.onFinished();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
if (SettingsStore.isFeatureEnabled("feature_keybackup")) {
|
render() {
|
||||||
if (!MatrixClientPeg.get().getKeyBackupEnabled()) {
|
let description;
|
||||||
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
if (SettingsStore.isFeatureEnabled("feature_keybackup")) {
|
||||||
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
description = <div>
|
||||||
// Not quite a standard question dialog as the primary button cancels
|
<p>{_t(
|
||||||
// the action and does something else instead, whilst non-default button
|
"When you log out, you'll lose your secure message history. To prevent " +
|
||||||
// confirms the action.
|
"this, set up a recovery method.",
|
||||||
return (<BaseDialog
|
)}</p>
|
||||||
title={_t("Warning!")}
|
<p>{_t(
|
||||||
contentId='mx_Dialog_content'
|
"Alternatively, advanced users can also manually export encryption keys in " +
|
||||||
hasCancel={false}
|
"<a>Settings</a> before logging out.", {},
|
||||||
onFinsihed={onFinished}
|
{
|
||||||
>
|
a: sub => <a href='#/settings' onClick={this._onSettingsLinkClick}>{sub}</a>,
|
||||||
<div className="mx_Dialog_content" id='mx_Dialog_content'>
|
},
|
||||||
{ description }
|
)}</p>
|
||||||
</div>
|
</div>;
|
||||||
<DialogButtons primaryButton={_t('Set a Recovery Method')}
|
} else {
|
||||||
|
description = <div>{_t(
|
||||||
|
"For security, logging out will delete any end-to-end " +
|
||||||
|
"encryption keys from this browser. If you want to be able " +
|
||||||
|
"to decrypt your conversation history from future Riot sessions, " +
|
||||||
|
"please export your room keys for safe-keeping.",
|
||||||
|
)}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SettingsStore.isFeatureEnabled("feature_keybackup")) {
|
||||||
|
if (!MatrixClientPeg.get().getKeyBackupEnabled()) {
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
||||||
|
// Not quite a standard question dialog as the primary button cancels
|
||||||
|
// the action and does something else instead, whilst non-default button
|
||||||
|
// confirms the action.
|
||||||
|
return (<BaseDialog
|
||||||
|
title={_t("Warning!")}
|
||||||
|
contentId='mx_Dialog_content'
|
||||||
hasCancel={false}
|
hasCancel={false}
|
||||||
onPrimaryButtonClick={onSetRecoveryMethodClick}
|
onFinsihed={this._onFinished}
|
||||||
focus={true}
|
|
||||||
>
|
>
|
||||||
<button onClick={onLogoutConfirm}>
|
<div className="mx_Dialog_content" id='mx_Dialog_content'>
|
||||||
{_t("I understand, log out without")}
|
{ description }
|
||||||
</button>
|
</div>
|
||||||
</DialogButtons>
|
<DialogButtons primaryButton={_t('Set a Recovery Method')}
|
||||||
</BaseDialog>);
|
hasCancel={false}
|
||||||
|
onPrimaryButtonClick={this._onSetRecoveryMethodClick}
|
||||||
|
focus={true}
|
||||||
|
>
|
||||||
|
<button onClick={this._onLogoutConfirm}>
|
||||||
|
{_t("I understand, log out without")}
|
||||||
|
</button>
|
||||||
|
</DialogButtons>
|
||||||
|
</BaseDialog>);
|
||||||
|
} else {
|
||||||
|
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
|
||||||
|
return (<QuestionDialog
|
||||||
|
hasCancelButton={true}
|
||||||
|
title={_t("Sign out")}
|
||||||
|
// TODO: This is made up by me and would need to also mention verifying
|
||||||
|
// once you can restorew a backup by verifying a device
|
||||||
|
description={_t(
|
||||||
|
"When signing in again, you can access encrypted chat history by " +
|
||||||
|
"restoring your key backup. You'll need your recovery key.",
|
||||||
|
)}
|
||||||
|
button={_t("Sign out")}
|
||||||
|
onFinished={this._onFinished}
|
||||||
|
/>);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
|
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
|
||||||
return (<QuestionDialog
|
return (<QuestionDialog
|
||||||
hasCancelButton={true}
|
hasCancelButton={true}
|
||||||
title={_t("Sign out")}
|
title={_t("Sign out")}
|
||||||
// TODO: This is made up by me and would need to also mention verifying
|
description={description}
|
||||||
// once you can restorew a backup by verifying a device
|
|
||||||
description={_t(
|
|
||||||
"When signing in again, you can access encrypted chat history by " +
|
|
||||||
"restoring your key backup. You'll need your recovery key.",
|
|
||||||
)}
|
|
||||||
button={_t("Sign out")}
|
button={_t("Sign out")}
|
||||||
onFinished={onFinished}
|
extraButtons={[
|
||||||
|
(<button key="export" className="mx_Dialog_primary"
|
||||||
|
onClick={this._onExportE2eKeysClicked}>
|
||||||
|
{ _t("Export E2E room keys") }
|
||||||
|
</button>),
|
||||||
|
]}
|
||||||
|
onFinished={this._onFinished}
|
||||||
/>);
|
/>);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
|
|
||||||
return (<QuestionDialog
|
|
||||||
hasCancelButton={true}
|
|
||||||
title={_t("Sign out")}
|
|
||||||
description={description}
|
|
||||||
button={_t("Sign out")}
|
|
||||||
extraButtons={[
|
|
||||||
(<button key="export" className="mx_Dialog_primary"
|
|
||||||
onClick={onExportE2eKeysClicked}>
|
|
||||||
{ _t("Export E2E room keys") }
|
|
||||||
</button>),
|
|
||||||
]}
|
|
||||||
onFinished={onFinished}
|
|
||||||
/>);
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
Loading…
Reference in New Issue