Handle missing Element Call brand (#9376)

This commit is contained in:
Šimon Brandner 2022-10-07 21:55:48 +02:00 committed by GitHub
parent 26a74a193f
commit 5680d13acf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 14 deletions

View file

@ -117,9 +117,9 @@ export interface IConfigOptions {
obey_asserted_identity?: boolean; // MSC3086 obey_asserted_identity?: boolean; // MSC3086
}; };
element_call: { element_call: {
url: string; url?: string;
use_exclusively: boolean; use_exclusively?: boolean;
brand: string; brand?: string;
}; };
logout_redirect_url?: string; logout_redirect_url?: string;

View file

@ -52,7 +52,7 @@ import { UPDATE_EVENT } from "../../../stores/AsyncStore";
import { isVideoRoom as calcIsVideoRoom } from "../../../utils/video-rooms"; import { isVideoRoom as calcIsVideoRoom } from "../../../utils/video-rooms";
import LegacyCallHandler, { LegacyCallHandlerEvent } from "../../../LegacyCallHandler"; import LegacyCallHandler, { LegacyCallHandlerEvent } from "../../../LegacyCallHandler";
import { useFeatureEnabled, useSettingValue } from "../../../hooks/useSettings"; import { useFeatureEnabled, useSettingValue } from "../../../hooks/useSettings";
import SdkConfig from "../../../SdkConfig"; import SdkConfig, { DEFAULTS } from "../../../SdkConfig";
import { useEventEmitterState, useTypedEventEmitterState } from "../../../hooks/useEventEmitter"; import { useEventEmitterState, useTypedEventEmitterState } from "../../../hooks/useEventEmitter";
import { useWidgets } from "../right_panel/RoomSummaryCard"; import { useWidgets } from "../right_panel/RoomSummaryCard";
import { WidgetType } from "../../../widgets/WidgetType"; import { WidgetType } from "../../../widgets/WidgetType";
@ -195,7 +195,7 @@ const VideoCallButton: FC<VideoCallButtonProps> = ({ room, busy, setBusy, behavi
let menu: JSX.Element | null = null; let menu: JSX.Element | null = null;
if (menuOpen) { if (menuOpen) {
const buttonRect = buttonRef.current!.getBoundingClientRect(); const buttonRect = buttonRef.current!.getBoundingClientRect();
const brand = SdkConfig.get("element_call").brand; const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
menu = <IconizedContextMenu {...aboveLeftOf(buttonRect)} onFinished={closeMenu}> menu = <IconizedContextMenu {...aboveLeftOf(buttonRect)} onFinished={closeMenu}>
<IconizedContextMenuOptionList> <IconizedContextMenuOptionList>
<IconizedContextMenuOption label={_t("Video call (Jitsi)")} onClick={onJitsiClick} /> <IconizedContextMenuOption label={_t("Video call (Jitsi)")} onClick={onJitsiClick} />
@ -230,7 +230,9 @@ const CallButtons: FC<CallButtonsProps> = ({ room }) => {
const groupCallsEnabled = useFeatureEnabled("feature_group_calls"); const groupCallsEnabled = useFeatureEnabled("feature_group_calls");
const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms"); const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms");
const isVideoRoom = useMemo(() => videoRoomsEnabled && calcIsVideoRoom(room), [videoRoomsEnabled, room]); 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( const hasLegacyCall = useEventEmitterState(
LegacyCallHandler.instance, LegacyCallHandler.instance,

View file

@ -32,7 +32,7 @@ import SettingsFieldset from '../../SettingsFieldset';
import SettingsStore from "../../../../../settings/SettingsStore"; import SettingsStore from "../../../../../settings/SettingsStore";
import { VoiceBroadcastInfoEventType } from '../../../../../voice-broadcast'; import { VoiceBroadcastInfoEventType } from '../../../../../voice-broadcast';
import { ElementCall } from "../../../../../models/Call"; import { ElementCall } from "../../../../../models/Call";
import SdkConfig from "../../../../../SdkConfig"; import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";
interface IEventShowOpts { interface IEventShowOpts {
isState?: boolean; isState?: boolean;
@ -446,7 +446,7 @@ export default class RolesRoomSettingsTab extends React.Component<IProps> {
let label = plEventsToLabels[eventType]; let label = plEventsToLabels[eventType];
if (label) { if (label) {
const brand = SdkConfig.get("element_call").brand; const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
label = _t(label, { brand }); label = _t(label, { brand });
} else { } else {
label = _t("Send %(eventType)s events", { eventType }); label = _t("Send %(eventType)s events", { eventType });

View file

@ -25,7 +25,7 @@ import SettingsSubsection from "../../shared/SettingsSubsection";
import SettingsTab from "../SettingsTab"; import SettingsTab from "../SettingsTab";
import { ElementCall } from "../../../../../models/Call"; import { ElementCall } from "../../../../../models/Call";
import { useRoomState } from "../../../../../hooks/useRoomState"; import { useRoomState } from "../../../../../hooks/useRoomState";
import SdkConfig from "../../../../../SdkConfig"; import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";
interface ElementCallSwitchProps { interface ElementCallSwitchProps {
roomId: string; roomId: string;
@ -69,7 +69,7 @@ const ElementCallSwitch: React.FC<ElementCallSwitchProps> = ({ roomId }) => {
}); });
}, [roomId, content, events, isPublic]); }, [roomId, content, events, isPublic]);
const brand = SdkConfig.get("element_call").brand; const brand = SdkConfig.get("element_call").brand ?? DEFAULTS.element_call.brand;
return <LabelledToggleSwitch return <LabelledToggleSwitch
data-testid="element-call-switch" data-testid="element-call-switch"

View file

@ -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 { RoomMember } from "matrix-js-sdk/src/models/room-member";
import type { ClientWidgetApi } from "matrix-widget-api"; import type { ClientWidgetApi } from "matrix-widget-api";
import type { IApp } from "../stores/WidgetStore"; import type { IApp } from "../stores/WidgetStore";
import SdkConfig from "../SdkConfig"; import SdkConfig, { DEFAULTS } from "../SdkConfig";
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../MediaDeviceHandler"; import MediaDeviceHandler, { MediaDeviceKindEnum } from "../MediaDeviceHandler";
import { timeout } from "../utils/promise"; import { timeout } from "../utils/promise";
@ -622,7 +622,7 @@ export class ElementCall extends Call {
private constructor(public readonly groupCall: MatrixEvent, client: MatrixClient) { private constructor(public readonly groupCall: MatrixEvent, client: MatrixClient) {
// Splice together the Element Call URL for this call // 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"; url.pathname = "/room";
const params = new URLSearchParams({ const params = new URLSearchParams({
embed: "", embed: "",

View file

@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
import { Direction } from "matrix-js-sdk/src/matrix"; import { Direction } from "matrix-js-sdk/src/matrix";
import SdkConfig from "../../SdkConfig"; import SdkConfig, { DEFAULTS } from "../../SdkConfig";
import { iterableDiff, iterableIntersection } from "../../utils/iterables"; import { iterableDiff, iterableIntersection } from "../../utils/iterables";
import { MatrixClientPeg } from "../../MatrixClientPeg"; import { MatrixClientPeg } from "../../MatrixClientPeg";
import Modal from "../../Modal"; 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. // 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. // Widgets don't technically need to request this capability, but Scalar still does.
this.allowedCapabilities.add("visibility"); 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 is a trusted Element Call widget that we control
this.allowedCapabilities.add(MatrixCapabilities.AlwaysOnScreen); this.allowedCapabilities.add(MatrixCapabilities.AlwaysOnScreen);
this.allowedCapabilities.add(MatrixCapabilities.MSC3846TurnServers); this.allowedCapabilities.add(MatrixCapabilities.MSC3846TurnServers);