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

Commit 2d8c23e

Browse files
authored
Hide voip buttons in group rooms in environments with widgets disabled (#12664)
* Hide voip buttons in group rooms in environments with widgets disabled Signed-off-by: Michael Telatynski <[email protected]> * Fix test stubs Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 5bcf76c commit 2d8c23e

File tree

3 files changed

+79
-23
lines changed

3 files changed

+79
-23
lines changed

src/components/views/rooms/RoomHeader.tsx

+23-20
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default function RoomHeader({
8383
hasActiveCallSession,
8484
callOptions,
8585
showVoiceCallButton,
86+
showVideoCallButton,
8687
} = useRoomCall(room);
8788

8889
const groupCallsEnabled = useFeatureEnabled("feature_group_calls");
@@ -200,39 +201,41 @@ export default function RoomHeader({
200201
)}
201202
</>
202203
);
203-
204-
let voiceCallButton: JSX.Element | undefined;
205-
if (showVoiceCallButton) {
206-
voiceCallButton = (
207-
<Tooltip label={voiceCallDisabledReason ?? _t("voip|voice_call")}>
208-
<IconButton
209-
// We need both: isViewingCall and isConnectedToCall
210-
// - in the Lobby we are viewing a call but are not connected to it.
211-
// - in pip view we are connected to the call but not viewing it.
212-
disabled={!!voiceCallDisabledReason || isViewingCall || isConnectedToCall}
213-
aria-label={voiceCallDisabledReason ?? _t("voip|voice_call")}
214-
onClick={(ev) => voiceCallClick(ev, callOptions[0])}
215-
>
216-
<VoiceCallIcon />
217-
</IconButton>
218-
</Tooltip>
219-
);
220-
}
221-
204+
let voiceCallButton: JSX.Element | undefined = (
205+
<Tooltip label={voiceCallDisabledReason ?? _t("voip|voice_call")}>
206+
<IconButton
207+
// We need both: isViewingCall and isConnectedToCall
208+
// - in the Lobby we are viewing a call but are not connected to it.
209+
// - in pip view we are connected to the call but not viewing it.
210+
disabled={!!voiceCallDisabledReason || isViewingCall || isConnectedToCall}
211+
aria-label={voiceCallDisabledReason ?? _t("voip|voice_call")}
212+
onClick={(ev) => voiceCallClick(ev, callOptions[0])}
213+
>
214+
<VoiceCallIcon />
215+
</IconButton>
216+
</Tooltip>
217+
);
222218
const closeLobbyButton = (
223219
<Tooltip label={_t("voip|close_lobby")}>
224220
<IconButton onClick={toggleCall} aria-label={_t("voip|close_lobby")}>
225221
<CloseCallIcon />
226222
</IconButton>
227223
</Tooltip>
228224
);
229-
let videoCallButton = startVideoCallButton;
225+
let videoCallButton: JSX.Element | undefined = startVideoCallButton;
230226
if (isConnectedToCall) {
231227
videoCallButton = toggleCallButton;
232228
} else if (isViewingCall) {
233229
videoCallButton = closeLobbyButton;
234230
}
235231

232+
if (!showVideoCallButton) {
233+
videoCallButton = undefined;
234+
}
235+
if (!showVoiceCallButton) {
236+
voiceCallButton = undefined;
237+
}
238+
236239
return (
237240
<>
238241
<Flex as="header" align="center" gap="var(--cpd-space-3x)" className="mx_RoomHeader light-panel">

src/hooks/room/useRoomCall.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import { Action } from "../../dispatcher/actions";
4141
import { CallStore, CallStoreEvent } from "../../stores/CallStore";
4242
import { isVideoRoom } from "../../utils/video-rooms";
4343
import { useGuestAccessInformation } from "./useGuestAccessInformation";
44+
import SettingsStore from "../../settings/SettingsStore";
45+
import { UIFeature } from "../../settings/UIFeature";
4446

4547
export enum PlatformCallType {
4648
ElementCall,
@@ -83,6 +85,7 @@ export const useRoomCall = (
8385
isConnectedToCall: boolean;
8486
hasActiveCallSession: boolean;
8587
callOptions: PlatformCallType[];
88+
showVideoCallButton: boolean;
8689
showVoiceCallButton: boolean;
8790
} => {
8891
// settings
@@ -268,8 +271,14 @@ export const useRoomCall = (
268271
}, [isViewingCall, room.roomId]);
269272

270273
// We hide the voice call button if it'd have the same effect as the video call button
271-
const hideVoiceCallButton =
274+
let hideVoiceCallButton =
272275
isManagedHybridWidgetEnabled(room.roomId) || !callOptions.includes(PlatformCallType.LegacyCall);
276+
let hideVideoCallButton = false;
277+
// We hide both buttons if they require widgets but widgets are disabled.
278+
if (memberCount > 2 && !SettingsStore.getValue(UIFeature.Widgets)) {
279+
hideVoiceCallButton = true;
280+
hideVideoCallButton = true;
281+
}
273282

274283
/**
275284
* We've gone through all the steps
@@ -285,5 +294,6 @@ export const useRoomCall = (
285294
hasActiveCallSession: hasActiveCallSession,
286295
callOptions,
287296
showVoiceCallButton: !hideVoiceCallButton,
297+
showVideoCallButton: !hideVideoCallButton,
288298
};
289299
};

test/components/views/rooms/RoomHeader-test.tsx

+45-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { _t } from "../../../../src/languageHandler";
6161
import * as UseCall from "../../../../src/hooks/useCall";
6262
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
6363
import WidgetStore, { IApp } from "../../../../src/stores/WidgetStore";
64+
import { UIFeature } from "../../../../src/settings/UIFeature";
6465

6566
jest.mock("../../../../src/utils/ShieldUtils");
6667

@@ -255,7 +256,47 @@ describe("RoomHeader", () => {
255256
expect(queryByLabelText(container, "Voice call")).not.toBeInTheDocument();
256257
});
257258

259+
describe("UIFeature.Widgets enabled (default)", () => {
260+
beforeEach(() => {
261+
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature == UIFeature.Widgets);
262+
});
263+
264+
it("should show call buttons in a room with 2 members", () => {
265+
mockRoomMembers(room, 2);
266+
const { container } = render(<RoomHeader room={room} />, getWrapper());
267+
expect(getByLabelText(container, "Video call")).toBeInTheDocument();
268+
});
269+
270+
it("should show call buttons in a room with more than 2 members", () => {
271+
mockRoomMembers(room, 3);
272+
const { container } = render(<RoomHeader room={room} />, getWrapper());
273+
expect(getByLabelText(container, "Video call")).toBeInTheDocument();
274+
});
275+
});
276+
277+
describe("UIFeature.Widgets disabled", () => {
278+
beforeEach(() => {
279+
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => false);
280+
});
281+
282+
it("should show call buttons in a room with 2 members", () => {
283+
mockRoomMembers(room, 2);
284+
const { container } = render(<RoomHeader room={room} />, getWrapper());
285+
expect(getByLabelText(container, "Video call")).toBeInTheDocument();
286+
});
287+
288+
it("should not show call buttons in a room with more than 2 members", () => {
289+
mockRoomMembers(room, 3);
290+
const { container } = render(<RoomHeader room={room} />, getWrapper());
291+
expect(queryByLabelText(container, "Video call")).not.toBeInTheDocument();
292+
});
293+
});
294+
258295
describe("groups call disabled", () => {
296+
beforeEach(() => {
297+
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature == UIFeature.Widgets);
298+
});
299+
259300
it("you can't call if you're alone", () => {
260301
mockRoomMembers(room, 1);
261302
const { container } = render(<RoomHeader room={room} />, getWrapper());
@@ -313,7 +354,9 @@ describe("RoomHeader", () => {
313354

314355
describe("group call enabled", () => {
315356
beforeEach(() => {
316-
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature === "feature_group_calls");
357+
jest.spyOn(SettingsStore, "getValue").mockImplementation(
358+
(feature) => feature === "feature_group_calls" || feature == UIFeature.Widgets,
359+
);
317360
});
318361

319362
it("renders only the video call element", async () => {
@@ -353,7 +396,7 @@ describe("RoomHeader", () => {
353396

354397
it("clicking on ongoing (unpinned) call re-pins it", () => {
355398
mockRoomMembers(room, 3);
356-
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
399+
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature == UIFeature.Widgets);
357400
// allow calls
358401
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockReturnValue(true);
359402
jest.spyOn(WidgetLayoutStore.instance, "isInContainer").mockReturnValue(false);

0 commit comments

Comments
 (0)