Add config to skip widget_build_url for DM rooms (#11044)

* Add config to skip widget_build_url for DM rooms

* Add tests
This commit is contained in:
Michael Telatynski 2023-06-06 15:07:51 +01:00 committed by GitHub
parent d340fa8d2a
commit 2e68479577
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 6 deletions

View file

@ -24,6 +24,7 @@ import { IStoredLayout, WidgetLayoutStore } from "../stores/widgets/WidgetLayout
import WidgetEchoStore from "../stores/WidgetEchoStore";
import WidgetStore from "../stores/WidgetStore";
import SdkConfig from "../SdkConfig";
import DMRoomMap from "../utils/DMRoomMap";
/* eslint-disable camelcase */
interface IManagedHybridWidgetData {
@ -33,16 +34,25 @@ interface IManagedHybridWidgetData {
}
/* eslint-enable camelcase */
function getWidgetBuildUrl(): string | undefined {
function getWidgetBuildUrl(roomId: string): string | undefined {
const isDm = !!DMRoomMap.shared().getUserIdForRoomId(roomId);
if (SdkConfig.get().widget_build_url) {
if (isDm && SdkConfig.get().widget_build_url_ignore_dm) {
return undefined;
}
return SdkConfig.get().widget_build_url;
}
const wellKnown = getCallBehaviourWellKnown(MatrixClientPeg.get());
if (isDm && wellKnown?.ignore_dm) {
return undefined;
}
/* eslint-disable-next-line camelcase */
return getCallBehaviourWellKnown(MatrixClientPeg.get())?.widget_build_url;
return wellKnown?.widget_build_url;
}
export function isManagedHybridWidgetEnabled(): boolean {
return !!getWidgetBuildUrl();
export function isManagedHybridWidgetEnabled(roomId: string): boolean {
return !!getWidgetBuildUrl(roomId);
}
export async function addManagedHybridWidget(roomId: string): Promise<void> {
@ -60,7 +70,7 @@ export async function addManagedHybridWidget(roomId: string): Promise<void> {
// Get widget data
/* eslint-disable-next-line camelcase */
const widgetBuildUrl = getWidgetBuildUrl();
const widgetBuildUrl = getWidgetBuildUrl(roomId);
if (!widgetBuildUrl) {
return;
}