From 7a222bfd608bbc0c5d2a2860c6d44f6bcb5489d9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 8 Apr 2024 09:05:43 +0100 Subject: [PATCH 1/4] Fix inability to join a `knock` room via space hierarchy view Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/SpaceHierarchy.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index dfd8ff5fce4..4536d1ffacf 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -41,6 +41,7 @@ import { HistoryVisibility, HierarchyRelation, HierarchyRoom, + JoinRule, } from "matrix-js-sdk/src/matrix"; import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy"; import classNames from "classnames"; @@ -157,7 +158,8 @@ const Tile: React.FC = ({ ); - } else if (joinedRoom) { + } else if (joinedRoom || room.join_rule === JoinRule.Knock) { + // We use the view flow for knock rooms as it allows us to reuse the request to join UX in RoomView button = ( Date: Mon, 8 Apr 2024 11:49:29 +0100 Subject: [PATCH 2/4] Update src/components/structures/SpaceHierarchy.tsx Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- src/components/structures/SpaceHierarchy.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index 4536d1ffacf..29e8c29c93c 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -159,7 +159,8 @@ const Tile: React.FC = ({ ); } else if (joinedRoom || room.join_rule === JoinRule.Knock) { - // We use the view flow for knock rooms as it allows us to reuse the request to join UX in RoomView + // If the room is knockable, show the "View" button even if we are not a member; that + // allows us to reuse the "request to join" UX in RoomView. button = ( Date: Tue, 9 Apr 2024 14:53:14 +0100 Subject: [PATCH 3/4] Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../structures/SpaceHierarchy-test.tsx | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 0246329d8d6..653b24fc538 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -17,7 +17,7 @@ limitations under the License. import React from "react"; import { mocked } from "jest-mock"; import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "@testing-library/react"; -import { MatrixClient, Room, HierarchyRoom } from "matrix-js-sdk/src/matrix"; +import { HierarchyRoom, JoinRule, MatrixClient, Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership } from "matrix-js-sdk/src/types"; import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy"; import { TooltipProvider } from "@vector-im/compound-web"; @@ -210,6 +210,13 @@ describe("SpaceHierarchy", () => { type: "m.space.child", sender: "@other:server", }, + { + state_key: "!knock1:server", + content: { order: "4" }, + origin_server_ts: 111, + type: "m.space.child", + sender: "@other:server", + }, ], world_readable: true, guest_can_join: true, @@ -253,9 +260,25 @@ describe("SpaceHierarchy", () => { world_readable: true, guest_can_join: true, }; + const hierarchyKnockRoom1: HierarchyRoom = { + room_id: "!knock1:server", + name: "Knock room", + num_joined_members: 3, + children_state: [], + world_readable: true, + guest_can_join: true, + join_rule: JoinRule.Knock, + }; mocked(client.getRoomHierarchy).mockResolvedValue({ - rooms: [hierarchyRoot, hierarchyRoom1, hierarchyRoom2, hierarchySpace1, hierarchyRoom3], + rooms: [ + hierarchyRoot, + hierarchyRoom1, + hierarchyRoom2, + hierarchySpace1, + hierarchyRoom3, + hierarchyKnockRoom1, + ], }); const defaultProps = { @@ -293,5 +316,24 @@ describe("SpaceHierarchy", () => { expect(client.joinRoom).toHaveBeenCalledWith(space1.roomId, expect.any(Object)); expect(client.joinRoom).toHaveBeenCalledWith(room3.roomId, expect.any(Object)); }); + + it("should take user to view room for unjoined knockable rooms", async () => { + jest.spyOn(dispatcher, "dispatch"); + + const { getByText } = render(getComponent()); + // Wait for spinners to go away + await waitForElementToBeRemoved(screen.getAllByRole("progressbar")); + const button = getByText("Knock room")! + .closest("li")! + .querySelector(".mx_AccessibleButton_kind_primary_outline")!; + fireEvent.click(button); + + expect(defaultProps.showRoom).toHaveBeenCalledWith( + expect.anything(), + expect.anything(), + hierarchyKnockRoom1.room_id, + undefined, + ); + }); }); }); From 1d373114e6fa441b73ac407e562f7940605e052d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 9 Apr 2024 14:59:03 +0100 Subject: [PATCH 4/4] Update snapshot Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../SpaceHierarchy-test.tsx.snap | 78 ++++++++++++++++++- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap b/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap index 4205a612222..f328c1fa0b2 100644 --- a/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap +++ b/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap @@ -195,6 +195,76 @@ exports[`SpaceHierarchy renders 1`] = ` +
  • +
    +
    +
    + + K + +
    +
    + Knock room +
    +
    + 3 members +
    +
    +
    +
    + View +
    + + +
    +
  • renders 1`] = ` class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid" >