diff --git a/src/components/views/rooms/RoomHeader.tsx b/src/components/views/rooms/RoomHeader.tsx index 92d7c78ac9d7..7203cd2a7a78 100644 --- a/src/components/views/rooms/RoomHeader.tsx +++ b/src/components/views/rooms/RoomHeader.tsx @@ -51,6 +51,7 @@ import RightPanelStore from "../../../stores/right-panel/RightPanelStore"; import { Linkify, topicToHtml } from "../../../HtmlUtils"; import PosthogTrackers from "../../../PosthogTrackers"; import { VideoRoomChatButton } from "./RoomHeader/VideoRoomChatButton"; +import { RoomKnocksBar } from "./RoomKnocksBar"; /** * A helper to transform a notification color to the what the Compound Icon Button @@ -115,165 +116,170 @@ export default function RoomHeader({ [roomTopic?.html, roomTopic?.text], ); + const askToJoinEnabled = useFeatureEnabled("feature_ask_to_join"); + return ( - - + + {additionalButtons?.map((props) => { + const label = props.label(); - {isDirectMessage && e2eStatus === E2EStatus.Warning && ( - - + return ( + + { + event.stopPropagation(); + props.onClick(); + }} + > + {typeof props.icon === "function" ? props.icon() : props.icon} + - )} - - {roomTopic && ( - + - {roomTopicBody} - - )} - - - - {additionalButtons?.map((props) => { - const label = props.label(); - - return ( - + + + + {!useElementCallExclusively && ( + { - event.stopPropagation(); - props.onClick(); - }} + disabled={!!voiceCallDisabledReason} + aria-label={!voiceCallDisabledReason ? _t("voip|voice_call") : voiceCallDisabledReason!} + onClick={voiceCallClick} > - {typeof props.icon === "function" ? props.icon() : props.icon} + - ); - })} - - - - - - {!useElementCallExclusively && ( - - - - - - )} + )} - {/* Renders nothing when room is not a video room */} - + {/* Renders nothing when room is not a video room */} + - - { - evt.stopPropagation(); - RightPanelStore.instance.showOrHidePanel(RightPanelPhases.ThreadPanel); - PosthogTrackers.trackInteraction("WebRoomHeaderButtonsThreadsButton", evt); - }} - aria-label={_t("common|threads")} - > - - - - {notificationsEnabled && ( - + { evt.stopPropagation(); - RightPanelStore.instance.showOrHidePanel(RightPanelPhases.NotificationPanel); + RightPanelStore.instance.showOrHidePanel(RightPanelPhases.ThreadPanel); + PosthogTrackers.trackInteraction("WebRoomHeaderButtonsThreadsButton", evt); }} - aria-label={_t("notifications|enable_prompt_toast_title")} + aria-label={_t("common|threads")} > - + + {notificationsEnabled && ( + + { + evt.stopPropagation(); + RightPanelStore.instance.showOrHidePanel(RightPanelPhases.NotificationPanel); + }} + aria-label={_t("notifications|enable_prompt_toast_title")} + > + + + + )} + + {!isDirectMessage && ( + { + RightPanelStore.instance.showOrHidePanel(RightPanelPhases.RoomMemberList); + e.stopPropagation(); + }} + > + + {formatCount(memberCount)} + + )} - {!isDirectMessage && ( - { - RightPanelStore.instance.showOrHidePanel(RightPanelPhases.RoomMemberList); - e.stopPropagation(); - }} - > - - {formatCount(memberCount)} - - - )} - + {askToJoinEnabled && } + ); } diff --git a/test/components/views/rooms/RoomHeader-test.tsx b/test/components/views/rooms/RoomHeader-test.tsx index fc40241ad4f1..ffda789c5546 100644 --- a/test/components/views/rooms/RoomHeader-test.tsx +++ b/test/components/views/rooms/RoomHeader-test.tsx @@ -16,7 +16,15 @@ limitations under the License. import React from "react"; import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call"; -import { EventType, JoinRule, MatrixClient, MatrixEvent, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; +import { + EventType, + JoinRule, + MatrixClient, + MatrixEvent, + PendingEventOrdering, + Room, + RoomMember, +} from "matrix-js-sdk/src/matrix"; import { createEvent, fireEvent, @@ -562,6 +570,25 @@ describe("RoomHeader", () => { expect(callback).toHaveBeenCalled(); expect(event.stopPropagation).toHaveBeenCalled(); }); + + describe("ask to join disabled", () => { + it("does not render the RoomKnocksBar", () => { + render(, withClientContextRenderOptions(MatrixClientPeg.get()!)); + expect(screen.queryByRole("heading", { name: "Asking to join" })).not.toBeInTheDocument(); + }); + }); + + describe("ask to join enabled", () => { + it("does render the RoomKnocksBar", () => { + jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature === "feature_ask_to_join"); + jest.spyOn(room, "canInvite").mockReturnValue(true); + jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Knock); + jest.spyOn(room, "getMembersWithMembership").mockReturnValue([new RoomMember(room.roomId, "@foo")]); + + render(, withClientContextRenderOptions(MatrixClientPeg.get()!)); + expect(screen.getByRole("heading", { name: "Asking to join" })).toBeInTheDocument(); + }); + }); }); /**