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

Do not show "Forget room" button in Room View header for guest users #10898

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
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 (
<RoomContext.Provider value={this.state}>
<main className={mainClasses} ref={this.roomView} onKeyDown={this.onReactKeyDown}>
Expand All @@ -2473,7 +2477,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
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}
Expand Down
29 changes: 29 additions & 0 deletions test/components/structures/RoomView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Loading