Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3e0c6fc

Browse files
t3chguydbkr
authored andcommitted
Fix publishing address wrongly demanding the alias be available (#7690)
1 parent bdcdd74 commit 3e0c6fc

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

src/components/views/elements/RoomAliasField.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ interface IProps {
2828
label?: string;
2929
placeholder?: string;
3030
disabled?: boolean;
31+
// if roomId is passed then the entered alias is checked to point to this roomId, else must be unassigned
32+
roomId?: string;
3133
onKeyDown?: KeyboardEventHandler;
3234
onChange?(value: string): void;
3335
}
@@ -165,7 +167,24 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
165167
key: "required",
166168
test: async ({ value, allowEmpty }) => allowEmpty || !!value,
167169
invalid: () => _t("Please provide an address"),
168-
}, {
170+
}, this.props.roomId ? {
171+
key: "matches",
172+
final: true,
173+
test: async ({ value }) => {
174+
if (!value) {
175+
return true;
176+
}
177+
const client = this.context;
178+
try {
179+
const result = await client.getRoomIdForAlias(this.asFullAlias(value));
180+
return result.room_id === this.props.roomId;
181+
} catch (err) {
182+
console.log(err);
183+
return false;
184+
}
185+
},
186+
invalid: () => _t("This address does not point at this room"),
187+
} : {
169188
key: "taken",
170189
final: true,
171190
test: async ({ value }) => {

src/components/views/room_settings/AliasSettings.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { ChangeEvent, ContextType, createRef } from "react";
17+
import React, { ChangeEvent, ContextType, createRef, SyntheticEvent } from "react";
1818
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
1919
import { logger } from "matrix-js-sdk/src/logger";
2020

@@ -32,13 +32,15 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
3232
import SettingsFieldset from "../settings/SettingsFieldset";
3333

3434
interface IEditableAliasesListProps {
35+
roomId?: string;
3536
domain?: string;
3637
}
3738

3839
class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
3940
private aliasField = createRef<RoomAliasField>();
4041

41-
private onAliasAdded = async () => {
42+
private onAliasAdded = async (ev: SyntheticEvent) => {
43+
ev.preventDefault();
4244
await this.aliasField.current.validate({ allowEmpty: false });
4345

4446
if (this.aliasField.current.isValid) {
@@ -51,7 +53,7 @@ class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
5153
};
5254

5355
protected renderNewItemField() {
54-
const onChange = (alias) => this.onNewItemChanged({ target: { value: alias } });
56+
const onChange = (alias: string) => this.onNewItemChanged({ target: { value: alias } });
5557
return (
5658
<form
5759
onSubmit={this.onAliasAdded}
@@ -63,7 +65,9 @@ class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
6365
ref={this.aliasField}
6466
onChange={onChange}
6567
value={this.props.newItem || ""}
66-
domain={this.props.domain} />
68+
domain={this.props.domain}
69+
roomId={this.props.roomId}
70+
/>
6771
<AccessibleButton onClick={this.onAliasAdded} kind="primary">
6872
{ _t("Add") }
6973
</AccessibleButton>
@@ -360,7 +364,7 @@ export default class AliasSettings extends React.Component<IProps, IState> {
360364
</Field>
361365
);
362366

363-
let localAliasesList;
367+
let localAliasesList: JSX.Element;
364368
if (this.state.localAliasesLoading) {
365369
localAliasesList = <Spinner />;
366370
} else {
@@ -428,6 +432,7 @@ export default class AliasSettings extends React.Component<IProps, IState> {
428432
itemsLabel={_t('Other published addresses:')}
429433
noItemsLabel={_t('No other published addresses yet, add one below')}
430434
placeholder={_t('New published address (e.g. #alias:server)')}
435+
roomId={this.props.roomId}
431436
/>
432437
</SettingsFieldset>
433438
<SettingsFieldset

src/components/views/settings/JoinRuleSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh
6262
onError,
6363
);
6464

65-
const { join_rule: joinRule } = content;
65+
const { join_rule: joinRule = JoinRule.Invite } = content || {};
6666
const restrictedAllowRoomIds = joinRule === JoinRule.Restricted
67-
? content.allow.filter(o => o.type === RestrictedAllowType.RoomMembership).map(o => o.room_id)
67+
? content.allow?.filter(o => o.type === RestrictedAllowType.RoomMembership).map(o => o.room_id)
6868
: undefined;
6969

7070
const editRestrictedRoomIds = async (): Promise<string[] | undefined> => {

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,7 @@
23102310
"Missing room name or separator e.g. (my-room:domain.org)": "Missing room name or separator e.g. (my-room:domain.org)",
23112311
"Some characters not allowed": "Some characters not allowed",
23122312
"Please provide an address": "Please provide an address",
2313+
"This address does not point at this room": "This address does not point at this room",
23132314
"This address is available to use": "This address is available to use",
23142315
"This address is already in use": "This address is already in use",
23152316
"This address had invalid server or is already in use": "This address had invalid server or is already in use",

0 commit comments

Comments
 (0)