diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 2e81dff67a8..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" ? 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(); + }); + }); });