diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index ca5e2f1d04..ea58201322 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -38,6 +38,7 @@ import { UIFeature } from "./UIFeature"; import { OrderedMultiController } from "./controllers/OrderedMultiController"; import {Layout} from "./Layout"; import ReducedMotionController from './controllers/ReducedMotionController'; +import IncompatibleController from "./controllers/IncompatibleController"; // These are just a bunch of helper arrays to avoid copy/pasting a bunch of times const LEVELS_ROOM_SETTINGS = [ @@ -188,6 +189,8 @@ export const SETTINGS: {[setting: string]: ISetting} = { displayName: _td("Show message previews for reactions in DMs"), supportedLevels: LEVELS_FEATURE, default: false, + // this option is a subset of `feature_roomlist_preview_reactions_all` so disable it when that one is enabled + controller: new IncompatibleController("feature_roomlist_preview_reactions_all"), }, "feature_roomlist_preview_reactions_all": { isFeature: true, diff --git a/src/settings/controllers/IncompatibleController.ts b/src/settings/controllers/IncompatibleController.ts new file mode 100644 index 0000000000..c48ce0a60b --- /dev/null +++ b/src/settings/controllers/IncompatibleController.ts @@ -0,0 +1,46 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import SettingController from "./SettingController"; +import { SettingLevel } from "../SettingLevel"; +import SettingsStore from "../SettingsStore"; + +/** + * 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: string, private forcedValue = false) { + super(); + } + + public getValueOverride( + level: SettingLevel, + roomId: string, + calculatedValue: any, + calculatedAtLevel: SettingLevel, + ): any { + if (this.incompatibleSettingEnabled) { + return this.forcedValue; + } + return null; // no override + } + + public get incompatibleSettingEnabled(): boolean { + return SettingsStore.getValue(this.settingName); + } +}