Apply prettier formatting

This commit is contained in:
Michael Weimann 2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
No known key found for this signature in database
GPG key ID: 53F535A266BB9584
1576 changed files with 65385 additions and 62478 deletions

View file

@ -15,13 +15,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import FileSaver from 'file-saver';
import React from 'react';
import { MatrixClient } from 'matrix-js-sdk/src/client';
import FileSaver from "file-saver";
import React from "react";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from '../../../../languageHandler';
import * as MegolmExportEncryption from '../../../../utils/MegolmExportEncryption';
import { _t } from "../../../../languageHandler";
import * as MegolmExportEncryption from "../../../../utils/MegolmExportEncryption";
import { IDialogProps } from "../../../../components/views/dialogs/IDialogProps";
import BaseDialog from "../../../../components/views/dialogs/BaseDialog";
import Field from "../../../../components/views/elements/Field";
@ -68,11 +68,11 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
const passphrase = this.state.passphrase1;
if (passphrase !== this.state.passphrase2) {
this.setState({ errStr: _t('Passphrases must match') });
this.setState({ errStr: _t("Passphrases must match") });
return false;
}
if (!passphrase) {
this.setState({ errStr: _t('Passphrase must not be empty') });
this.setState({ errStr: _t("Passphrase must not be empty") });
return false;
}
@ -83,29 +83,31 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
private startExport(passphrase: string): void {
// extra Promise.resolve() to turn synchronous exceptions into
// asynchronous ones.
Promise.resolve().then(() => {
return this.props.matrixClient.exportRoomKeys();
}).then((k) => {
return MegolmExportEncryption.encryptMegolmKeyFile(
JSON.stringify(k), passphrase,
);
}).then((f) => {
const blob = new Blob([f], {
type: 'text/plain;charset=us-ascii',
Promise.resolve()
.then(() => {
return this.props.matrixClient.exportRoomKeys();
})
.then((k) => {
return MegolmExportEncryption.encryptMegolmKeyFile(JSON.stringify(k), passphrase);
})
.then((f) => {
const blob = new Blob([f], {
type: "text/plain;charset=us-ascii",
});
FileSaver.saveAs(blob, "element-keys.txt");
this.props.onFinished(true);
})
.catch((e) => {
logger.error("Error exporting e2e keys:", e);
if (this.unmounted) {
return;
}
const msg = e.friendlyText || _t("Unknown error");
this.setState({
errStr: msg,
phase: Phase.Edit,
});
});
FileSaver.saveAs(blob, 'element-keys.txt');
this.props.onFinished(true);
}).catch((e) => {
logger.error("Error exporting e2e keys:", e);
if (this.unmounted) {
return;
}
const msg = e.friendlyText || _t('Unknown error');
this.setState({
errStr: msg,
phase: Phase.Edit,
});
});
this.setState({
errStr: null,
@ -126,54 +128,53 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
};
public render(): JSX.Element {
const disableForm = (this.state.phase === Phase.Exporting);
const disableForm = this.state.phase === Phase.Exporting;
return (
<BaseDialog className='mx_exportE2eKeysDialog'
<BaseDialog
className="mx_exportE2eKeysDialog"
onFinished={this.props.onFinished}
title={_t("Export room keys")}
>
<form onSubmit={this.onPassphraseFormSubmit}>
<div className="mx_Dialog_content">
<p>
{ _t(
'This process allows you to export the keys for messages ' +
'you have received in encrypted rooms to a local file. You ' +
'will then be able to import the file into another Matrix ' +
'client in the future, so that client will also be able to ' +
'decrypt these messages.',
) }
{_t(
"This process allows you to export the keys for messages " +
"you have received in encrypted rooms to a local file. You " +
"will then be able to import the file into another Matrix " +
"client in the future, so that client will also be able to " +
"decrypt these messages.",
)}
</p>
<p>
{ _t(
'The exported file will allow anyone who can read it to decrypt ' +
'any encrypted messages that you can see, so you should be ' +
'careful to keep it secure. To help with this, you should enter ' +
'a passphrase below, which will be used to encrypt the exported ' +
'data. It will only be possible to import the data by using the ' +
'same passphrase.',
) }
{_t(
"The exported file will allow anyone who can read it to decrypt " +
"any encrypted messages that you can see, so you should be " +
"careful to keep it secure. To help with this, you should enter " +
"a passphrase below, which will be used to encrypt the exported " +
"data. It will only be possible to import the data by using the " +
"same passphrase.",
)}
</p>
<div className='error'>
{ this.state.errStr }
</div>
<div className='mx_E2eKeysDialog_inputTable'>
<div className='mx_E2eKeysDialog_inputRow'>
<div className="error">{this.state.errStr}</div>
<div className="mx_E2eKeysDialog_inputTable">
<div className="mx_E2eKeysDialog_inputRow">
<Field
label={_t("Enter passphrase")}
value={this.state.passphrase1}
onChange={e => this.onPassphraseChange(e, "passphrase1")}
onChange={(e) => this.onPassphraseChange(e, "passphrase1")}
autoFocus={true}
size={64}
type="password"
disabled={disableForm}
/>
</div>
<div className='mx_E2eKeysDialog_inputRow'>
<div className="mx_E2eKeysDialog_inputRow">
<Field
label={_t("Confirm passphrase")}
value={this.state.passphrase2}
onChange={e => this.onPassphraseChange(e, "passphrase2")}
onChange={(e) => this.onPassphraseChange(e, "passphrase2")}
size={64}
type="password"
disabled={disableForm}
@ -181,15 +182,15 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
</div>
</div>
</div>
<div className='mx_Dialog_buttons'>
<div className="mx_Dialog_buttons">
<input
className='mx_Dialog_primary'
type='submit'
value={_t('Export')}
className="mx_Dialog_primary"
type="submit"
value={_t("Export")}
disabled={disableForm}
/>
<button onClick={this.onCancelClick} disabled={disableForm}>
{ _t("Cancel") }
{_t("Cancel")}
</button>
</div>
</form>