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

@ -19,7 +19,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";
import EditableItemList from "../elements/EditableItemList";
import { _t } from '../../../languageHandler';
import { _t } from "../../../languageHandler";
import Field from "../elements/Field";
import Spinner from "../elements/Spinner";
import ErrorDialog from "../dialogs/ErrorDialog";
@ -68,7 +68,7 @@ class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
roomId={this.props.roomId}
/>
<AccessibleButton onClick={this.onAliasAdded} kind="primary">
{ _t("Add") }
{_t("Add")}
</AccessibleButton>
</form>
);
@ -170,20 +170,22 @@ export default class AliasSettings extends React.Component<IProps, IState> {
if (alias) eventContent["alias"] = alias;
this.context.sendStateEvent(this.props.roomId, "m.room.canonical_alias",
eventContent, "").catch((err) => {
logger.error(err);
Modal.createDialog(ErrorDialog, {
title: _t("Error updating main address"),
description: _t(
"There was an error updating the room's main address. It may not be allowed by the server " +
"or a temporary failure occurred.",
),
this.context
.sendStateEvent(this.props.roomId, "m.room.canonical_alias", eventContent, "")
.catch((err) => {
logger.error(err);
Modal.createDialog(ErrorDialog, {
title: _t("Error updating main address"),
description: _t(
"There was an error updating the room's main address. It may not be allowed by the server " +
"or a temporary failure occurred.",
),
});
this.setState({ canonicalAlias: oldAlias });
})
.finally(() => {
this.setState({ updatingCanonicalAlias: false });
});
this.setState({ canonicalAlias: oldAlias });
}).finally(() => {
this.setState({ updatingCanonicalAlias: false });
});
}
private changeAltAliases(altAliases: string[]) {
@ -202,7 +204,8 @@ export default class AliasSettings extends React.Component<IProps, IState> {
eventContent["alt_aliases"] = altAliases;
}
this.context.sendStateEvent(this.props.roomId, "m.room.canonical_alias", eventContent, "")
this.context
.sendStateEvent(this.props.roomId, "m.room.canonical_alias", eventContent, "")
.then(() => {
this.setState({
altAliases,
@ -215,10 +218,11 @@ export default class AliasSettings extends React.Component<IProps, IState> {
title: _t("Error updating main address"),
description: _t(
"There was an error updating the room's alternative addresses. " +
"It may not be allowed by the server or a temporary failure occurred.",
"It may not be allowed by the server or a temporary failure occurred.",
),
});
}).finally(() => {
})
.finally(() => {
this.setState({ updatingCanonicalAlias: false });
});
}
@ -231,55 +235,61 @@ export default class AliasSettings extends React.Component<IProps, IState> {
if (!alias || alias.length === 0) return; // ignore attempts to create blank aliases
const localDomain = this.context.getDomain();
if (!alias.includes(':')) alias += ':' + localDomain;
if (!alias.includes(":")) alias += ":" + localDomain;
this.context.createAlias(alias, this.props.roomId).then(() => {
this.setState({
localAliases: this.state.localAliases.concat(alias),
newAlias: null,
this.context
.createAlias(alias, this.props.roomId)
.then(() => {
this.setState({
localAliases: this.state.localAliases.concat(alias),
newAlias: null,
});
if (!this.state.canonicalAlias) {
this.changeCanonicalAlias(alias);
}
})
.catch((err) => {
logger.error(err);
Modal.createDialog(ErrorDialog, {
title: _t("Error creating address"),
description: _t(
"There was an error creating that address. It may not be allowed by the server " +
"or a temporary failure occurred.",
),
});
});
if (!this.state.canonicalAlias) {
this.changeCanonicalAlias(alias);
}
}).catch((err) => {
logger.error(err);
Modal.createDialog(ErrorDialog, {
title: _t("Error creating address"),
description: _t(
"There was an error creating that address. It may not be allowed by the server " +
"or a temporary failure occurred.",
),
});
});
};
private onLocalAliasDeleted = (index: number) => {
const alias = this.state.localAliases[index];
// TODO: In future, we should probably be making sure that the alias actually belongs
// to this room. See https://github.com/vector-im/element-web/issues/7353
this.context.deleteAlias(alias).then(() => {
const localAliases = this.state.localAliases.filter(a => a !== alias);
this.setState({ localAliases });
this.context
.deleteAlias(alias)
.then(() => {
const localAliases = this.state.localAliases.filter((a) => a !== alias);
this.setState({ localAliases });
if (this.state.canonicalAlias === alias) {
this.changeCanonicalAlias(null);
}
}).catch((err) => {
logger.error(err);
let description;
if (err.errcode === "M_FORBIDDEN") {
description = _t("You don't have permission to delete the address.");
} else {
description = _t(
"There was an error removing that address. It may no longer exist or a temporary " +
"error occurred.",
);
}
Modal.createDialog(ErrorDialog, {
title: _t("Error removing address"),
description,
if (this.state.canonicalAlias === alias) {
this.changeCanonicalAlias(null);
}
})
.catch((err) => {
logger.error(err);
let description;
if (err.errcode === "M_FORBIDDEN") {
description = _t("You don't have permission to delete the address.");
} else {
description = _t(
"There was an error removing that address. It may no longer exist or a temporary " +
"error occurred.",
);
}
Modal.createDialog(ErrorDialog, {
title: _t("Error removing address"),
description,
});
});
});
};
private onLocalAliasesToggled = (event: ChangeEvent<HTMLDetailsElement>) => {
@ -303,7 +313,7 @@ export default class AliasSettings extends React.Component<IProps, IState> {
private onAltAliasAdded = (alias: string) => {
const altAliases = this.state.altAliases.slice();
if (!altAliases.some(a => a.trim() === alias.trim())) {
if (!altAliases.some((a) => a.trim() === alias.trim())) {
altAliases.push(alias.trim());
this.changeAltAliases(altAliases);
this.setState({ newAltAlias: "" });
@ -322,7 +332,7 @@ export default class AliasSettings extends React.Component<IProps, IState> {
private getLocalNonAltAliases() {
const { altAliases } = this.state;
return this.state.localAliases.filter(alias => !altAliases.includes(alias));
return this.state.localAliases.filter((alias) => !altAliases.includes(alias));
}
render() {
@ -337,27 +347,28 @@ export default class AliasSettings extends React.Component<IProps, IState> {
onChange={this.onCanonicalAliasChange}
value={canonicalValue}
disabled={this.state.updatingCanonicalAlias || !this.props.canSetCanonicalAlias}
element='select'
id='canonicalAlias'
label={_t('Main address')}
element="select"
id="canonicalAlias"
label={_t("Main address")}
>
<option value="" key="unset">{ _t('not specified') }</option>
{
this.getAliases().map((alias, i) => {
if (alias === this.state.canonicalAlias) found = true;
return (
<option value={alias} key={i}>
{ alias }
</option>
);
})
}
{
found || !this.state.canonicalAlias ? '' :
<option value={this.state.canonicalAlias} key='arbitrary'>
{ this.state.canonicalAlias }
<option value="" key="unset">
{_t("not specified")}
</option>
{this.getAliases().map((alias, i) => {
if (alias === this.state.canonicalAlias) found = true;
return (
<option value={alias} key={i}>
{alias}
</option>
}
);
})}
{found || !this.state.canonicalAlias ? (
""
) : (
<option value={this.state.canonicalAlias} key="arbitrary">
{this.state.canonicalAlias}
</option>
)}
</Field>
);
@ -365,37 +376,41 @@ export default class AliasSettings extends React.Component<IProps, IState> {
if (this.state.localAliasesLoading) {
localAliasesList = <Spinner />;
} else {
localAliasesList = (<EditableAliasesList
id="roomAliases"
items={this.state.localAliases}
newItem={this.state.newAlias}
onNewItemChanged={this.onNewAliasChanged}
canRemove={this.props.canSetAliases}
canEdit={this.props.canSetAliases}
onItemAdded={this.onLocalAliasAdded}
onItemRemoved={this.onLocalAliasDeleted}
noItemsLabel={isSpaceRoom
? _t("This space has no local addresses")
: _t("This room has no local addresses")}
placeholder={_t('Local address')}
domain={localDomain}
/>);
localAliasesList = (
<EditableAliasesList
id="roomAliases"
items={this.state.localAliases}
newItem={this.state.newAlias}
onNewItemChanged={this.onNewAliasChanged}
canRemove={this.props.canSetAliases}
canEdit={this.props.canSetAliases}
onItemAdded={this.onLocalAliasAdded}
onItemRemoved={this.onLocalAliasDeleted}
noItemsLabel={
isSpaceRoom ? _t("This space has no local addresses") : _t("This room has no local addresses")
}
placeholder={_t("Local address")}
domain={localDomain}
/>
);
}
return (
<div className='mx_AliasSettings'>
<div className="mx_AliasSettings">
<SettingsFieldset
data-test-id='published-address-fieldset'
data-test-id="published-address-fieldset"
legend={_t("Published Addresses")}
description={<>
{ isSpaceRoom
? _t("Published addresses can be used by anyone on any server to join your space.")
: _t("Published addresses can be used by anyone on any server to join your room.") }
&nbsp;
{ _t("To publish an address, it needs to be set as a local address first.") }
</>}
description={
<>
{isSpaceRoom
? _t("Published addresses can be used by anyone on any server to join your space.")
: _t("Published addresses can be used by anyone on any server to join your room.")}
&nbsp;
{_t("To publish an address, it needs to be set as a local address first.")}
</>
}
>
{ /*
{/*
<span className='mx_SettingsTab_subheading'>{ _t("Published Addresses") }</span>
<p>
{ isSpaceRoom
@ -403,18 +418,19 @@ export default class AliasSettings extends React.Component<IProps, IState> {
: _t("Published addresses can be used by anyone on any server to join your room.") }
&nbsp;
{ _t("To publish an address, it needs to be set as a local address first.") }
</p> */ }
{ canonicalAliasSection }
{ this.props.hidePublishSetting
? null
: <RoomPublishSetting
</p> */}
{canonicalAliasSection}
{this.props.hidePublishSetting ? null : (
<RoomPublishSetting
roomId={this.props.roomId}
canSetCanonicalAlias={this.props.canSetCanonicalAlias}
/> }
/>
)}
<datalist id="mx_AliasSettings_altRecommendations">
{ this.getLocalNonAltAliases().map(alias => {
{this.getLocalNonAltAliases().map((alias) => {
return <option value={alias} key={alias} />;
}) };
})}
;
</datalist>
<EditableAliasesList
id="roomAltAliases"
@ -426,26 +442,34 @@ export default class AliasSettings extends React.Component<IProps, IState> {
onItemAdded={this.onAltAliasAdded}
onItemRemoved={this.onAltAliasDeleted}
suggestionsListId="mx_AliasSettings_altRecommendations"
itemsLabel={_t('Other published addresses:')}
noItemsLabel={_t('No other published addresses yet, add one below')}
placeholder={_t('New published address (e.g. #alias:server)')}
itemsLabel={_t("Other published addresses:")}
noItemsLabel={_t("No other published addresses yet, add one below")}
placeholder={_t("New published address (e.g. #alias:server)")}
roomId={this.props.roomId}
/>
</SettingsFieldset>
<SettingsFieldset
data-test-id='local-address-fieldset'
data-test-id="local-address-fieldset"
legend={_t("Local Addresses")}
description={isSpaceRoom
? _t("Set addresses for this space so users can find this space " +
"through your homeserver (%(localDomain)s)", { localDomain })
: _t("Set addresses for this room so users can find this room " +
"through your homeserver (%(localDomain)s)", { localDomain })}>
description={
isSpaceRoom
? _t(
"Set addresses for this space so users can find this space " +
"through your homeserver (%(localDomain)s)",
{ localDomain },
)
: _t(
"Set addresses for this room so users can find this room " +
"through your homeserver (%(localDomain)s)",
{ localDomain },
)
}
>
<details onToggle={this.onLocalAliasesToggled} open={this.state.detailsOpen}>
<summary>{ this.state.detailsOpen ? _t('Show less') : _t("Show more") }</summary>
{ localAliasesList }
<summary>{this.state.detailsOpen ? _t("Show less") : _t("Show more")}</summary>
{localAliasesList}
</details>
</SettingsFieldset>
</div>
);
}

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { createRef } from 'react';
import React, { createRef } from "react";
import classNames from "classnames";
import { _t } from "../../../languageHandler";
@ -23,7 +23,7 @@ import Field from "../elements/Field";
import { mediaFromMxc } from "../../../customisations/Media";
import AccessibleButton from "../elements/AccessibleButton";
import AvatarSetting from "../settings/AvatarSetting";
import { htmlSerializeFromMdIfNeeded } from '../../../editor/serialize';
import { htmlSerializeFromMdIfNeeded } from "../../../editor/serialize";
import { chromeFileInputFix } from "../../../utils/BrowserWorkarounds";
interface IProps {
@ -60,10 +60,10 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
if (avatarUrl) avatarUrl = mediaFromMxc(avatarUrl).getSquareThumbnailHttp(96);
const topicEvent = room.currentState.getStateEvents("m.room.topic", "");
const topic = topicEvent && topicEvent.getContent() ? topicEvent.getContent()['topic'] : '';
const topic = topicEvent && topicEvent.getContent() ? topicEvent.getContent()["topic"] : "";
const nameEvent = room.currentState.getStateEvents('m.room.name', '');
const name = nameEvent && nameEvent.getContent() ? nameEvent.getContent()['name'] : '';
const nameEvent = room.currentState.getStateEvents("m.room.name", "");
const name = nameEvent && nameEvent.getContent() ? nameEvent.getContent()["name"] : "";
this.state = {
originalDisplayName: name,
@ -74,9 +74,9 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
originalTopic: topic,
topic: topic,
profileFieldsTouched: {},
canSetName: room.currentState.maySendStateEvent('m.room.name', client.getUserId()),
canSetTopic: room.currentState.maySendStateEvent('m.room.topic', client.getUserId()),
canSetAvatar: room.currentState.maySendStateEvent('m.room.avatar', client.getUserId()),
canSetName: room.currentState.maySendStateEvent("m.room.name", client.getUserId()),
canSetTopic: room.currentState.maySendStateEvent("m.room.topic", client.getUserId()),
canSetAvatar: room.currentState.maySendStateEvent("m.room.avatar", client.getUserId()),
};
}
@ -135,12 +135,12 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
if (this.state.avatarFile) {
const { content_uri: uri } = await client.uploadContent(this.state.avatarFile);
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', { url: uri }, '');
await client.sendStateEvent(this.props.roomId, "m.room.avatar", { url: uri }, "");
newState.avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96);
newState.originalAvatarUrl = newState.avatarUrl;
newState.avatarFile = null;
} else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', {}, '');
await client.sendStateEvent(this.props.roomId, "m.room.avatar", {}, "");
}
if (this.state.originalTopic !== this.state.topic) {
@ -220,38 +220,21 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
public render(): JSX.Element {
let profileSettingsButtons;
if (
this.state.canSetName ||
this.state.canSetTopic ||
this.state.canSetAvatar
) {
if (this.state.canSetName || this.state.canSetTopic || this.state.canSetAvatar) {
profileSettingsButtons = (
<div className="mx_ProfileSettings_buttons">
<AccessibleButton
onClick={this.cancelProfileChanges}
kind="link"
disabled={!this.isSaveEnabled()}
>
{ _t("Cancel") }
<AccessibleButton onClick={this.cancelProfileChanges} kind="link" disabled={!this.isSaveEnabled()}>
{_t("Cancel")}
</AccessibleButton>
<AccessibleButton
onClick={this.saveProfile}
kind="primary"
disabled={!this.isSaveEnabled()}
>
{ _t("Save") }
<AccessibleButton onClick={this.saveProfile} kind="primary" disabled={!this.isSaveEnabled()}>
{_t("Save")}
</AccessibleButton>
</div>
);
}
return (
<form
onSubmit={this.saveProfile}
autoComplete="off"
noValidate={true}
className="mx_ProfileSettings"
>
<form onSubmit={this.saveProfile} autoComplete="off" noValidate={true} className="mx_ProfileSettings">
<input
type="file"
ref={this.avatarUpload}
@ -290,9 +273,10 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
avatarName={this.state.displayName || this.props.roomId}
avatarAltText={_t("Room avatar")}
uploadAvatar={this.state.canSetAvatar ? this.uploadAvatar : undefined}
removeAvatar={this.state.canSetAvatar ? this.removeAvatar : undefined} />
removeAvatar={this.state.canSetAvatar ? this.removeAvatar : undefined}
/>
</div>
{ profileSettingsButtons }
{profileSettingsButtons}
</form>
);
}

View file

@ -20,7 +20,7 @@ import { Visibility } from "matrix-js-sdk/src/@types/partials";
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
import { _t } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import DirectoryCustomisations from '../../../customisations/Directory';
import DirectoryCustomisations from "../../../customisations/Directory";
interface IProps {
roomId: string;
@ -47,20 +47,19 @@ export default class RoomPublishSetting extends React.PureComponent<IProps, ISta
this.setState({ isRoomPublished: newValue });
const client = MatrixClientPeg.get();
client.setRoomDirectoryVisibility(
this.props.roomId,
newValue ? Visibility.Public : Visibility.Private,
).catch(() => {
// Roll back the local echo on the change
this.setState({ isRoomPublished: valueBefore });
});
client
.setRoomDirectoryVisibility(this.props.roomId, newValue ? Visibility.Public : Visibility.Private)
.catch(() => {
// Roll back the local echo on the change
this.setState({ isRoomPublished: valueBefore });
});
};
componentDidMount() {
const client = MatrixClientPeg.get();
client.getRoomDirectoryVisibility(this.props.roomId).then((result => {
this.setState({ isRoomPublished: result.visibility === 'public' });
}));
client.getRoomDirectoryVisibility(this.props.roomId).then((result) => {
this.setState({ isRoomPublished: result.visibility === "public" });
});
}
render() {
@ -69,13 +68,14 @@ export default class RoomPublishSetting extends React.PureComponent<IProps, ISta
const room = client.getRoom(this.props.roomId);
const isRoomPublishable = room.getJoinRule() !== "invite";
const enabled = (
const enabled =
(DirectoryCustomisations.requireCanonicalAliasAccessToPublish?.() === false ||
this.props.canSetCanonicalAlias) && (isRoomPublishable || this.state.isRoomPublished)
);
this.props.canSetCanonicalAlias) &&
(isRoomPublishable || this.state.isRoomPublished);
return (
<LabelledToggleSwitch value={this.state.isRoomPublished}
<LabelledToggleSwitch
value={this.state.isRoomPublished}
onChange={this.onRoomPublishChange}
disabled={!enabled}
label={_t("Publish this room to the public in %(domain)s's room directory?", {

View file

@ -17,18 +17,18 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React from 'react';
import React from "react";
import { Room } from "matrix-js-sdk/src/models/room";
import { _t, _td } from '../../../languageHandler';
import { _t, _td } from "../../../languageHandler";
import SettingsStore from "../../../settings/SettingsStore";
import dis from "../../../dispatcher/dispatcher";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { Action } from "../../../dispatcher/actions";
import { SettingLevel } from "../../../settings/SettingLevel";
import SettingsFlag from "../elements/SettingsFlag";
import SettingsFieldset from '../settings/SettingsFieldset';
import AccessibleButton from '../elements/AccessibleButton';
import SettingsFieldset from "../settings/SettingsFieldset";
import AccessibleButton from "../elements/AccessibleButton";
interface IProps {
room: Room;
@ -52,24 +52,28 @@ export default class UrlPreviewSettings extends React.Component<IProps> {
// Only show account setting state and room state setting state in non-e2ee rooms where they apply
const accountEnabled = SettingsStore.getValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled");
if (accountEnabled) {
previewsForAccount = (
_t("You have <a>enabled</a> URL previews by default.", {}, {
'a': (sub) => <AccessibleButton
kind='link_inline'
onClick={this.onClickUserSettings}>
{ sub }
</AccessibleButton>,
})
previewsForAccount = _t(
"You have <a>enabled</a> URL previews by default.",
{},
{
a: (sub) => (
<AccessibleButton kind="link_inline" onClick={this.onClickUserSettings}>
{sub}
</AccessibleButton>
),
},
);
} else {
previewsForAccount = (
_t("You have <a>disabled</a> URL previews by default.", {}, {
'a': (sub) => <AccessibleButton
kind='link_inline'
onClick={this.onClickUserSettings}>
{ sub }
</AccessibleButton>,
})
previewsForAccount = _t(
"You have <a>disabled</a> URL previews by default.",
{},
{
a: (sub) => (
<AccessibleButton kind="link_inline" onClick={this.onClickUserSettings}>
{sub}
</AccessibleButton>
),
},
);
}
@ -86,37 +90,44 @@ export default class UrlPreviewSettings extends React.Component<IProps> {
);
} else {
let str = _td("URL previews are enabled by default for participants in this room.");
if (!SettingsStore.getValueAt(SettingLevel.ROOM, "urlPreviewsEnabled", roomId, /*explicit=*/true)) {
if (!SettingsStore.getValueAt(SettingLevel.ROOM, "urlPreviewsEnabled", roomId, /*explicit=*/ true)) {
str = _td("URL previews are disabled by default for participants in this room.");
}
previewsForRoom = (<label>{ _t(str) }</label>);
previewsForRoom = <label>{_t(str)}</label>;
}
} else {
previewsForAccount = (
_t("In encrypted rooms, like this one, URL previews are disabled by default to ensure that your " +
previewsForAccount = _t(
"In encrypted rooms, like this one, URL previews are disabled by default to ensure that your " +
"homeserver (where the previews are generated) cannot gather information about links you see in " +
"this room.")
"this room.",
);
}
const previewsForRoomAccount = ( // in an e2ee room we use a special key to enforce per-room opt-in
<SettingsFlag name={isEncrypted ? 'urlPreviewsEnabled_e2ee' : 'urlPreviewsEnabled'}
level={SettingLevel.ROOM_ACCOUNT}
roomId={roomId} />
);
const previewsForRoomAccount = // in an e2ee room we use a special key to enforce per-room opt-in
(
<SettingsFlag
name={isEncrypted ? "urlPreviewsEnabled_e2ee" : "urlPreviewsEnabled"}
level={SettingLevel.ROOM_ACCOUNT}
roomId={roomId}
/>
);
const description = <>
<p>
{ _t('When someone puts a URL in their message, a URL preview can be shown to give more ' +
'information about that link such as the title, description, and an image from the website.') }
</p>
<p>{ previewsForAccount }</p>
</>;
const description = (
<>
<p>
{_t(
"When someone puts a URL in their message, a URL preview can be shown to give more " +
"information about that link such as the title, description, and an image from the website.",
)}
</p>
<p>{previewsForAccount}</p>
</>
);
return (
<SettingsFieldset legend={_t("URL Previews")} description={description}>
{ previewsForRoom }
<label>{ previewsForRoomAccount }</label>
{previewsForRoom}
<label>{previewsForRoomAccount}</label>
</SettingsFieldset>
);
}