2016-02-02 12:46:14 +00:00
|
|
|
/*
|
2021-06-22 21:02:09 +00:00
|
|
|
Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
|
2016-02-02 12:46:14 +00: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.
|
|
|
|
*/
|
|
|
|
|
2022-02-01 15:06:26 +00:00
|
|
|
import React, { ChangeEvent, ContextType, createRef, SyntheticEvent } from "react";
|
2021-06-07 14:48:55 +00:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
2021-10-22 22:23:32 +00:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2021-06-07 14:48:55 +00:00
|
|
|
|
2019-12-26 18:52:57 +00:00
|
|
|
import EditableItemList from "../elements/EditableItemList";
|
2017-05-25 10:39:08 +00:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-01-26 03:53:38 +00:00
|
|
|
import Field from "../elements/Field";
|
2021-06-07 14:48:55 +00:00
|
|
|
import Spinner from "../elements/Spinner";
|
2019-02-20 23:13:35 +00:00
|
|
|
import ErrorDialog from "../dialogs/ErrorDialog";
|
2019-12-26 18:52:57 +00:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2020-01-13 20:28:33 +00:00
|
|
|
import Modal from "../../../Modal";
|
2020-03-16 16:27:06 +00:00
|
|
|
import RoomPublishSetting from "./RoomPublishSetting";
|
2021-06-07 14:48:55 +00:00
|
|
|
import RoomAliasField from "../elements/RoomAliasField";
|
2022-01-04 09:22:51 +00:00
|
|
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
2021-12-09 17:44:22 +00:00
|
|
|
import SettingsFieldset from "../settings/SettingsFieldset";
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
interface IEditableAliasesListProps {
|
2022-02-01 15:06:26 +00:00
|
|
|
roomId?: string;
|
2021-06-07 14:48:55 +00:00
|
|
|
domain?: string;
|
|
|
|
}
|
2020-01-05 21:58:36 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
|
|
|
|
private aliasField = createRef<RoomAliasField>();
|
2020-01-05 21:58:36 +00:00
|
|
|
|
2022-02-01 15:06:26 +00:00
|
|
|
private onAliasAdded = async (ev: SyntheticEvent) => {
|
|
|
|
ev.preventDefault();
|
2021-06-07 14:48:55 +00:00
|
|
|
await this.aliasField.current.validate({ allowEmpty: false });
|
2020-01-05 21:58:36 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
if (this.aliasField.current.isValid) {
|
2020-01-05 21:58:36 +00:00
|
|
|
if (this.props.onItemAdded) this.props.onItemAdded(this.props.newItem);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
this.aliasField.current.focus();
|
|
|
|
this.aliasField.current.validate({ allowEmpty: false, focused: true });
|
2020-01-05 21:58:36 +00:00
|
|
|
};
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
protected renderNewItemField() {
|
2022-02-01 15:06:26 +00:00
|
|
|
const onChange = (alias: string) => this.onNewItemChanged({ target: { value: alias } });
|
2019-12-26 18:52:57 +00:00
|
|
|
return (
|
2019-12-27 17:05:51 +00:00
|
|
|
<form
|
2021-06-07 14:48:55 +00:00
|
|
|
onSubmit={this.onAliasAdded}
|
2019-12-27 17:05:51 +00:00
|
|
|
autoComplete="off"
|
|
|
|
noValidate={true}
|
|
|
|
className="mx_EditableItemList_newItem"
|
|
|
|
>
|
2019-12-26 18:52:57 +00:00
|
|
|
<RoomAliasField
|
2021-06-07 14:48:55 +00:00
|
|
|
ref={this.aliasField}
|
2019-12-26 18:52:57 +00:00
|
|
|
onChange={onChange}
|
|
|
|
value={this.props.newItem || ""}
|
2022-02-01 15:06:26 +00:00
|
|
|
domain={this.props.domain}
|
|
|
|
roomId={this.props.roomId}
|
|
|
|
/>
|
2021-06-07 14:48:55 +00:00
|
|
|
<AccessibleButton onClick={this.onAliasAdded} kind="primary">
|
2019-12-27 17:05:51 +00:00
|
|
|
{ _t("Add") }
|
2019-12-26 18:52:57 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
interface IProps {
|
|
|
|
roomId: string;
|
|
|
|
canSetCanonicalAlias: boolean;
|
|
|
|
canSetAliases: boolean;
|
|
|
|
canonicalAliasEvent?: MatrixEvent;
|
2021-06-08 15:32:43 +00:00
|
|
|
hidePublishSetting?: boolean;
|
2021-06-07 14:48:55 +00:00
|
|
|
}
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
interface IState {
|
|
|
|
altAliases: string[];
|
|
|
|
localAliases: string[];
|
|
|
|
canonicalAlias?: string;
|
|
|
|
updatingCanonicalAlias: boolean;
|
|
|
|
localAliasesLoading: boolean;
|
|
|
|
detailsOpen: boolean;
|
|
|
|
newAlias?: string;
|
|
|
|
newAltAlias?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class AliasSettings extends React.Component<IProps, IState> {
|
2022-01-04 09:22:51 +00:00
|
|
|
public static contextType = MatrixClientContext;
|
|
|
|
context: ContextType<typeof MatrixClientContext>;
|
|
|
|
|
2019-02-20 23:13:35 +00:00
|
|
|
static defaultProps = {
|
|
|
|
canSetAliases: false,
|
|
|
|
canSetCanonicalAlias: false,
|
|
|
|
};
|
|
|
|
|
2022-01-04 09:22:51 +00:00
|
|
|
constructor(props, context: ContextType<typeof MatrixClientContext>) {
|
|
|
|
super(props, context);
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
const state = {
|
2020-03-09 15:26:43 +00:00
|
|
|
altAliases: [], // [ #alias:domain.tld, ... ]
|
|
|
|
localAliases: [], // [ #alias:my-hs.tld, ... ]
|
|
|
|
canonicalAlias: null, // #canonical:domain.tld
|
2019-02-21 23:11:09 +00:00
|
|
|
updatingCanonicalAlias: false,
|
2020-03-09 15:26:43 +00:00
|
|
|
localAliasesLoading: false,
|
2020-03-16 17:24:49 +00:00
|
|
|
detailsOpen: false,
|
2016-02-02 12:46:14 +00:00
|
|
|
};
|
|
|
|
|
2019-02-21 23:27:49 +00:00
|
|
|
if (props.canonicalAliasEvent) {
|
2020-03-09 15:26:43 +00: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 17:01:14 +00:00
|
|
|
}
|
2018-09-20 00:07:01 +00:00
|
|
|
|
2019-02-21 23:27:49 +00:00
|
|
|
this.state = state;
|
2019-02-20 23:13:35 +00:00
|
|
|
}
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2020-03-09 15:26:43 +00:00
|
|
|
componentDidMount() {
|
2020-03-09 15:43:52 +00:00
|
|
|
if (this.props.canSetCanonicalAlias) {
|
|
|
|
// load local aliases for providing recommendations
|
|
|
|
// for the canonical alias and alt_aliases
|
|
|
|
this.loadLocalAliases();
|
|
|
|
}
|
2020-03-09 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private async loadLocalAliases() {
|
2020-03-09 15:26:43 +00:00
|
|
|
this.setState({ localAliasesLoading: true });
|
2020-02-19 14:15:05 +00:00
|
|
|
try {
|
2022-01-04 09:22:51 +00:00
|
|
|
const mxClient = this.context;
|
2022-05-25 21:56:30 +00:00
|
|
|
|
2020-03-09 15:26:43 +00:00
|
|
|
let localAliases = [];
|
2022-05-25 21:56:30 +00:00
|
|
|
const response = await mxClient.getLocalAliases(this.props.roomId);
|
|
|
|
if (Array.isArray(response?.aliases)) {
|
|
|
|
localAliases = response.aliases;
|
2020-02-19 14:15:05 +00:00
|
|
|
}
|
2020-03-09 15:26:43 +00:00
|
|
|
this.setState({ localAliases });
|
2021-06-12 04:24:05 +00:00
|
|
|
|
|
|
|
if (localAliases.length === 0) {
|
|
|
|
this.setState({ detailsOpen: true });
|
|
|
|
}
|
2020-02-19 14:15:05 +00:00
|
|
|
} finally {
|
2020-03-09 15:26:43 +00:00
|
|
|
this.setState({ localAliasesLoading: false });
|
2020-02-18 14:57:17 +00:00
|
|
|
}
|
2019-02-20 23:13:35 +00:00
|
|
|
}
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private changeCanonicalAlias(alias: string) {
|
2019-02-21 23:11:09 +00:00
|
|
|
if (!this.props.canSetCanonicalAlias) return;
|
|
|
|
|
2020-03-09 15:26:43 +00:00
|
|
|
const oldAlias = this.state.canonicalAlias;
|
2019-02-21 23:11:09 +00:00
|
|
|
this.setState({
|
|
|
|
canonicalAlias: alias,
|
|
|
|
updatingCanonicalAlias: true,
|
|
|
|
});
|
|
|
|
|
2020-03-09 15:26:43 +00:00
|
|
|
const eventContent = {
|
|
|
|
alt_aliases: this.state.altAliases,
|
|
|
|
};
|
|
|
|
|
2019-02-21 23:11:09 +00:00
|
|
|
if (alias) eventContent["alias"] = alias;
|
|
|
|
|
2022-01-04 09:22:51 +00:00
|
|
|
this.context.sendStateEvent(this.props.roomId, "m.room.canonical_alias",
|
2019-02-21 23:11:09 +00:00
|
|
|
eventContent, "").catch((err) => {
|
2021-10-15 14:30:53 +00:00
|
|
|
logger.error(err);
|
2022-06-14 16:51:51 +00:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
2019-02-21 23:11:09 +00:00
|
|
|
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 00:53:29 +00:00
|
|
|
"or a temporary failure occurred.",
|
2019-02-21 23:11:09 +00:00
|
|
|
),
|
|
|
|
});
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ canonicalAlias: oldAlias });
|
2019-02-21 23:11:09 +00:00
|
|
|
}).finally(() => {
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ updatingCanonicalAlias: false });
|
2019-02-21 23:11:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private changeAltAliases(altAliases: string[]) {
|
2020-03-09 15:29:04 +00:00
|
|
|
if (!this.props.canSetCanonicalAlias) return;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
updatingCanonicalAlias: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const eventContent = {};
|
|
|
|
|
|
|
|
if (this.state.canonicalAlias) {
|
2021-06-07 14:48:55 +00:00
|
|
|
eventContent["alias"] = this.state.canonicalAlias;
|
2020-03-09 15:29:04 +00:00
|
|
|
}
|
|
|
|
if (altAliases) {
|
|
|
|
eventContent["alt_aliases"] = altAliases;
|
|
|
|
}
|
|
|
|
|
2022-01-04 09:22:51 +00:00
|
|
|
this.context.sendStateEvent(this.props.roomId, "m.room.canonical_alias", eventContent, "")
|
|
|
|
.then(() => {
|
|
|
|
this.setState({
|
|
|
|
altAliases,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
// TODO: Add error handling based upon server validation
|
|
|
|
logger.error(err);
|
2022-06-14 16:51:51 +00:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
2022-01-04 09:22:51 +00:00
|
|
|
title: _t("Error updating main address"),
|
|
|
|
description: _t(
|
|
|
|
"There was an error updating the room's alternative addresses. " +
|
2020-03-09 15:50:34 +00:00
|
|
|
"It may not be allowed by the server or a temporary failure occurred.",
|
2022-01-04 09:22:51 +00:00
|
|
|
),
|
|
|
|
});
|
|
|
|
}).finally(() => {
|
|
|
|
this.setState({ updatingCanonicalAlias: false });
|
2020-03-09 15:29:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onNewAliasChanged = (value: string) => {
|
|
|
|
this.setState({ newAlias: value });
|
2019-02-20 23:13:35 +00:00
|
|
|
};
|
2017-10-04 09:00:01 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onLocalAliasAdded = (alias: string) => {
|
2016-02-02 12:46:14 +00:00
|
|
|
if (!alias || alias.length === 0) return; // ignore attempts to create blank aliases
|
|
|
|
|
2022-01-04 09:22:51 +00:00
|
|
|
const localDomain = this.context.getDomain();
|
2018-09-20 00:38:25 +00:00
|
|
|
if (!alias.includes(':')) alias += ':' + localDomain;
|
2020-01-05 21:58:36 +00:00
|
|
|
|
2022-01-04 09:22:51 +00:00
|
|
|
this.context.createAlias(alias, this.props.roomId).then(() => {
|
2020-01-05 21:58:36 +00:00
|
|
|
this.setState({
|
2020-03-09 15:26:43 +00:00
|
|
|
localAliases: this.state.localAliases.concat(alias),
|
|
|
|
newAlias: null,
|
2016-02-02 12:46:14 +00:00
|
|
|
});
|
2020-01-05 21:58:36 +00:00
|
|
|
if (!this.state.canonicalAlias) {
|
|
|
|
this.changeCanonicalAlias(alias);
|
|
|
|
}
|
|
|
|
}).catch((err) => {
|
2021-10-15 14:30:53 +00:00
|
|
|
logger.error(err);
|
2022-06-14 16:51:51 +00:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
2020-04-14 09:06:57 +00:00
|
|
|
title: _t("Error creating address"),
|
2020-01-05 21:58:36 +00:00
|
|
|
description: _t(
|
2020-04-14 09:06:57 +00:00
|
|
|
"There was an error creating that address. It may not be allowed by the server " +
|
2020-01-05 21:58:36 +00:00
|
|
|
"or a temporary failure occurred.",
|
|
|
|
),
|
2016-02-02 12:46:14 +00:00
|
|
|
});
|
2020-01-05 21:58:36 +00:00
|
|
|
});
|
2019-02-20 23:13:35 +00:00
|
|
|
};
|
2018-09-20 00:07:01 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onLocalAliasDeleted = (index: number) => {
|
2020-03-09 15:26:43 +00:00
|
|
|
const alias = this.state.localAliases[index];
|
2019-02-21 03:44:08 +00:00
|
|
|
// TODO: In future, we should probably be making sure that the alias actually belongs
|
2020-08-03 15:02:26 +00:00
|
|
|
// to this room. See https://github.com/vector-im/element-web/issues/7353
|
2022-01-04 09:22:51 +00:00
|
|
|
this.context.deleteAlias(alias).then(() => {
|
2020-03-17 19:37:40 +00:00
|
|
|
const localAliases = this.state.localAliases.filter(a => a !== alias);
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ localAliases });
|
2019-02-21 23:11:09 +00:00
|
|
|
|
|
|
|
if (this.state.canonicalAlias === alias) {
|
|
|
|
this.changeCanonicalAlias(null);
|
2019-02-21 03:44:08 +00:00
|
|
|
}
|
|
|
|
}).catch((err) => {
|
2021-10-15 14:30:53 +00:00
|
|
|
logger.error(err);
|
2020-03-11 11:13:28 +00:00
|
|
|
let description;
|
|
|
|
if (err.errcode === "M_FORBIDDEN") {
|
2020-04-14 09:06:57 +00:00
|
|
|
description = _t("You don't have permission to delete the address.");
|
2020-03-11 11:13:28 +00:00
|
|
|
} else {
|
|
|
|
description = _t(
|
2020-04-14 09:06:57 +00:00
|
|
|
"There was an error removing that address. It may no longer exist or a temporary " +
|
2019-02-22 00:53:29 +00:00
|
|
|
"error occurred.",
|
2020-03-11 11:13:28 +00:00
|
|
|
);
|
|
|
|
}
|
2022-06-14 16:51:51 +00:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
2020-04-14 09:06:57 +00:00
|
|
|
title: _t("Error removing address"),
|
2020-03-11 11:13:28 +00:00
|
|
|
description,
|
2018-09-20 00:07:01 +00:00
|
|
|
});
|
2019-02-21 03:44:08 +00:00
|
|
|
});
|
2019-02-20 23:13:35 +00:00
|
|
|
};
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onLocalAliasesToggled = (event: ChangeEvent<HTMLDetailsElement>) => {
|
2020-03-09 15:43:52 +00: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 14:48:55 +00:00
|
|
|
this.setState({ detailsOpen: event.currentTarget.open });
|
2020-03-09 15:43:52 +00:00
|
|
|
};
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onCanonicalAliasChange = (event: ChangeEvent<HTMLSelectElement>) => {
|
2019-02-21 23:11:09 +00:00
|
|
|
this.changeCanonicalAlias(event.target.value);
|
2019-02-20 23:13:35 +00:00
|
|
|
};
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onNewAltAliasChanged = (value: string) => {
|
|
|
|
this.setState({ newAltAlias: value });
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2020-03-09 15:29:04 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onAltAliasAdded = (alias: string) => {
|
2020-03-09 15:29:04 +00: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 14:48:55 +00:00
|
|
|
this.setState({ newAltAlias: "" });
|
2020-03-09 15:29:04 +00:00
|
|
|
}
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2020-03-09 15:29:04 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private onAltAliasDeleted = (index: number) => {
|
2020-03-09 15:29:04 +00:00
|
|
|
const altAliases = this.state.altAliases.slice();
|
|
|
|
altAliases.splice(index, 1);
|
|
|
|
this.changeAltAliases(altAliases);
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2020-03-09 15:29:04 +00:00
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private getAliases() {
|
|
|
|
return this.state.altAliases.concat(this.getLocalNonAltAliases());
|
2020-03-09 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 14:48:55 +00:00
|
|
|
private getLocalNonAltAliases() {
|
2021-06-29 12:11:58 +00:00
|
|
|
const { altAliases } = this.state;
|
2020-03-09 15:26:43 +00:00
|
|
|
return this.state.localAliases.filter(alias => !altAliases.includes(alias));
|
|
|
|
}
|
|
|
|
|
2019-02-20 23:13:35 +00:00
|
|
|
render() {
|
2022-01-04 09:22:51 +00:00
|
|
|
const mxClient = this.context;
|
|
|
|
const localDomain = mxClient.getDomain();
|
|
|
|
const isSpaceRoom = mxClient.getRoom(this.props.roomId)?.isSpaceRoom();
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2019-02-21 23:33:02 +00:00
|
|
|
let found = false;
|
|
|
|
const canonicalValue = this.state.canonicalAlias || "";
|
|
|
|
const canonicalAliasSection = (
|
2021-04-27 15:23:27 +00:00
|
|
|
<Field
|
|
|
|
onChange={this.onCanonicalAliasChange}
|
|
|
|
value={canonicalValue}
|
|
|
|
disabled={this.state.updatingCanonicalAlias || !this.props.canSetCanonicalAlias}
|
|
|
|
element='select'
|
|
|
|
id='canonicalAlias'
|
|
|
|
label={_t('Main address')}
|
|
|
|
>
|
2019-02-21 23:33:02 +00:00
|
|
|
<option value="" key="unset">{ _t('not specified') }</option>
|
|
|
|
{
|
2021-06-07 14:48:55 +00:00
|
|
|
this.getAliases().map((alias, i) => {
|
2020-03-09 15:26:43 +00:00
|
|
|
if (alias === this.state.canonicalAlias) found = true;
|
|
|
|
return (
|
|
|
|
<option value={alias} key={i}>
|
|
|
|
{ alias }
|
|
|
|
</option>
|
|
|
|
);
|
2019-02-21 23:33:02 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
{
|
|
|
|
found || !this.state.canonicalAlias ? '' :
|
2021-07-19 21:43:11 +00:00
|
|
|
<option value={this.state.canonicalAlias} key='arbitrary'>
|
2021-04-27 15:23:27 +00:00
|
|
|
{ this.state.canonicalAlias }
|
|
|
|
</option>
|
2019-02-21 23:33:02 +00:00
|
|
|
}
|
|
|
|
</Field>
|
|
|
|
);
|
2016-02-02 12:46:14 +00:00
|
|
|
|
2022-02-01 15:06:26 +00:00
|
|
|
let localAliasesList: JSX.Element;
|
2020-02-19 14:15:05 +00:00
|
|
|
if (this.state.localAliasesLoading) {
|
|
|
|
localAliasesList = <Spinner />;
|
|
|
|
} else {
|
2020-03-09 15:26:43 +00:00
|
|
|
localAliasesList = (<EditableAliasesList
|
2020-02-19 14:15:05 +00:00
|
|
|
id="roomAliases"
|
2020-03-09 15:26:43 +00:00
|
|
|
items={this.state.localAliases}
|
2020-02-19 14:15:05 +00: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 15:32:43 +00:00
|
|
|
noItemsLabel={isSpaceRoom
|
|
|
|
? _t("This space has no local addresses")
|
|
|
|
: _t("This room has no local addresses")}
|
2020-03-16 17:25:13 +00:00
|
|
|
placeholder={_t('Local address')}
|
2020-02-19 14:15:05 +00:00
|
|
|
domain={localDomain}
|
2020-03-09 15:26:43 +00:00
|
|
|
/>);
|
2020-02-19 14:15:05 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 12:46:14 +00:00
|
|
|
return (
|
2019-01-28 18:34:21 +00:00
|
|
|
<div className='mx_AliasSettings'>
|
2021-12-09 17:44:22 +00:00
|
|
|
<SettingsFieldset
|
2022-01-06 10:09:26 +00:00
|
|
|
data-test-id='published-address-fieldset'
|
2021-12-09 17:44:22 +00:00
|
|
|
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.") }
|
|
|
|
|
|
|
|
{ _t("To publish an address, it needs to be set as a local address first.") }
|
|
|
|
</>}
|
|
|
|
>
|
|
|
|
{ /*
|
2021-07-19 21:43:11 +00:00
|
|
|
<span className='mx_SettingsTab_subheading'>{ _t("Published Addresses") }</span>
|
2021-06-08 15:32:43 +00:00
|
|
|
<p>
|
|
|
|
{ isSpaceRoom
|
|
|
|
? _t("Published addresses can be used by anyone on any server to join your space.")
|
2021-07-19 21:43:11 +00:00
|
|
|
: _t("Published addresses can be used by anyone on any server to join your room.") }
|
2021-06-08 15:32:43 +00:00
|
|
|
|
|
|
|
{ _t("To publish an address, it needs to be set as a local address first.") }
|
2021-12-09 17:44:22 +00:00
|
|
|
</p> */ }
|
|
|
|
{ canonicalAliasSection }
|
|
|
|
{ this.props.hidePublishSetting
|
|
|
|
? null
|
|
|
|
: <RoomPublishSetting
|
|
|
|
roomId={this.props.roomId}
|
|
|
|
canSetCanonicalAlias={this.props.canSetCanonicalAlias}
|
|
|
|
/> }
|
|
|
|
<datalist id="mx_AliasSettings_altRecommendations">
|
|
|
|
{ this.getLocalNonAltAliases().map(alias => {
|
|
|
|
return <option value={alias} key={alias} />;
|
|
|
|
}) };
|
|
|
|
</datalist>
|
|
|
|
<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}
|
|
|
|
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)')}
|
2022-02-01 15:06:26 +00:00
|
|
|
roomId={this.props.roomId}
|
2021-12-09 17:44:22 +00:00
|
|
|
/>
|
|
|
|
</SettingsFieldset>
|
2022-01-06 10:09:26 +00:00
|
|
|
<SettingsFieldset
|
|
|
|
data-test-id='local-address-fieldset'
|
|
|
|
legend={_t("Local Addresses")}
|
2021-12-09 17:44:22 +00:00
|
|
|
description={isSpaceRoom
|
2021-06-08 15:32:43 +00:00
|
|
|
? _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-12-09 17:44:22 +00:00
|
|
|
"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 }
|
|
|
|
</details>
|
|
|
|
</SettingsFieldset>
|
|
|
|
|
2016-02-02 12:46:14 +00:00
|
|
|
</div>
|
|
|
|
);
|
2019-02-20 23:13:35 +00:00
|
|
|
}
|
2019-02-22 01:18:12 +00:00
|
|
|
}
|