Do not ask for a room address when the room already has one (#34499)
This commit is contained in:
@@ -249,8 +249,13 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
|
||||
};
|
||||
|
||||
private async hasAliases(): Promise<boolean> {
|
||||
// The published addresses can live on any server, so a room can be linkable without this
|
||||
// server holding a local alias for it.
|
||||
const room = this.props.room;
|
||||
if (room.getCanonicalAlias() || room.getAltAliases().length > 0) return true;
|
||||
|
||||
const cli = this.context;
|
||||
const response = await cli.getLocalAliases(this.props.room.roomId);
|
||||
const response = await cli.getLocalAliases(room.roomId);
|
||||
const localAliases = response.aliases;
|
||||
return Array.isArray(localAliases) && localAliases.length !== 0;
|
||||
}
|
||||
|
||||
+56
@@ -581,4 +581,60 @@ describe("<SecurityRoomSettingsTab />", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("public room address warning", () => {
|
||||
const warning = "To link to this room, please add an address.";
|
||||
|
||||
const setCanonicalAlias = (room: Room, content: object): void => {
|
||||
room.currentState.setStateEvents([
|
||||
new MatrixEvent({
|
||||
type: EventType.RoomCanonicalAlias,
|
||||
content,
|
||||
sender: userId,
|
||||
state_key: "",
|
||||
room_id: room.roomId,
|
||||
}),
|
||||
]);
|
||||
};
|
||||
|
||||
const renderPublicRoom = async (configure?: (room: Room) => void): Promise<void> => {
|
||||
const room = new Room(roomId, client, userId);
|
||||
setRoomStateEvents(room, JoinRule.Public);
|
||||
configure?.(room);
|
||||
getComponent(room);
|
||||
await flushPromises();
|
||||
};
|
||||
|
||||
it("warns when the room has no address anywhere", async () => {
|
||||
client.getLocalAliases.mockResolvedValue({ aliases: [] });
|
||||
|
||||
await renderPublicRoom();
|
||||
|
||||
expect(screen.getByText(warning)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not warn when the room's main address is on another server", async () => {
|
||||
client.getLocalAliases.mockResolvedValue({ aliases: [] });
|
||||
|
||||
await renderPublicRoom((room) => setCanonicalAlias(room, { alias: "#room:other.server.org" }));
|
||||
|
||||
expect(screen.queryByText(warning)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not warn when the room only has alternative addresses", async () => {
|
||||
client.getLocalAliases.mockResolvedValue({ aliases: [] });
|
||||
|
||||
await renderPublicRoom((room) => setCanonicalAlias(room, { alt_aliases: ["#room:other.server.org"] }));
|
||||
|
||||
expect(screen.queryByText(warning)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not warn when the local server has an address for the room", async () => {
|
||||
client.getLocalAliases.mockResolvedValue({ aliases: ["#room:server.org"] });
|
||||
|
||||
await renderPublicRoom();
|
||||
|
||||
expect(screen.queryByText(warning)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user