Fix publishing address wrongly demanding the alias be available (#7690)

This commit is contained in:
Michael Telatynski 2022-02-01 15:06:26 +00:00 committed by GitHub
parent bf8c04ff55
commit 98c5f50f36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 8 deletions

View file

@ -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<IProps, IState>
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 }) => {