From 5c780bae4ec3aaa7a3b27183486255f4b9e9f504 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Feb 2022 14:06:15 +0000 Subject: [PATCH 1/5] Fix enter wrongly causing page to refresh in alias settings --- src/components/views/room_settings/AliasSettings.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/views/room_settings/AliasSettings.tsx b/src/components/views/room_settings/AliasSettings.tsx index 1c127e57314..3e7605802ca 100644 --- a/src/components/views/room_settings/AliasSettings.tsx +++ b/src/components/views/room_settings/AliasSettings.tsx @@ -38,7 +38,8 @@ interface IEditableAliasesListProps { class EditableAliasesList extends EditableItemList { private aliasField = createRef(); - private onAliasAdded = async () => { + private onAliasAdded = async (ev: SyntheticEvent) => { + ev.preventDefault(); await this.aliasField.current.validate({ allowEmpty: false }); if (this.aliasField.current.isValid) { From 0d10246f95783ce329ad89c906c33f648c4016c9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Feb 2022 14:09:07 +0000 Subject: [PATCH 2/5] Null-guard for rooms without an m.room.join_rules --- src/components/views/settings/JoinRuleSettings.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/settings/JoinRuleSettings.tsx b/src/components/views/settings/JoinRuleSettings.tsx index 4ec832ca49d..d44947d8509 100644 --- a/src/components/views/settings/JoinRuleSettings.tsx +++ b/src/components/views/settings/JoinRuleSettings.tsx @@ -62,9 +62,9 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh onError, ); - const { join_rule: joinRule } = content; + const { join_rule: joinRule = JoinRule.Invite } = content || {}; const restrictedAllowRoomIds = joinRule === JoinRule.Restricted - ? content.allow.filter(o => o.type === RestrictedAllowType.RoomMembership).map(o => o.room_id) + ? content.allow?.filter(o => o.type === RestrictedAllowType.RoomMembership).map(o => o.room_id) : undefined; const editRestrictedRoomIds = async (): Promise => { From 070b978e4b59ee01c7e1f4f41b7b463ff4a75c4f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Feb 2022 14:09:34 +0000 Subject: [PATCH 3/5] Fix publishing address wrongly demanding the alias be available --- .../views/elements/RoomAliasField.tsx | 21 ++++++++++++++++++- .../views/room_settings/AliasSettings.tsx | 12 +++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/components/views/elements/RoomAliasField.tsx b/src/components/views/elements/RoomAliasField.tsx index 8e82f20a095..a8cf278a30c 100644 --- a/src/components/views/elements/RoomAliasField.tsx +++ b/src/components/views/elements/RoomAliasField.tsx @@ -28,6 +28,8 @@ interface IProps { label?: string; placeholder?: string; disabled?: boolean; + // if roomId is passed then the entered alias is checked to point to this roomId, else must be unassigned + roomId?: string; onKeyDown?: KeyboardEventHandler; onChange?(value: string): void; } @@ -165,7 +167,24 @@ export default class RoomAliasField extends React.PureComponent key: "required", test: async ({ value, allowEmpty }) => allowEmpty || !!value, invalid: () => _t("Please provide an address"), - }, { + }, this.props.roomId ? { + key: "matches", + final: true, + test: async ({ value }) => { + if (!value) { + return true; + } + const client = this.context; + try { + const result = await client.getRoomIdForAlias(this.asFullAlias(value)); + return result.room_id === this.props.roomId; + } catch (err) { + console.log(err); + return false; + } + }, + invalid: () => _t("This address does not point at this room"), + } : { key: "taken", final: true, test: async ({ value }) => { diff --git a/src/components/views/room_settings/AliasSettings.tsx b/src/components/views/room_settings/AliasSettings.tsx index 3e7605802ca..e87a6811984 100644 --- a/src/components/views/room_settings/AliasSettings.tsx +++ b/src/components/views/room_settings/AliasSettings.tsx @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { ChangeEvent, ContextType, createRef } from "react"; +import React, { ChangeEvent, ContextType, createRef, SyntheticEvent } from "react"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { logger } from "matrix-js-sdk/src/logger"; @@ -32,6 +32,7 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext"; import SettingsFieldset from "../settings/SettingsFieldset"; interface IEditableAliasesListProps { + roomId?: string; domain?: string; } @@ -52,7 +53,7 @@ class EditableAliasesList extends EditableItemList { }; protected renderNewItemField() { - const onChange = (alias) => this.onNewItemChanged({ target: { value: alias } }); + const onChange = (alias: string) => this.onNewItemChanged({ target: { value: alias } }); return (
{ ref={this.aliasField} onChange={onChange} value={this.props.newItem || ""} - domain={this.props.domain} /> + domain={this.props.domain} + roomId={this.props.roomId} + /> { _t("Add") } @@ -361,7 +364,7 @@ export default class AliasSettings extends React.Component { ); - let localAliasesList; + let localAliasesList: JSX.Element; if (this.state.localAliasesLoading) { localAliasesList = ; } else { @@ -379,6 +382,7 @@ export default class AliasSettings extends React.Component { : _t("This room has no local addresses")} placeholder={_t('Local address')} domain={localDomain} + roomId={this.props.roomId} />); } From ee91b88fe53e3e4446179dbe43a3cc07b55a4220 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Feb 2022 14:13:40 +0000 Subject: [PATCH 4/5] Fix inverse behaviour --- src/components/views/room_settings/AliasSettings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/room_settings/AliasSettings.tsx b/src/components/views/room_settings/AliasSettings.tsx index e87a6811984..ec84544aaec 100644 --- a/src/components/views/room_settings/AliasSettings.tsx +++ b/src/components/views/room_settings/AliasSettings.tsx @@ -382,7 +382,6 @@ export default class AliasSettings extends React.Component { : _t("This room has no local addresses")} placeholder={_t('Local address')} domain={localDomain} - roomId={this.props.roomId} />); } @@ -433,6 +432,7 @@ export default class AliasSettings extends React.Component { 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} /> Date: Tue, 1 Feb 2022 14:17:50 +0000 Subject: [PATCH 5/5] i18n --- src/i18n/strings/en_EN.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index bff54532f9d..1de12aa124b 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2317,6 +2317,7 @@ "Missing room name or separator e.g. (my-room:domain.org)": "Missing room name or separator e.g. (my-room:domain.org)", "Some characters not allowed": "Some characters not allowed", "Please provide an address": "Please provide an address", + "This address does not point at this room": "This address does not point at this room", "This address is available to use": "This address is available to use", "This address is already in use": "This address is already in use", "This address had invalid server or is already in use": "This address had invalid server or is already in use",