From 46eabd39c92121083df434ac054d2e9a105eb944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 7 Oct 2022 20:31:00 +0200 Subject: [PATCH 1/2] Handle missing `brand` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/rooms/RoomHeader.tsx | 4 ++-- .../views/settings/tabs/room/RolesRoomSettingsTab.tsx | 4 ++-- .../views/settings/tabs/room/VoipRoomSettingsTab.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/views/rooms/RoomHeader.tsx b/src/components/views/rooms/RoomHeader.tsx index 6f0eac864f5..e0361a33cdb 100644 --- a/src/components/views/rooms/RoomHeader.tsx +++ b/src/components/views/rooms/RoomHeader.tsx @@ -52,7 +52,7 @@ import { UPDATE_EVENT } from "../../../stores/AsyncStore"; import { isVideoRoom as calcIsVideoRoom } from "../../../utils/video-rooms"; import LegacyCallHandler, { LegacyCallHandlerEvent } from "../../../LegacyCallHandler"; import { useFeatureEnabled, useSettingValue } from "../../../hooks/useSettings"; -import SdkConfig from "../../../SdkConfig"; +import SdkConfig, { DEFAULTS } from "../../../SdkConfig"; import { useEventEmitterState, useTypedEventEmitterState } from "../../../hooks/useEventEmitter"; import { useWidgets } from "../right_panel/RoomSummaryCard"; import { WidgetType } from "../../../widgets/WidgetType"; @@ -195,7 +195,7 @@ const VideoCallButton: FC = ({ room, busy, setBusy, behavi let menu: JSX.Element | null = null; if (menuOpen) { const buttonRect = buttonRef.current!.getBoundingClientRect(); - const brand = SdkConfig.get("element_call").brand; + const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand; menu = diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index 1c70c3ea39f..5da39961541 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -32,7 +32,7 @@ import SettingsFieldset from '../../SettingsFieldset'; import SettingsStore from "../../../../../settings/SettingsStore"; import { VoiceBroadcastInfoEventType } from '../../../../../voice-broadcast'; import { ElementCall } from "../../../../../models/Call"; -import SdkConfig from "../../../../../SdkConfig"; +import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig"; interface IEventShowOpts { isState?: boolean; @@ -446,7 +446,7 @@ export default class RolesRoomSettingsTab extends React.Component { let label = plEventsToLabels[eventType]; if (label) { - const brand = SdkConfig.get("element_call").brand; + const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand; label = _t(label, { brand }); } else { label = _t("Send %(eventType)s events", { eventType }); diff --git a/src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx index 29863b64aab..b8dca6205c7 100644 --- a/src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx @@ -25,7 +25,7 @@ import SettingsSubsection from "../../shared/SettingsSubsection"; import SettingsTab from "../SettingsTab"; import { ElementCall } from "../../../../../models/Call"; import { useRoomState } from "../../../../../hooks/useRoomState"; -import SdkConfig from "../../../../../SdkConfig"; +import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig"; interface ElementCallSwitchProps { roomId: string; @@ -69,7 +69,7 @@ const ElementCallSwitch: React.FC = ({ roomId }) => { }); }, [roomId, content, events, isPublic]); - const brand = SdkConfig.get("element_call").brand; + const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand; return Date: Fri, 7 Oct 2022 21:17:31 +0200 Subject: [PATCH 2/2] Also correctly handle the other options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/IConfigOptions.ts | 6 +++--- src/components/views/rooms/RoomHeader.tsx | 4 +++- src/models/Call.ts | 4 ++-- src/stores/widgets/StopGapWidgetDriver.ts | 7 +++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts index 9739cc88702..d8c26909dfc 100644 --- a/src/IConfigOptions.ts +++ b/src/IConfigOptions.ts @@ -117,9 +117,9 @@ export interface IConfigOptions { obey_asserted_identity?: boolean; // MSC3086 }; element_call: { - url: string; - use_exclusively: boolean; - brand: string; + url?: string; + use_exclusively?: boolean; + brand?: string; }; logout_redirect_url?: string; diff --git a/src/components/views/rooms/RoomHeader.tsx b/src/components/views/rooms/RoomHeader.tsx index e0361a33cdb..013a992698f 100644 --- a/src/components/views/rooms/RoomHeader.tsx +++ b/src/components/views/rooms/RoomHeader.tsx @@ -230,7 +230,9 @@ const CallButtons: FC = ({ room }) => { const groupCallsEnabled = useFeatureEnabled("feature_group_calls"); const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms"); const isVideoRoom = useMemo(() => videoRoomsEnabled && calcIsVideoRoom(room), [videoRoomsEnabled, room]); - const useElementCallExclusively = useMemo(() => SdkConfig.get("element_call").use_exclusively, []); + const useElementCallExclusively = useMemo(() => { + return SdkConfig.get("element_call").use_exclusively ?? DEFAULTS.element_call.use_exclusively; + }, []); const hasLegacyCall = useEventEmitterState( LegacyCallHandler.instance, diff --git a/src/models/Call.ts b/src/models/Call.ts index c12c4fdfc9b..455b08e6a57 100644 --- a/src/models/Call.ts +++ b/src/models/Call.ts @@ -31,7 +31,7 @@ import type { Room } from "matrix-js-sdk/src/models/room"; import type { RoomMember } from "matrix-js-sdk/src/models/room-member"; import type { ClientWidgetApi } from "matrix-widget-api"; import type { IApp } from "../stores/WidgetStore"; -import SdkConfig from "../SdkConfig"; +import SdkConfig, { DEFAULTS } from "../SdkConfig"; import SettingsStore from "../settings/SettingsStore"; import MediaDeviceHandler, { MediaDeviceKindEnum } from "../MediaDeviceHandler"; import { timeout } from "../utils/promise"; @@ -622,7 +622,7 @@ export class ElementCall extends Call { private constructor(public readonly groupCall: MatrixEvent, client: MatrixClient) { // Splice together the Element Call URL for this call - const url = new URL(SdkConfig.get("element_call").url); + const url = new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url); url.pathname = "/room"; const params = new URLSearchParams({ embed: "", diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 9de442a4b9d..dd806dd6dd9 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger"; import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { Direction } from "matrix-js-sdk/src/matrix"; -import SdkConfig from "../../SdkConfig"; +import SdkConfig, { DEFAULTS } from "../../SdkConfig"; import { iterableDiff, iterableIntersection } from "../../utils/iterables"; import { MatrixClientPeg } from "../../MatrixClientPeg"; import Modal from "../../Modal"; @@ -104,7 +104,10 @@ export class StopGapWidgetDriver extends WidgetDriver { // Auto-approve the legacy visibility capability. We send it regardless of capability. // Widgets don't technically need to request this capability, but Scalar still does. this.allowedCapabilities.add("visibility"); - } else if (virtual && new URL(SdkConfig.get("element_call").url).origin === this.forWidget.origin) { + } else if ( + virtual + && new URL(SdkConfig.get("element_call").url ?? DEFAULTS.element_call.url).origin === this.forWidget.origin + ) { // This is a trusted Element Call widget that we control this.allowedCapabilities.add(MatrixCapabilities.AlwaysOnScreen); this.allowedCapabilities.add(MatrixCapabilities.MSC3846TurnServers);