Implement new config style for features

This commit is contained in:
Travis Ralston 2020-08-17 13:24:55 -06:00
parent eda4e24926
commit 71643862c0
2 changed files with 16 additions and 1 deletions

View file

@ -53,7 +53,7 @@ const LEVEL_HANDLERS = {
[SettingLevel.ROOM_ACCOUNT]: new RoomAccountSettingsHandler(defaultWatchManager),
[SettingLevel.ACCOUNT]: new AccountSettingsHandler(defaultWatchManager),
[SettingLevel.ROOM]: new RoomSettingsHandler(defaultWatchManager),
[SettingLevel.CONFIG]: new ConfigSettingsHandler(),
[SettingLevel.CONFIG]: new ConfigSettingsHandler(featureNames),
[SettingLevel.DEFAULT]: new DefaultSettingsHandler(defaultSettings, invertedDefaultSettings),
};

View file

@ -24,9 +24,24 @@ import {isNullOrUndefined} from "matrix-js-sdk/src/utils";
* roomId parameter.
*/
export default class ConfigSettingsHandler extends SettingsHandler {
public constructor(private featureNames: string[]) {
super();
}
public getValue(settingName: string, roomId: string): any {
const config = SdkConfig.get() || {};
if (this.featureNames.includes(settingName)) {
const labsConfig = config["features"] || {};
const val = labsConfig[settingName];
if (isNullOrUndefined(val)) return null; // no definition at this level
if (val === true || val === false) return val; // new style: mapped as a boolean
if (val === "enable") return true; // backwards compat
if (val === "disable") return false; // backwards compat
if (val === "labs") return null; // backwards compat, no override
return null; // fallback in the case of invalid input
}
// Special case themes
if (settingName === "theme") {
return config["default_theme"];