From 3c70a918a93efa357223d3f686c9d4d2277399df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 16 Jul 2022 12:08:20 +0200 Subject: [PATCH 1/3] Fix wrong buttons being used when exploring public rooms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../views/dialogs/spotlight/SpotlightDialog.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index 4bf7b572392..e769bd58c83 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -603,6 +603,16 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n } if (isPublicRoomResult(result)) { const clientRoom = cli.getRoom(result.publicRoom.room_id); + // Element Web currently does not allow guests to join rooms, so we + // instead show them view buttons for all rooms. If the room is not + // world readable, a modal will appear asking you to register first. If + // it is readable, the preview appears as normal. + const showViewButton = ( + clientRoom?.getMyMembership() === "join" || + result.publicRoom.world_readable || + cli.isGuest() + ); + const listener = (ev) => { const { publicRoom } = result; viewRoom({ @@ -618,11 +628,11 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n onClick={listener} endAdornment={ - { _t(clientRoom ? "View" : "Join") } + { showViewButton ? _t("View") : _t("Join") } } aria-labelledby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_name`} aria-describedby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_alias`} From edb74500174ad1d27045d4bf84ef1bf0ff8223fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 16 Jul 2022 12:38:08 +0200 Subject: [PATCH 2/3] Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- cypress/e2e/12-spotlight/spotlight.spec.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cypress/e2e/12-spotlight/spotlight.spec.ts b/cypress/e2e/12-spotlight/spotlight.spec.ts index 7b5ca76fe15..372391d84e4 100644 --- a/cypress/e2e/12-spotlight/spotlight.spec.ts +++ b/cypress/e2e/12-spotlight/spotlight.spec.ts @@ -16,6 +16,9 @@ limitations under the License. /// +import { EventType } from "matrix-js-sdk/src/@types/event"; +import { HistoryVisibility } from "matrix-js-sdk/src/@types/partials"; + import { MatrixClient } from "../../global"; import { SynapseInstance } from "../../plugins/synapsedocker"; import Chainable = Cypress.Chainable; @@ -139,6 +142,9 @@ describe("Spotlight", () => { const room2Name = "Lounge"; let room2Id: string; + const room3Name = "Public"; + let room3Id: string; + beforeEach(() => { cy.startSynapse("default").then(data => { synapse = data; @@ -163,6 +169,19 @@ describe("Spotlight", () => { room2Id = _room2Id; bot2.invite(room2Id, bot1.getUserId()); }); + bot2.createRoom({ + name: room3Name, + visibility: Visibility.Public, initial_state: [{ + type: EventType.RoomHistoryVisibility, + state_key: "", + content: { + history_visibility: HistoryVisibility.WorldReadable, + }, + }], + }).then(({ room_id: _room3Id }) => { + room3Id = _room3Id; + bot2.invite(room3Id, bot1.getUserId()); + }); }), ).then(() => cy.get('.mx_RoomSublist_skeletonUI').should('not.exist'), @@ -212,6 +231,7 @@ describe("Spotlight", () => { cy.spotlightSearch().clear().type(room1Name); cy.spotlightResults().should("have.length", 1); cy.spotlightResults().eq(0).should("contain", room1Name); + cy.spotlightResults().eq(0).should("contain", "View"); cy.spotlightResults().eq(0).click(); cy.url().should("contain", room1Id); }).then(() => { @@ -225,6 +245,7 @@ describe("Spotlight", () => { cy.spotlightSearch().clear().type(room2Name); cy.spotlightResults().should("have.length", 1); cy.spotlightResults().eq(0).should("contain", room2Name); + cy.spotlightResults().eq(0).should("contain", "Join"); cy.spotlightResults().eq(0).click(); cy.url().should("contain", room2Id); }).then(() => { @@ -233,6 +254,21 @@ describe("Spotlight", () => { }); }); + it("should find unknown public world readable rooms", () => { + cy.openSpotlightDialog().within(() => { + cy.spotlightFilter(Filter.PublicRooms); + cy.spotlightSearch().clear().type(room3Name); + cy.spotlightResults().should("have.length", 1); + cy.spotlightResults().eq(0).should("contain", room3Name); + cy.spotlightResults().eq(0).should("contain", "View"); + cy.spotlightResults().eq(0).click(); + cy.url().should("contain", room3Id); + }).then(() => { + cy.get(".mx_RoomPreviewBar_actions .mx_AccessibleButton").click(); + cy.roomHeaderName().should("contain", room3Name); + }); + }); + // TODO: We currently can’t test finding rooms on other homeservers/other protocols // We obviously don’t have federation or bridges in cypress tests /* From 554f0817c514f923075782a3218484655f1ae6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 16 Jul 2022 12:57:28 +0200 Subject: [PATCH 3/3] Fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- cypress/e2e/12-spotlight/spotlight.spec.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/12-spotlight/spotlight.spec.ts b/cypress/e2e/12-spotlight/spotlight.spec.ts index 372391d84e4..a99bb43f6ab 100644 --- a/cypress/e2e/12-spotlight/spotlight.spec.ts +++ b/cypress/e2e/12-spotlight/spotlight.spec.ts @@ -16,9 +16,6 @@ limitations under the License. /// -import { EventType } from "matrix-js-sdk/src/@types/event"; -import { HistoryVisibility } from "matrix-js-sdk/src/@types/partials"; - import { MatrixClient } from "../../global"; import { SynapseInstance } from "../../plugins/synapsedocker"; import Chainable = Cypress.Chainable; @@ -172,10 +169,10 @@ describe("Spotlight", () => { bot2.createRoom({ name: room3Name, visibility: Visibility.Public, initial_state: [{ - type: EventType.RoomHistoryVisibility, + type: "m.room.history_visibility", state_key: "", content: { - history_visibility: HistoryVisibility.WorldReadable, + history_visibility: "world_readable", }, }], }).then(({ room_id: _room3Id }) => {