2016-02-02 15:46:14 +03:00
|
|
|
/*
|
2021-06-23 00:02:09 +03:00
|
|
|
Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
|
2016-02-02 15:46:14 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
import React, { ChangeEvent, createRef } from "react";
|
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|
|
|
|
2019-12-26 21:52:57 +03:00
|
|
|
import EditableItemList from "../elements/EditableItemList";
|
2021-06-07 17:48:55 +03:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-01-26 06:53:38 +03:00
|
|
|
import Field from "../elements/Field";
|
2021-06-07 17:48:55 +03:00
|
|
|
import Spinner from "../elements/Spinner";
|
2019-02-21 02:13:35 +03:00
|
|
|
import ErrorDialog from "../dialogs/ErrorDialog";
|
2019-12-26 21:52:57 +03:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2020-01-13 23:28:33 +03:00
|
|
|
import Modal from "../../../Modal";
|
2020-03-16 19:27:06 +03:00
|
|
|
import RoomPublishSetting from "./RoomPublishSetting";
|
2021-06-07 17:48:55 +03:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
|
|
|
import RoomAliasField from "../elements/RoomAliasField";
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
interface IEditableAliasesListProps {
|
|
|
|
domain?: string;
|
|
|
|
}
|
2020-01-06 00:58:36 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
|
|
|
|
private aliasField = createRef<RoomAliasField>();
|
2020-01-06 00:58:36 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onAliasAdded = async () => {
|
|
|
|
await this.aliasField.current.validate({ allowEmpty: false });
|
2020-01-06 00:58:36 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
if (this.aliasField.current.isValid) {
|
2020-01-06 00:58:36 +03:00
|
|
|
if (this.props.onItemAdded) this.props.onItemAdded(this.props.newItem);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
this.aliasField.current.focus();
|
|
|
|
this.aliasField.current.validate({ allowEmpty: false, focused: true });
|
2020-01-06 00:58:36 +03:00
|
|
|
};
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
protected renderNewItemField() {
|
2020-03-09 18:31:30 +03:00
|
|
|
// if we don't need the RoomAliasField,
|
2021-06-07 17:48:55 +03:00
|
|
|
// we don't need to overriden version of renderNewItemField
|
2020-03-09 18:31:30 +03:00
|
|
|
if (!this.props.domain) {
|
2021-06-07 17:48:55 +03:00
|
|
|
return super.renderNewItemField();
|
2020-03-09 18:31:30 +03:00
|
|
|
}
|
2021-06-29 15:11:58 +03:00
|
|
|
const onChange = (alias) => this.onNewItemChanged({ target: { value: alias } });
|
2019-12-26 21:52:57 +03:00
|
|
|
return (
|
2019-12-27 20:05:51 +03:00
|
|
|
<form
|
2021-06-07 17:48:55 +03:00
|
|
|
onSubmit={this.onAliasAdded}
|
2019-12-27 20:05:51 +03:00
|
|
|
autoComplete="off"
|
|
|
|
noValidate={true}
|
|
|
|
className="mx_EditableItemList_newItem"
|
|
|
|
>
|
2019-12-26 21:52:57 +03:00
|
|
|
<RoomAliasField
|
2021-06-07 17:48:55 +03:00
|
|
|
ref={this.aliasField}
|
2019-12-26 21:52:57 +03:00
|
|
|
onChange={onChange}
|
|
|
|
value={this.props.newItem || ""}
|
|
|
|
domain={this.props.domain} />
|
2021-06-07 17:48:55 +03:00
|
|
|
<AccessibleButton onClick={this.onAliasAdded} kind="primary">
|
2019-12-27 20:05:51 +03:00
|
|
|
{ _t("Add") }
|
2019-12-26 21:52:57 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
interface IProps {
|
|
|
|
roomId: string;
|
|
|
|
canSetCanonicalAlias: boolean;
|
|
|
|
canSetAliases: boolean;
|
|
|
|
canonicalAliasEvent?: MatrixEvent;
|
2021-06-08 18:32:43 +03:00
|
|
|
hidePublishSetting?: boolean;
|
2021-06-07 17:48:55 +03:00
|
|
|
}
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
interface IState {
|
|
|
|
altAliases: string[];
|
|
|
|
localAliases: string[];
|
|
|
|
canonicalAlias?: string;
|
|
|
|
updatingCanonicalAlias: boolean;
|
|
|
|
localAliasesLoading: boolean;
|
|
|
|
detailsOpen: boolean;
|
|
|
|
newAlias?: string;
|
|
|
|
newAltAlias?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
@replaceableComponent("views.room_settings.AliasSettings")
|
|
|
|
export default class AliasSettings extends React.Component<IProps, IState> {
|
2019-02-21 02:13:35 +03:00
|
|
|
static defaultProps = {
|
|
|
|
canSetAliases: false,
|
|
|
|
canSetCanonicalAlias: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const state = {
|
2020-03-09 18:26:43 +03:00
|
|
|
altAliases: [], // [ #alias:domain.tld, ... ]
|
|
|
|
localAliases: [], // [ #alias:my-hs.tld, ... ]
|
|
|
|
canonicalAlias: null, // #canonical:domain.tld
|
2019-02-22 02:11:09 +03:00
|
|
|
updatingCanonicalAlias: false,
|
2020-03-09 18:26:43 +03:00
|
|
|
localAliasesLoading: false,
|
2020-03-16 20:24:49 +03:00
|
|
|
detailsOpen: false,
|
2016-02-02 15:46:14 +03:00
|
|
|
};
|
|
|
|
|
2019-02-22 02:27:49 +03:00
|
|
|
if (props.canonicalAliasEvent) {
|
2020-03-09 18:26:43 +03:00
|
|
|
const content = props.canonicalAliasEvent.getContent();
|
|
|
|
const altAliases = content.alt_aliases;
|
|
|
|
if (Array.isArray(altAliases)) {
|
|
|
|
state.altAliases = altAliases.slice();
|
|
|
|
}
|
|
|
|
state.canonicalAlias = content.alias;
|
2016-09-16 20:01:14 +03:00
|
|
|
}
|
2018-09-20 03:07:01 +03:00
|
|
|
|
2019-02-22 02:27:49 +03:00
|
|
|
this.state = state;
|
2019-02-21 02:13:35 +03:00
|
|
|
}
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2020-03-09 18:26:43 +03:00
|
|
|
componentDidMount() {
|
2020-03-09 18:43:52 +03:00
|
|
|
if (this.props.canSetCanonicalAlias) {
|
|
|
|
// load local aliases for providing recommendations
|
|
|
|
// for the canonical alias and alt_aliases
|
|
|
|
this.loadLocalAliases();
|
|
|
|
}
|
2020-03-09 18:26:43 +03:00
|
|
|
}
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private async loadLocalAliases() {
|
2020-03-09 18:26:43 +03:00
|
|
|
this.setState({ localAliasesLoading: true });
|
2020-02-19 17:15:05 +03:00
|
|
|
try {
|
2020-03-09 18:26:43 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
let localAliases = [];
|
2020-02-19 17:15:05 +03:00
|
|
|
if (await cli.doesServerSupportUnstableFeature("org.matrix.msc2432")) {
|
|
|
|
const response = await cli.unstableGetLocalAliases(this.props.roomId);
|
2020-03-09 18:26:43 +03:00
|
|
|
if (Array.isArray(response.aliases)) {
|
|
|
|
localAliases = response.aliases;
|
|
|
|
}
|
2020-02-19 17:15:05 +03:00
|
|
|
}
|
2020-03-09 18:26:43 +03:00
|
|
|
this.setState({ localAliases });
|
2021-06-12 07:24:05 +03:00
|
|
|
|
|
|
|
if (localAliases.length === 0) {
|
|
|
|
this.setState({ detailsOpen: true });
|
|
|
|
}
|
2020-02-19 17:15:05 +03:00
|
|
|
} finally {
|
2020-03-09 18:26:43 +03:00
|
|
|
this.setState({ localAliasesLoading: false });
|
2020-02-18 17:57:17 +03:00
|
|
|
}
|
2019-02-21 02:13:35 +03:00
|
|
|
}
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private changeCanonicalAlias(alias: string) {
|
2019-02-22 02:11:09 +03:00
|
|
|
if (!this.props.canSetCanonicalAlias) return;
|
|
|
|
|
2020-03-09 18:26:43 +03:00
|
|
|
const oldAlias = this.state.canonicalAlias;
|
2019-02-22 02:11:09 +03:00
|
|
|
this.setState({
|
|
|
|
canonicalAlias: alias,
|
|
|
|
updatingCanonicalAlias: true,
|
|
|
|
});
|
|
|
|
|
2020-03-09 18:26:43 +03:00
|
|
|
const eventContent = {
|
|
|
|
alt_aliases: this.state.altAliases,
|
|
|
|
};
|
|
|
|
|
2019-02-22 02:11:09 +03:00
|
|
|
if (alias) eventContent["alias"] = alias;
|
|
|
|
|
|
|
|
MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.canonical_alias",
|
|
|
|
eventContent, "").catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
Modal.createTrackedDialog('Error updating main address', '', 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 " +
|
2019-02-22 03:53:29 +03:00
|
|
|
"or a temporary failure occurred.",
|
2019-02-22 02:11:09 +03:00
|
|
|
),
|
|
|
|
});
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ canonicalAlias: oldAlias });
|
2019-02-22 02:11:09 +03:00
|
|
|
}).finally(() => {
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ updatingCanonicalAlias: false });
|
2019-02-22 02:11:09 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private changeAltAliases(altAliases: string[]) {
|
2020-03-09 18:29:04 +03:00
|
|
|
if (!this.props.canSetCanonicalAlias) return;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
updatingCanonicalAlias: true,
|
|
|
|
altAliases,
|
|
|
|
});
|
|
|
|
|
|
|
|
const eventContent = {};
|
|
|
|
|
|
|
|
if (this.state.canonicalAlias) {
|
2021-06-07 17:48:55 +03:00
|
|
|
eventContent["alias"] = this.state.canonicalAlias;
|
2020-03-09 18:29:04 +03:00
|
|
|
}
|
|
|
|
if (altAliases) {
|
|
|
|
eventContent["alt_aliases"] = altAliases;
|
|
|
|
}
|
|
|
|
|
|
|
|
MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.canonical_alias",
|
|
|
|
eventContent, "").catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
Modal.createTrackedDialog('Error updating alternative addresses', '', ErrorDialog, {
|
|
|
|
title: _t("Error updating main address"),
|
|
|
|
description: _t(
|
2020-03-09 18:50:34 +03:00
|
|
|
"There was an error updating the room's alternative addresses. " +
|
|
|
|
"It may not be allowed by the server or a temporary failure occurred.",
|
2020-03-09 18:29:04 +03:00
|
|
|
),
|
|
|
|
});
|
|
|
|
}).finally(() => {
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ updatingCanonicalAlias: false });
|
2020-03-09 18:29:04 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onNewAliasChanged = (value: string) => {
|
|
|
|
this.setState({ newAlias: value });
|
2019-02-21 02:13:35 +03:00
|
|
|
};
|
2017-10-04 12:00:01 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onLocalAliasAdded = (alias: string) => {
|
2016-02-02 15:46:14 +03:00
|
|
|
if (!alias || alias.length === 0) return; // ignore attempts to create blank aliases
|
|
|
|
|
2017-10-04 12:00:01 +03:00
|
|
|
const localDomain = MatrixClientPeg.get().getDomain();
|
2018-09-20 03:38:25 +03:00
|
|
|
if (!alias.includes(':')) alias += ':' + localDomain;
|
2020-01-06 00:58:36 +03:00
|
|
|
|
|
|
|
MatrixClientPeg.get().createAlias(alias, this.props.roomId).then(() => {
|
|
|
|
this.setState({
|
2020-03-09 18:26:43 +03:00
|
|
|
localAliases: this.state.localAliases.concat(alias),
|
|
|
|
newAlias: null,
|
2016-02-02 15:46:14 +03:00
|
|
|
});
|
2020-01-06 00:58:36 +03:00
|
|
|
if (!this.state.canonicalAlias) {
|
|
|
|
this.changeCanonicalAlias(alias);
|
|
|
|
}
|
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
2020-04-14 12:06:57 +03:00
|
|
|
Modal.createTrackedDialog('Error creating address', '', ErrorDialog, {
|
|
|
|
title: _t("Error creating address"),
|
2020-01-06 00:58:36 +03:00
|
|
|
description: _t(
|
2020-04-14 12:06:57 +03:00
|
|
|
"There was an error creating that address. It may not be allowed by the server " +
|
2020-01-06 00:58:36 +03:00
|
|
|
"or a temporary failure occurred.",
|
|
|
|
),
|
2016-02-02 15:46:14 +03:00
|
|
|
});
|
2020-01-06 00:58:36 +03:00
|
|
|
});
|
2019-02-21 02:13:35 +03:00
|
|
|
};
|
2018-09-20 03:07:01 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onLocalAliasDeleted = (index: number) => {
|
2020-03-09 18:26:43 +03:00
|
|
|
const alias = this.state.localAliases[index];
|
2019-02-21 06:44:08 +03:00
|
|
|
// TODO: In future, we should probably be making sure that the alias actually belongs
|
2020-08-03 18:02:26 +03:00
|
|
|
// to this room. See https://github.com/vector-im/element-web/issues/7353
|
2019-02-21 06:44:08 +03:00
|
|
|
MatrixClientPeg.get().deleteAlias(alias).then(() => {
|
2020-03-17 22:37:40 +03:00
|
|
|
const localAliases = this.state.localAliases.filter(a => a !== alias);
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ localAliases });
|
2019-02-22 02:11:09 +03:00
|
|
|
|
|
|
|
if (this.state.canonicalAlias === alias) {
|
|
|
|
this.changeCanonicalAlias(null);
|
2019-02-21 06:44:08 +03:00
|
|
|
}
|
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
2020-03-11 14:13:28 +03:00
|
|
|
let description;
|
|
|
|
if (err.errcode === "M_FORBIDDEN") {
|
2020-04-14 12:06:57 +03:00
|
|
|
description = _t("You don't have permission to delete the address.");
|
2020-03-11 14:13:28 +03:00
|
|
|
} else {
|
|
|
|
description = _t(
|
2020-04-14 12:06:57 +03:00
|
|
|
"There was an error removing that address. It may no longer exist or a temporary " +
|
2019-02-22 03:53:29 +03:00
|
|
|
"error occurred.",
|
2020-03-11 14:13:28 +03:00
|
|
|
);
|
|
|
|
}
|
2020-04-14 12:06:57 +03:00
|
|
|
Modal.createTrackedDialog('Error removing address', '', ErrorDialog, {
|
|
|
|
title: _t("Error removing address"),
|
2020-03-11 14:13:28 +03:00
|
|
|
description,
|
2018-09-20 03:07:01 +03:00
|
|
|
});
|
2019-02-21 06:44:08 +03:00
|
|
|
});
|
2019-02-21 02:13:35 +03:00
|
|
|
};
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onLocalAliasesToggled = (event: ChangeEvent<HTMLDetailsElement>) => {
|
2020-03-09 18:43:52 +03:00
|
|
|
// expanded
|
|
|
|
if (event.target.open) {
|
|
|
|
// if local aliases haven't been preloaded yet at component mount
|
|
|
|
if (!this.props.canSetCanonicalAlias && this.state.localAliases.length === 0) {
|
|
|
|
this.loadLocalAliases();
|
|
|
|
}
|
|
|
|
}
|
2021-06-07 17:48:55 +03:00
|
|
|
this.setState({ detailsOpen: event.currentTarget.open });
|
2020-03-09 18:43:52 +03:00
|
|
|
};
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onCanonicalAliasChange = (event: ChangeEvent<HTMLSelectElement>) => {
|
2019-02-22 02:11:09 +03:00
|
|
|
this.changeCanonicalAlias(event.target.value);
|
2019-02-21 02:13:35 +03:00
|
|
|
};
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onNewAltAliasChanged = (value: string) => {
|
|
|
|
this.setState({ newAltAlias: value });
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2020-03-09 18:29:04 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onAltAliasAdded = (alias: string) => {
|
2020-03-09 18:29:04 +03:00
|
|
|
const altAliases = this.state.altAliases.slice();
|
|
|
|
if (!altAliases.some(a => a.trim() === alias.trim())) {
|
|
|
|
altAliases.push(alias.trim());
|
|
|
|
this.changeAltAliases(altAliases);
|
2021-06-07 17:48:55 +03:00
|
|
|
this.setState({ newAltAlias: "" });
|
2020-03-09 18:29:04 +03:00
|
|
|
}
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2020-03-09 18:29:04 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private onAltAliasDeleted = (index: number) => {
|
2020-03-09 18:29:04 +03:00
|
|
|
const altAliases = this.state.altAliases.slice();
|
|
|
|
altAliases.splice(index, 1);
|
|
|
|
this.changeAltAliases(altAliases);
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2020-03-09 18:29:04 +03:00
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private getAliases() {
|
|
|
|
return this.state.altAliases.concat(this.getLocalNonAltAliases());
|
2020-03-09 18:26:43 +03:00
|
|
|
}
|
|
|
|
|
2021-06-07 17:48:55 +03:00
|
|
|
private getLocalNonAltAliases() {
|
2021-06-29 15:11:58 +03:00
|
|
|
const { altAliases } = this.state;
|
2020-03-09 18:26:43 +03:00
|
|
|
return this.state.localAliases.filter(alias => !altAliases.includes(alias));
|
|
|
|
}
|
|
|
|
|
2019-02-21 02:13:35 +03:00
|
|
|
render() {
|
2021-06-08 18:32:43 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const localDomain = cli.getDomain();
|
|
|
|
const isSpaceRoom = cli.getRoom(this.props.roomId)?.isSpaceRoom();
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2019-02-22 02:33:02 +03:00
|
|
|
let found = false;
|
|
|
|
const canonicalValue = this.state.canonicalAlias || "";
|
|
|
|
const canonicalAliasSection = (
|
2021-04-27 18:23:27 +03:00
|
|
|
<Field
|
|
|
|
onChange={this.onCanonicalAliasChange}
|
|
|
|
value={canonicalValue}
|
|
|
|
disabled={this.state.updatingCanonicalAlias || !this.props.canSetCanonicalAlias}
|
|
|
|
element='select'
|
|
|
|
id='canonicalAlias'
|
|
|
|
label={_t('Main address')}
|
|
|
|
>
|
2019-02-22 02:33:02 +03:00
|
|
|
<option value="" key="unset">{ _t('not specified') }</option>
|
|
|
|
{
|
2021-06-07 17:48:55 +03:00
|
|
|
this.getAliases().map((alias, i) => {
|
2020-03-09 18:26:43 +03:00
|
|
|
if (alias === this.state.canonicalAlias) found = true;
|
|
|
|
return (
|
|
|
|
<option value={alias} key={i}>
|
|
|
|
{ alias }
|
|
|
|
</option>
|
|
|
|
);
|
2019-02-22 02:33:02 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
{
|
|
|
|
found || !this.state.canonicalAlias ? '' :
|
2021-04-27 18:23:27 +03:00
|
|
|
<option value={ this.state.canonicalAlias } key='arbitrary'>
|
|
|
|
{ this.state.canonicalAlias }
|
|
|
|
</option>
|
2019-02-22 02:33:02 +03:00
|
|
|
}
|
|
|
|
</Field>
|
|
|
|
);
|
2016-02-02 15:46:14 +03:00
|
|
|
|
2020-02-19 17:15:05 +03:00
|
|
|
let localAliasesList;
|
|
|
|
if (this.state.localAliasesLoading) {
|
|
|
|
localAliasesList = <Spinner />;
|
|
|
|
} else {
|
2020-03-09 18:26:43 +03:00
|
|
|
localAliasesList = (<EditableAliasesList
|
2020-02-19 17:15:05 +03:00
|
|
|
id="roomAliases"
|
2020-03-09 18:26:43 +03:00
|
|
|
items={this.state.localAliases}
|
2020-02-19 17:15:05 +03:00
|
|
|
newItem={this.state.newAlias}
|
|
|
|
onNewItemChanged={this.onNewAliasChanged}
|
|
|
|
canRemove={this.props.canSetAliases}
|
|
|
|
canEdit={this.props.canSetAliases}
|
|
|
|
onItemAdded={this.onLocalAliasAdded}
|
|
|
|
onItemRemoved={this.onLocalAliasDeleted}
|
2021-06-08 18:32:43 +03:00
|
|
|
noItemsLabel={isSpaceRoom
|
|
|
|
? _t("This space has no local addresses")
|
|
|
|
: _t("This room has no local addresses")}
|
2020-03-16 20:25:13 +03:00
|
|
|
placeholder={_t('Local address')}
|
2020-02-19 17:15:05 +03:00
|
|
|
domain={localDomain}
|
2020-03-09 18:26:43 +03:00
|
|
|
/>);
|
2020-02-19 17:15:05 +03:00
|
|
|
}
|
|
|
|
|
2016-02-02 15:46:14 +03:00
|
|
|
return (
|
2019-01-28 21:34:21 +03:00
|
|
|
<div className='mx_AliasSettings'>
|
2020-03-16 19:28:45 +03:00
|
|
|
<span className='mx_SettingsTab_subheading'>{_t("Published Addresses")}</span>
|
2021-06-08 18:32:43 +03:00
|
|
|
<p>
|
|
|
|
{ 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.")}
|
|
|
|
|
|
|
|
{ _t("To publish an address, it needs to be set as a local address first.") }
|
|
|
|
</p>
|
|
|
|
{ canonicalAliasSection }
|
|
|
|
{ this.props.hidePublishSetting
|
|
|
|
? null
|
|
|
|
: <RoomPublishSetting
|
|
|
|
roomId={this.props.roomId}
|
|
|
|
canSetCanonicalAlias={this.props.canSetCanonicalAlias}
|
|
|
|
/> }
|
2020-03-09 18:31:07 +03:00
|
|
|
<datalist id="mx_AliasSettings_altRecommendations">
|
2021-06-07 17:48:55 +03:00
|
|
|
{this.getLocalNonAltAliases().map(alias => {
|
2020-03-09 18:31:07 +03:00
|
|
|
return <option value={alias} key={alias} />;
|
|
|
|
})};
|
|
|
|
</datalist>
|
2020-03-09 18:29:04 +03:00
|
|
|
<EditableAliasesList
|
|
|
|
id="roomAltAliases"
|
|
|
|
items={this.state.altAliases}
|
|
|
|
newItem={this.state.newAltAlias}
|
|
|
|
onNewItemChanged={this.onNewAltAliasChanged}
|
|
|
|
canRemove={this.props.canSetCanonicalAlias}
|
|
|
|
canEdit={this.props.canSetCanonicalAlias}
|
|
|
|
onItemAdded={this.onAltAliasAdded}
|
|
|
|
onItemRemoved={this.onAltAliasDeleted}
|
2020-03-09 18:31:07 +03:00
|
|
|
suggestionsListId="mx_AliasSettings_altRecommendations"
|
2020-03-16 19:28:45 +03:00
|
|
|
itemsLabel={_t('Other published addresses:')}
|
|
|
|
noItemsLabel={_t('No other published addresses yet, add one below')}
|
2020-03-16 20:25:13 +03:00
|
|
|
placeholder={_t('New published address (e.g. #alias:server)')}
|
2020-03-09 18:29:04 +03:00
|
|
|
/>
|
2021-06-07 17:48:55 +03:00
|
|
|
<span className='mx_SettingsTab_subheading mx_AliasSettings_localAliasHeader'>
|
|
|
|
{ _t("Local Addresses") }
|
|
|
|
</span>
|
|
|
|
<p>
|
2021-06-08 18:32:43 +03:00
|
|
|
{ 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 " +
|
2021-06-07 17:48:55 +03:00
|
|
|
"through your homeserver (%(localDomain)s)", { localDomain }) }
|
|
|
|
</p>
|
2021-06-12 07:24:05 +03:00
|
|
|
<details onToggle={this.onLocalAliasesToggled} open={this.state.detailsOpen}>
|
2020-03-16 20:24:49 +03:00
|
|
|
<summary>{ this.state.detailsOpen ? _t('Show less') : _t("Show more")}</summary>
|
2021-06-07 17:48:55 +03:00
|
|
|
{ localAliasesList }
|
2020-03-09 18:32:13 +03:00
|
|
|
</details>
|
2016-02-02 15:46:14 +03:00
|
|
|
</div>
|
|
|
|
);
|
2019-02-21 02:13:35 +03:00
|
|
|
}
|
2019-02-22 04:18:12 +03:00
|
|
|
}
|