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

Commit 4316eba

Browse files
spantaleevt3chguy
andauthored
Do not show "Forget room" button in Room View header for guest users (#10898)
* 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 <[email protected]> * Iterate --------- Signed-off-by: Slavi Pantaleev <[email protected]> Co-authored-by: Michael Telatynski <[email protected]>
1 parent d268cc1 commit 4316eba

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/components/structures/RoomView.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
24492449
viewingCall = true;
24502450
}
24512451

2452+
const myMember = this.state.room!.getMember(this.context.client!.getSafeUserId());
2453+
const showForgetButton =
2454+
!this.context.client.isGuest() && (["leave", "ban"].includes(myMembership) || myMember?.isKicked());
2455+
24522456
return (
24532457
<RoomContext.Provider value={this.state}>
24542458
<main className={mainClasses} ref={this.roomView} onKeyDown={this.onReactKeyDown}>
@@ -2463,7 +2467,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
24632467
inRoom={myMembership === "join"}
24642468
onSearchClick={onSearchClick}
24652469
onInviteClick={onInviteClick}
2466-
onForgetClick={myMembership === "leave" ? onForgetClick : null}
2470+
onForgetClick={showForgetButton ? onForgetClick : null}
24672471
e2eStatus={this.state.e2eStatus}
24682472
onAppsClick={this.state.hasPinnedWidgets ? onAppsClick : null}
24692473
appsShown={this.state.showApps}

test/components/structures/RoomView-test.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,33 @@ describe("RoomView", () => {
515515
await findByText("Are you sure you're at the right place?");
516516
expect(asFragment()).toMatchSnapshot();
517517
});
518+
519+
describe("Peeking", () => {
520+
beforeEach(() => {
521+
// Make room peekable
522+
room.currentState.setStateEvents([
523+
new MatrixEvent({
524+
type: "m.room.history_visibility",
525+
state_key: "",
526+
content: {
527+
history_visibility: "world_readable",
528+
},
529+
room_id: room.roomId,
530+
}),
531+
]);
532+
});
533+
534+
it("should show forget room button for non-guests", async () => {
535+
mocked(cli.isGuest).mockReturnValue(false);
536+
await mountRoomView();
537+
538+
expect(screen.getByLabelText("Forget room")).toBeInTheDocument();
539+
});
540+
541+
it("should not show forget room button for guests", async () => {
542+
mocked(cli.isGuest).mockReturnValue(true);
543+
await mountRoomView();
544+
expect(screen.queryByLabelText("Forget room")).not.toBeInTheDocument();
545+
});
546+
});
518547
});

0 commit comments

Comments
 (0)