From 55e97a342eb78bd8bf96bfd00768399e1a640e95 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sun, 14 May 2023 19:04:51 +0300 Subject: [PATCH 1/2] Do not show "Forget room" button in Room View header for guest users You can observe this problem by opening this in a new private tab: https://app.element.io/#/room/#matrix:matrix.org This is a public room with guest access enabled and Element will use a guest account to display it. Showing a "Forget room" button in the header for guest users is pointless. Clicking on it leads to a `M_GUEST_ACCESS_FORBIDDEN` error. Signed-off-by: Slavi Pantaleev --- src/components/structures/RoomView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index b4a38ee2eb8..f81751bfe0c 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -2454,7 +2454,7 @@ export class RoomView extends React.Component { inRoom={myMembership === "join"} onSearchClick={onSearchClick} onInviteClick={onInviteClick} - onForgetClick={myMembership === "leave" ? onForgetClick : null} + onForgetClick={myMembership === "leave" && !this.context.client.isGuest() ? onForgetClick : null} e2eStatus={this.state.e2eStatus} onAppsClick={this.state.hasPinnedWidgets ? onAppsClick : null} appsShown={this.state.showApps} From 0df2c3e1bce7ecd1822ac5a4074722759e2666a1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 21 Jul 2023 11:31:01 +0100 Subject: [PATCH 2/2] Iterate --- src/components/structures/RoomView.tsx | 6 +++- test/components/structures/RoomView-test.tsx | 29 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 936a72a9881..56d0b2b849e 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -2459,6 +2459,10 @@ export class RoomView extends React.Component { viewingCall = true; } + const myMember = this.state.room!.getMember(this.context.client!.getSafeUserId()); + const showForgetButton = + !this.context.client.isGuest() && (["leave", "ban"].includes(myMembership) || myMember?.isKicked()); + return (
@@ -2473,7 +2477,7 @@ export class RoomView extends React.Component { inRoom={myMembership === "join"} onSearchClick={onSearchClick} onInviteClick={onInviteClick} - onForgetClick={myMembership === "leave" && !this.context.client.isGuest() ? onForgetClick : null} + onForgetClick={showForgetButton ? onForgetClick : null} e2eStatus={this.state.e2eStatus} onAppsClick={this.state.hasPinnedWidgets ? onAppsClick : null} appsShown={this.state.showApps} diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index 1f3b0b955e2..aab93eefa83 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -515,4 +515,33 @@ describe("RoomView", () => { await findByText("Are you sure you're at the right place?"); expect(asFragment()).toMatchSnapshot(); }); + + describe("Peeking", () => { + beforeEach(() => { + // Make room peekable + room.currentState.setStateEvents([ + new MatrixEvent({ + type: "m.room.history_visibility", + state_key: "", + content: { + history_visibility: "world_readable", + }, + room_id: room.roomId, + }), + ]); + }); + + it("should show forget room button for non-guests", async () => { + mocked(cli.isGuest).mockReturnValue(false); + await mountRoomView(); + + expect(screen.getByLabelText("Forget room")).toBeInTheDocument(); + }); + + it("should not show forget room button for guests", async () => { + mocked(cli.isGuest).mockReturnValue(true); + await mountRoomView(); + expect(screen.queryByLabelText("Forget room")).not.toBeInTheDocument(); + }); + }); });