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

@ -14,23 +14,23 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import url from 'url';
import React from 'react';
import url from "url";
import React from "react";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import Modal from '../../../Modal';
import Modal from "../../../Modal";
import dis from "../../../dispatcher/dispatcher";
import { getThreepidsWithBindStatus } from '../../../boundThreepids';
import { getThreepidsWithBindStatus } from "../../../boundThreepids";
import IdentityAuthClient from "../../../IdentityAuthClient";
import { abbreviateUrl, unabbreviateUrl } from "../../../utils/UrlUtils";
import { getDefaultIdentityServerUrl, doesIdentityServerHaveTerms } from '../../../utils/IdentityServerUtils';
import { getDefaultIdentityServerUrl, doesIdentityServerHaveTerms } from "../../../utils/IdentityServerUtils";
import { timeout } from "../../../utils/promise";
import { ActionPayload } from '../../../dispatcher/payloads';
import InlineSpinner from '../elements/InlineSpinner';
import AccessibleButton from '../elements/AccessibleButton';
import Field from '../elements/Field';
import { ActionPayload } from "../../../dispatcher/payloads";
import InlineSpinner from "../elements/InlineSpinner";
import AccessibleButton from "../elements/AccessibleButton";
import Field from "../elements/Field";
import QuestionDialog from "../dialogs/QuestionDialog";
// We'll wait up to this long when checking for 3PID bindings on the IS.
@ -45,12 +45,12 @@ const REACHABILITY_TIMEOUT = 10000; // ms
async function checkIdentityServerUrl(u) {
const parsedUrl = url.parse(u);
if (parsedUrl.protocol !== 'https:') return _t("Identity server URL must be HTTPS");
if (parsedUrl.protocol !== "https:") return _t("Identity server URL must be HTTPS");
// 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
try {
const response = await fetch(u + '/_matrix/identity/api/v1');
const response = await fetch(u + "/_matrix/identity/api/v1");
if (response.ok) {
return null;
} else if (response.status < 200 || response.status >= 300) {
@ -85,7 +85,7 @@ export default class SetIdServer extends React.Component<IProps, IState> {
constructor(props) {
super(props);
let defaultIdServer = '';
let defaultIdServer = "";
if (!MatrixClientPeg.get().getIdentityServerUrl() && getDefaultIdentityServerUrl()) {
// If no identity server is configured but there's one in the config, prepopulate
// the field to help the user.
@ -129,12 +129,14 @@ export default class SetIdServer extends React.Component<IProps, IState> {
private getTooltip = () => {
if (this.state.checking) {
return <div>
<InlineSpinner />
{ _t("Checking server") }
</div>;
return (
<div>
<InlineSpinner />
{_t("Checking server")}
</div>
);
} else if (this.state.error) {
return <span className='warning'>{ this.state.error }</span>;
return <span className="warning">{this.state.error}</span>;
} else {
return null;
}
@ -153,7 +155,7 @@ export default class SetIdServer extends React.Component<IProps, IState> {
busy: false,
error: null,
currentClientIdServer: fullUrl,
idServer: '',
idServer: "",
});
};
@ -190,11 +192,11 @@ export default class SetIdServer extends React.Component<IProps, IState> {
const [confirmed] = await this.showServerChangeWarning({
title: _t("Change identity server"),
unboundMessage: _t(
"Disconnect from the identity server <current /> and " +
"connect to <new /> instead?", {},
"Disconnect from the identity server <current /> and " + "connect to <new /> instead?",
{},
{
current: sub => <b>{ abbreviateUrl(currentClientIdServer) }</b>,
new: sub => <b>{ abbreviateUrl(idServer) }</b>,
current: (sub) => <b>{abbreviateUrl(currentClientIdServer)}</b>,
new: (sub) => <b>{abbreviateUrl(idServer)}</b>,
},
),
button: _t("Continue"),
@ -224,11 +226,9 @@ export default class SetIdServer extends React.Component<IProps, IState> {
description: (
<div>
<span className="warning">
{ _t("The identity server you have chosen does not have any terms of service.") }
</span>
<span>
&nbsp;{ _t("Only continue if you trust the owner of the server.") }
{_t("The identity server you have chosen does not have any terms of service.")}
</span>
<span>&nbsp;{_t("Only continue if you trust the owner of the server.")}</span>
</div>
),
button: _t("Continue"),
@ -242,8 +242,9 @@ export default class SetIdServer extends React.Component<IProps, IState> {
const [confirmed] = await this.showServerChangeWarning({
title: _t("Disconnect identity server"),
unboundMessage: _t(
"Disconnect from the identity server <idserver />?", {},
{ idserver: sub => <b>{ abbreviateUrl(this.state.currentClientIdServer) }</b> },
"Disconnect from the identity server <idserver />?",
{},
{ idserver: (sub) => <b>{abbreviateUrl(this.state.currentClientIdServer)}</b> },
),
button: _t("Disconnect"),
});
@ -270,50 +271,70 @@ export default class SetIdServer extends React.Component<IProps, IState> {
currentServerReachable = false;
logger.warn(
`Unable to reach identity server at ${currentClientIdServer} to check ` +
`for 3PIDs during IS change flow`,
`for 3PIDs during IS change flow`,
);
logger.warn(e);
}
const boundThreepids = threepids.filter(tp => tp.bound);
const boundThreepids = threepids.filter((tp) => tp.bound);
let message;
let danger = false;
const messageElements = {
idserver: sub => <b>{ abbreviateUrl(currentClientIdServer) }</b>,
b: sub => <b>{ sub }</b>,
idserver: (sub) => <b>{abbreviateUrl(currentClientIdServer)}</b>,
b: (sub) => <b>{sub}</b>,
};
if (!currentServerReachable) {
message = <div>
<p>{ _t(
"You should <b>remove your personal data</b> from identity server " +
"<idserver /> before disconnecting. Unfortunately, identity server " +
"<idserver /> is currently offline or cannot be reached.",
{}, messageElements,
) }</p>
<p>{ _t("You should:") }</p>
<ul>
<li>{ _t(
"check your browser plugins for anything that might block " +
"the identity server (such as Privacy Badger)",
) }</li>
<li>{ _t("contact the administrators of identity server <idserver />", {}, {
idserver: messageElements.idserver,
}) }</li>
<li>{ _t("wait and try again later") }</li>
</ul>
</div>;
message = (
<div>
<p>
{_t(
"You should <b>remove your personal data</b> from identity server " +
"<idserver /> before disconnecting. Unfortunately, identity server " +
"<idserver /> is currently offline or cannot be reached.",
{},
messageElements,
)}
</p>
<p>{_t("You should:")}</p>
<ul>
<li>
{_t(
"check your browser plugins for anything that might block " +
"the identity server (such as Privacy Badger)",
)}
</li>
<li>
{_t(
"contact the administrators of identity server <idserver />",
{},
{
idserver: messageElements.idserver,
},
)}
</li>
<li>{_t("wait and try again later")}</li>
</ul>
</div>
);
danger = true;
button = _t("Disconnect anyway");
} else if (boundThreepids.length) {
message = <div>
<p>{ _t(
"You are still <b>sharing your personal data</b> on the identity " +
"server <idserver />.", {}, messageElements,
) }</p>
<p>{ _t(
"We recommend that you remove your email addresses and phone numbers " +
"from the identity server before disconnecting.",
) }</p>
</div>;
message = (
<div>
<p>
{_t(
"You are still <b>sharing your personal data</b> on the identity " + "server <idserver />.",
{},
messageElements,
)}
</p>
<p>
{_t(
"We recommend that you remove your email addresses and phone numbers " +
"from the identity server before disconnecting.",
)}
</p>
</div>
);
danger = true;
button = _t("Disconnect anyway");
} else {
@ -336,7 +357,7 @@ export default class SetIdServer extends React.Component<IProps, IState> {
base_url: null, // clear
});
let newFieldVal = '';
let newFieldVal = "";
if (getDefaultIdentityServerUrl()) {
// Prepopulate the client's default so the user at least has some idea of
// a valid value they might enter
@ -359,23 +380,24 @@ export default class SetIdServer extends React.Component<IProps, IState> {
sectionTitle = _t("Identity server (%(server)s)", { server: abbreviateUrl(idServerUrl) });
bodyText = _t(
"You are currently using <server></server> to discover and be discoverable by " +
"existing contacts you know. You can change your identity server below.",
"existing contacts you know. You can change your identity server below.",
{},
{ server: sub => <b>{ abbreviateUrl(idServerUrl) }</b> },
{ server: (sub) => <b>{abbreviateUrl(idServerUrl)}</b> },
);
if (this.props.missingTerms) {
bodyText = _t(
"If you don't want to use <server /> to discover and be discoverable by existing " +
"contacts you know, enter another identity server below.",
{}, { server: sub => <b>{ abbreviateUrl(idServerUrl) }</b> },
"contacts you know, enter another identity server below.",
{},
{ server: (sub) => <b>{abbreviateUrl(idServerUrl)}</b> },
);
}
} else {
sectionTitle = _t("Identity server");
bodyText = _t(
"You are not currently using an identity server. " +
"To discover and be discoverable by existing contacts you know, " +
"add one below.",
"To discover and be discoverable by existing contacts you know, " +
"add one below.",
);
}
@ -384,36 +406,34 @@ export default class SetIdServer extends React.Component<IProps, IState> {
let discoButtonContent: React.ReactNode = _t("Disconnect");
let discoBodyText = _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.",
"won't be discoverable by other users and you won't be " +
"able to invite others by email or phone.",
);
if (this.props.missingTerms) {
discoBodyText = _t(
"Using an identity server is optional. If you choose not to " +
"use an identity server, you won't be discoverable by other users " +
"and you won't be able to invite others by email or phone.",
"use an identity server, you won't be discoverable by other users " +
"and you won't be able to invite others by email or phone.",
);
discoButtonContent = _t("Do not use an identity server");
}
if (this.state.disconnectBusy) {
discoButtonContent = <InlineSpinner />;
}
discoSection = <div>
<span className="mx_SettingsTab_subsectionText">{ discoBodyText }</span>
<AccessibleButton onClick={this.onDisconnectClicked} kind="danger_sm">
{ discoButtonContent }
</AccessibleButton>
</div>;
discoSection = (
<div>
<span className="mx_SettingsTab_subsectionText">{discoBodyText}</span>
<AccessibleButton onClick={this.onDisconnectClicked} kind="danger_sm">
{discoButtonContent}
</AccessibleButton>
</div>
);
}
return (
<form className="mx_SetIdServer" onSubmit={this.checkIdServer}>
<span className="mx_SettingsTab_subheading">
{ sectionTitle }
</span>
<span className="mx_SettingsTab_subsectionText">
{ bodyText }
</span>
<span className="mx_SettingsTab_subheading">{sectionTitle}</span>
<span className="mx_SettingsTab_subsectionText">{bodyText}</span>
<Field
label={_t("Enter a new identity server")}
type="text"
@ -431,8 +451,10 @@ export default class SetIdServer extends React.Component<IProps, IState> {
kind="primary_sm"
onClick={this.checkIdServer}
disabled={!this.idServerChangeEnabled()}
>{ _t("Change") }</AccessibleButton>
{ discoSection }
>
{_t("Change")}
</AccessibleButton>
{discoSection}
</form>
);
}