mirror of
https://github.com/vector-im/element-web.git
synced 2025-12-27 20:21:55 +01:00
* Update all non-major dependencies * Delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Prettier Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import SettingController from "./SettingController";
|
|
import { type SettingLevel } from "../SettingLevel";
|
|
import SettingsStore from "../SettingsStore";
|
|
import { type BooleanSettingKey } from "../Settings.tsx";
|
|
|
|
/**
|
|
* Enforces that a boolean setting cannot be enabled if the incompatible setting
|
|
* is also enabled, to prevent cascading undefined behaviour between conflicting
|
|
* labs flags.
|
|
*/
|
|
export default class IncompatibleController extends SettingController {
|
|
public constructor(
|
|
private settingName: BooleanSettingKey,
|
|
private forcedValue: any = false,
|
|
private incompatibleValue: any | ((v: any) => boolean) = true,
|
|
) {
|
|
super();
|
|
}
|
|
|
|
public getValueOverride(
|
|
level: SettingLevel,
|
|
roomId: string,
|
|
calculatedValue: any,
|
|
calculatedAtLevel: SettingLevel | null,
|
|
): any {
|
|
if (this.incompatibleSetting) {
|
|
return this.forcedValue;
|
|
}
|
|
return null; // no override
|
|
}
|
|
|
|
public get settingDisabled(): boolean {
|
|
return this.incompatibleSetting;
|
|
}
|
|
|
|
public get incompatibleSetting(): boolean {
|
|
if (typeof this.incompatibleValue === "function") {
|
|
return this.incompatibleValue(SettingsStore.getValue(this.settingName));
|
|
}
|
|
return SettingsStore.getValue(this.settingName) === this.incompatibleValue;
|
|
}
|
|
}
|