Skip to content

Commit a79f6e7

Browse files
authored
Add option to hide pinned message banner in room view (#31296)
* feat: add `hidePinnedMessageBanner` to room view * test: add test for `hidePinnedMessageBanner`
1 parent 81c3750 commit a79f6e7

3 files changed

Lines changed: 421 additions & 19 deletions

File tree

src/components/structures/RoomView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ interface IRoomProps extends RoomViewProps {
180180
* If true, hide the right panel
181181
*/
182182
hideRightPanel?: boolean;
183+
184+
/**
185+
* If true, hide the pinned messages banner
186+
*/
187+
hidePinnedMessageBanner?: boolean;
183188
}
184189

185190
export { MainSplitContentType };
@@ -2464,7 +2469,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
24642469
</AuxPanel>
24652470
);
24662471

2467-
const pinnedMessageBanner = (
2472+
const pinnedMessageBanner = !this.props.hidePinnedMessageBanner && (
24682473
<PinnedMessageBanner room={this.state.room} permalinkCreator={this.permalinkCreator} />
24692474
);
24702475

test/unit-tests/components/structures/RoomView-test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import { CallStore } from "../../../../src/stores/CallStore.ts";
7777
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../../../../src/MediaDeviceHandler.ts";
7878
import Modal, { type ComponentProps } from "../../../../src/Modal.tsx";
7979
import ErrorDialog from "../../../../src/components/views/dialogs/ErrorDialog.tsx";
80+
import * as pinnedEventHooks from "../../../../src/hooks/usePinnedEvents";
8081

8182
// Used by group calls
8283
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
@@ -124,6 +125,11 @@ describe("RoomView", () => {
124125
afterEach(() => {
125126
unmockPlatformPeg();
126127
jest.clearAllMocks();
128+
129+
// Can't jest.restoreAllMocks() because some tests will break
130+
jest.spyOn(pinnedEventHooks, "usePinnedEvents").mockRestore();
131+
jest.spyOn(pinnedEventHooks, "useSortedFetchedPinnedEvents").mockRestore();
132+
127133
cleanup();
128134
});
129135

@@ -298,6 +304,35 @@ describe("RoomView", () => {
298304
expect(asFragment()).toMatchSnapshot();
299305
});
300306

307+
it("should hide the pinned message banner when hidePinnedMessageBanner=true", async () => {
308+
// Join the room
309+
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
310+
311+
const pinnedEvent = new MatrixEvent({
312+
type: EventType.RoomMessage,
313+
sender: "@alice:example.org",
314+
content: {
315+
body: "First pinned message",
316+
msgtype: "m.text",
317+
},
318+
room_id: room.roomId,
319+
origin_server_ts: 0,
320+
event_id: "$eventId",
321+
});
322+
323+
jest.spyOn(pinnedEventHooks, "usePinnedEvents").mockReturnValue([pinnedEvent.getId()!]);
324+
jest.spyOn(pinnedEventHooks, "useSortedFetchedPinnedEvents").mockReturnValue([pinnedEvent]);
325+
326+
const { asFragment, rerender } = await mountRoomView(undefined);
327+
// Check that the pinned message banner is rendered
328+
await expect(screen.findByTestId("pinned-message-banner")).resolves.toBeTruthy();
329+
// Now rerender with hidePinnedMessagesBanner=true
330+
rerender(<RoomView threepidInvite={undefined} forceTimeline={false} hidePinnedMessageBanner={true} />);
331+
// Check that the pinned message banner is not rendered
332+
await expect(screen.findByTestId("pinned-message-banner")).rejects.toThrow();
333+
expect(asFragment()).toMatchSnapshot();
334+
});
335+
301336
describe("invites", () => {
302337
beforeEach(() => {
303338
const member = new RoomMember(room.roomId, cli.getSafeUserId());

0 commit comments

Comments
 (0)