Skip to content

Commit 2e68479

Browse files
authored
Add config to skip widget_build_url for DM rooms (matrix-org#11044)
* Add config to skip widget_build_url for DM rooms * Add tests
1 parent d340fa8 commit 2e68479

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

src/IConfigOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export interface IConfigOptions {
106106
};
107107

108108
widget_build_url?: string; // url called to replace jitsi/call widget creation
109+
widget_build_url_ignore_dm?: boolean;
109110
audio_stream_url?: string;
110111
jitsi?: {
111112
preferred_domain: string;

src/LegacyCallHandler.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ export default class LegacyCallHandler extends EventEmitter {
963963
}
964964

965965
// We might be using managed hybrid widgets
966-
if (isManagedHybridWidgetEnabled()) {
966+
if (isManagedHybridWidgetEnabled(roomId)) {
967967
await addManagedHybridWidget(roomId);
968968
return;
969969
}

src/utils/WellKnownUtils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const EMBEDDED_PAGES_WK_PROPERTY = "io.element.embedded_pages";
2626
/* eslint-disable camelcase */
2727
export interface ICallBehaviourWellKnown {
2828
widget_build_url?: string;
29+
ignore_dm?: boolean;
2930
}
3031

3132
export interface IE2EEWellKnown {

src/widgets/ManagedHybrid.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IStoredLayout, WidgetLayoutStore } from "../stores/widgets/WidgetLayout
2424
import WidgetEchoStore from "../stores/WidgetEchoStore";
2525
import WidgetStore from "../stores/WidgetStore";
2626
import SdkConfig from "../SdkConfig";
27+
import DMRoomMap from "../utils/DMRoomMap";
2728

2829
/* eslint-disable camelcase */
2930
interface IManagedHybridWidgetData {
@@ -33,16 +34,25 @@ interface IManagedHybridWidgetData {
3334
}
3435
/* eslint-enable camelcase */
3536

36-
function getWidgetBuildUrl(): string | undefined {
37+
function getWidgetBuildUrl(roomId: string): string | undefined {
38+
const isDm = !!DMRoomMap.shared().getUserIdForRoomId(roomId);
3739
if (SdkConfig.get().widget_build_url) {
40+
if (isDm && SdkConfig.get().widget_build_url_ignore_dm) {
41+
return undefined;
42+
}
3843
return SdkConfig.get().widget_build_url;
3944
}
45+
46+
const wellKnown = getCallBehaviourWellKnown(MatrixClientPeg.get());
47+
if (isDm && wellKnown?.ignore_dm) {
48+
return undefined;
49+
}
4050
/* eslint-disable-next-line camelcase */
41-
return getCallBehaviourWellKnown(MatrixClientPeg.get())?.widget_build_url;
51+
return wellKnown?.widget_build_url;
4252
}
4353

44-
export function isManagedHybridWidgetEnabled(): boolean {
45-
return !!getWidgetBuildUrl();
54+
export function isManagedHybridWidgetEnabled(roomId: string): boolean {
55+
return !!getWidgetBuildUrl(roomId);
4656
}
4757

4858
export async function addManagedHybridWidget(roomId: string): Promise<void> {
@@ -60,7 +70,7 @@ export async function addManagedHybridWidget(roomId: string): Promise<void> {
6070

6171
// Get widget data
6272
/* eslint-disable-next-line camelcase */
63-
const widgetBuildUrl = getWidgetBuildUrl();
73+
const widgetBuildUrl = getWidgetBuildUrl(roomId);
6474
if (!widgetBuildUrl) {
6575
return;
6676
}

test/widgets/ManagedHybrid-test.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { isManagedHybridWidgetEnabled } from "../../src/widgets/ManagedHybrid";
18+
import DMRoomMap from "../../src/utils/DMRoomMap";
19+
import { stubClient } from "../test-utils";
20+
import SdkConfig from "../../src/SdkConfig";
21+
22+
describe("isManagedHybridWidgetEnabled", () => {
23+
let dmRoomMap: DMRoomMap;
24+
25+
beforeEach(() => {
26+
stubClient();
27+
dmRoomMap = {
28+
getUserIdForRoomId: jest.fn().mockReturnValue("@user:server"),
29+
} as unknown as DMRoomMap;
30+
DMRoomMap.setShared(dmRoomMap);
31+
});
32+
33+
it("should return false if widget_build_url is unset", () => {
34+
expect(isManagedHybridWidgetEnabled("!room:server")).toBeFalsy();
35+
});
36+
37+
it("should return true for DMs when widget_build_url_ignore_dm is unset", () => {
38+
SdkConfig.put({
39+
widget_build_url: "https://url",
40+
});
41+
expect(isManagedHybridWidgetEnabled("!room:server")).toBeTruthy();
42+
});
43+
44+
it("should return false for DMs when widget_build_url_ignore_dm is true", () => {
45+
SdkConfig.put({
46+
widget_build_url: "https://url",
47+
widget_build_url_ignore_dm: true,
48+
});
49+
expect(isManagedHybridWidgetEnabled("!room:server")).toBeFalsy();
50+
});
51+
});

0 commit comments

Comments
 (0)