Implement new config style for features
parent
eda4e24926
commit
71643862c0
|
@ -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),
|
||||
};
|
||||
|
||||
|
|
|
@ -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"];
|
||||
|
|
Loading…
Reference in New Issue