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

Commit dca4b8b

Browse files
Fix wrong buttons being used when exploring public rooms (#9062)
1 parent be0f4a1 commit dca4b8b

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

cypress/e2e/12-spotlight/spotlight.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ describe("Spotlight", () => {
139139
const room2Name = "Lounge";
140140
let room2Id: string;
141141

142+
const room3Name = "Public";
143+
let room3Id: string;
144+
142145
beforeEach(() => {
143146
cy.startSynapse("default").then(data => {
144147
synapse = data;
@@ -163,6 +166,19 @@ describe("Spotlight", () => {
163166
room2Id = _room2Id;
164167
bot2.invite(room2Id, bot1.getUserId());
165168
});
169+
bot2.createRoom({
170+
name: room3Name,
171+
visibility: Visibility.Public, initial_state: [{
172+
type: "m.room.history_visibility",
173+
state_key: "",
174+
content: {
175+
history_visibility: "world_readable",
176+
},
177+
}],
178+
}).then(({ room_id: _room3Id }) => {
179+
room3Id = _room3Id;
180+
bot2.invite(room3Id, bot1.getUserId());
181+
});
166182
}),
167183
).then(() =>
168184
cy.get('.mx_RoomSublist_skeletonUI').should('not.exist'),
@@ -212,6 +228,7 @@ describe("Spotlight", () => {
212228
cy.spotlightSearch().clear().type(room1Name);
213229
cy.spotlightResults().should("have.length", 1);
214230
cy.spotlightResults().eq(0).should("contain", room1Name);
231+
cy.spotlightResults().eq(0).should("contain", "View");
215232
cy.spotlightResults().eq(0).click();
216233
cy.url().should("contain", room1Id);
217234
}).then(() => {
@@ -225,6 +242,7 @@ describe("Spotlight", () => {
225242
cy.spotlightSearch().clear().type(room2Name);
226243
cy.spotlightResults().should("have.length", 1);
227244
cy.spotlightResults().eq(0).should("contain", room2Name);
245+
cy.spotlightResults().eq(0).should("contain", "Join");
228246
cy.spotlightResults().eq(0).click();
229247
cy.url().should("contain", room2Id);
230248
}).then(() => {
@@ -233,6 +251,21 @@ describe("Spotlight", () => {
233251
});
234252
});
235253

254+
it("should find unknown public world readable rooms", () => {
255+
cy.openSpotlightDialog().within(() => {
256+
cy.spotlightFilter(Filter.PublicRooms);
257+
cy.spotlightSearch().clear().type(room3Name);
258+
cy.spotlightResults().should("have.length", 1);
259+
cy.spotlightResults().eq(0).should("contain", room3Name);
260+
cy.spotlightResults().eq(0).should("contain", "View");
261+
cy.spotlightResults().eq(0).click();
262+
cy.url().should("contain", room3Id);
263+
}).then(() => {
264+
cy.get(".mx_RoomPreviewBar_actions .mx_AccessibleButton").click();
265+
cy.roomHeaderName().should("contain", room3Name);
266+
});
267+
});
268+
236269
// TODO: We currently can’t test finding rooms on other homeservers/other protocols
237270
// We obviously don’t have federation or bridges in cypress tests
238271
/*

src/components/views/dialogs/spotlight/SpotlightDialog.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,16 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
607607
}
608608
if (isPublicRoomResult(result)) {
609609
const clientRoom = cli.getRoom(result.publicRoom.room_id);
610+
// Element Web currently does not allow guests to join rooms, so we
611+
// instead show them view buttons for all rooms. If the room is not
612+
// world readable, a modal will appear asking you to register first. If
613+
// it is readable, the preview appears as normal.
614+
const showViewButton = (
615+
clientRoom?.getMyMembership() === "join" ||
616+
result.publicRoom.world_readable ||
617+
cli.isGuest()
618+
);
619+
610620
const listener = (ev) => {
611621
const { publicRoom } = result;
612622
viewRoom({
@@ -622,11 +632,11 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
622632
onClick={listener}
623633
endAdornment={
624634
<AccessibleButton
625-
kind={clientRoom ? "primary" : "primary_outline"}
635+
kind={showViewButton ? "primary_outline" : "primary"}
626636
onClick={listener}
627637
tabIndex={-1}
628638
>
629-
{ _t(clientRoom ? "View" : "Join") }
639+
{ showViewButton ? _t("View") : _t("Join") }
630640
</AccessibleButton>}
631641
aria-labelledby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_name`}
632642
aria-describedby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_alias`}

0 commit comments

Comments
 (0)