Merge branch 'develop' of https://github.com/nordeck/matrix-react-sdk into feature_confetti#14676
Conflicts: src/SlashCommands.tsx src/i18n/strings/de_DE.json
This commit is contained in:
@@ -158,6 +158,18 @@ export const SETTINGS: {[setting: string]: ISetting} = {
|
||||
supportedLevels: LEVELS_FEATURE,
|
||||
default: false,
|
||||
},
|
||||
"feature_roomlist_preview_reactions_dms": {
|
||||
isFeature: true,
|
||||
displayName: _td("Show message previews for reactions in DMs"),
|
||||
supportedLevels: LEVELS_FEATURE,
|
||||
default: false,
|
||||
},
|
||||
"feature_roomlist_preview_reactions_all": {
|
||||
isFeature: true,
|
||||
displayName: _td("Show message previews for reactions in all rooms"),
|
||||
supportedLevels: LEVELS_FEATURE,
|
||||
default: false,
|
||||
},
|
||||
"advancedRoomListLogging": {
|
||||
// TODO: Remove flag before launch: https://github.com/vector-im/element-web/issues/14231
|
||||
displayName: _td("Enable advanced debugging for the room list"),
|
||||
|
||||
@@ -23,7 +23,6 @@ import AccountSettingsHandler from "./handlers/AccountSettingsHandler";
|
||||
import RoomSettingsHandler from "./handlers/RoomSettingsHandler";
|
||||
import ConfigSettingsHandler from "./handlers/ConfigSettingsHandler";
|
||||
import { _t } from '../languageHandler';
|
||||
import SdkConfig from "../SdkConfig";
|
||||
import dis from '../dispatcher/dispatcher';
|
||||
import { ISetting, SETTINGS } from "./Settings";
|
||||
import LocalEchoWrapper from "./handlers/LocalEchoWrapper";
|
||||
@@ -53,7 +52,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),
|
||||
};
|
||||
|
||||
@@ -124,6 +123,14 @@ export default class SettingsStore {
|
||||
// Counter used for generation of watcher IDs
|
||||
private static watcherCount = 1;
|
||||
|
||||
/**
|
||||
* Gets all the feature-style setting names.
|
||||
* @returns {string[]} The names of the feature settings.
|
||||
*/
|
||||
public static getFeatureSettingNames(): string[] {
|
||||
return Object.keys(SETTINGS).filter(n => SettingsStore.isFeature(n));
|
||||
}
|
||||
|
||||
/**
|
||||
* Watches for changes in a particular setting. This is done without any local echo
|
||||
* wrapping and fires whenever a change is detected in a setting's value, at any level.
|
||||
@@ -240,19 +247,6 @@ export default class SettingsStore {
|
||||
return _t(displayName as string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all available labs feature names
|
||||
* @returns {string[]} The list of available feature names
|
||||
*/
|
||||
public static getLabsFeatures(): string[] {
|
||||
const possibleFeatures = Object.keys(SETTINGS).filter((s) => SettingsStore.isFeature(s));
|
||||
|
||||
const enableLabs = SdkConfig.get()["enableLabs"];
|
||||
if (enableLabs) return possibleFeatures;
|
||||
|
||||
return possibleFeatures.filter((s) => SettingsStore.getFeatureState(s) === "labs");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a setting is also a feature.
|
||||
* @param {string} settingName The setting to look up.
|
||||
@@ -263,39 +257,6 @@ export default class SettingsStore {
|
||||
return SETTINGS[settingName].isFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given feature is enabled. The feature given must be a known
|
||||
* feature.
|
||||
* @param {string} settingName The name of the setting that is a feature.
|
||||
* @param {String} roomId The optional room ID to validate in, may be null.
|
||||
* @return {boolean} True if the feature is enabled, false otherwise
|
||||
*/
|
||||
public static isFeatureEnabled(settingName: string, roomId: string = null) {
|
||||
if (!SettingsStore.isFeature(settingName)) {
|
||||
throw new Error("Setting " + settingName + " is not a feature");
|
||||
}
|
||||
|
||||
return SettingsStore.getValue(settingName, roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a feature as enabled or disabled on the current device.
|
||||
* @param {string} settingName The name of the setting.
|
||||
* @param {boolean} value True to enable the feature, false otherwise.
|
||||
* @returns {Promise} Resolves when the setting has been set.
|
||||
*/
|
||||
public static setFeatureEnabled(settingName: string, value: any): Promise<void> {
|
||||
// Verify that the setting is actually a setting
|
||||
if (!SETTINGS[settingName]) {
|
||||
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
|
||||
}
|
||||
if (!SettingsStore.isFeature(settingName)) {
|
||||
throw new Error("Setting " + settingName + " is not a feature");
|
||||
}
|
||||
|
||||
return SettingsStore.setValue(settingName, null, SettingLevel.DEVICE, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a setting. The room ID is optional if the setting is not to
|
||||
* be applied to any particular room, otherwise it should be supplied.
|
||||
@@ -346,13 +307,6 @@ export default class SettingsStore {
|
||||
const minIndex = levelOrder.indexOf(level);
|
||||
if (minIndex === -1) throw new Error("Level " + level + " is not prioritized");
|
||||
|
||||
if (SettingsStore.isFeature(settingName)) {
|
||||
const configValue = SettingsStore.getFeatureState(settingName);
|
||||
if (configValue === "enable") return true;
|
||||
if (configValue === "disable") return false;
|
||||
// else let it fall through the default process
|
||||
}
|
||||
|
||||
const handlers = SettingsStore.getHandlers(settingName);
|
||||
|
||||
// Check if we need to invert the setting at all. Do this after we get the setting
|
||||
@@ -480,6 +434,12 @@ export default class SettingsStore {
|
||||
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
|
||||
}
|
||||
|
||||
// When features are specified in the config.json, we force them as enabled or disabled.
|
||||
if (SettingsStore.isFeature(settingName)) {
|
||||
const configVal = SettingsStore.getValueAt(SettingLevel.CONFIG, settingName, roomId, true, true);
|
||||
if (configVal === true || configVal === false) return false;
|
||||
}
|
||||
|
||||
const handler = SettingsStore.getHandler(settingName, level);
|
||||
if (!handler) return false;
|
||||
return handler.canSetValue(settingName, roomId);
|
||||
@@ -611,24 +571,6 @@ export default class SettingsStore {
|
||||
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private static getFeatureState(settingName: string): LabsFeatureState {
|
||||
const featuresConfig = SdkConfig.get()['features'];
|
||||
const enableLabs = SdkConfig.get()['enableLabs']; // we'll honour the old flag
|
||||
|
||||
let featureState = enableLabs ? "labs" : "disable";
|
||||
if (featuresConfig && featuresConfig[settingName] !== undefined) {
|
||||
featureState = featuresConfig[settingName];
|
||||
}
|
||||
|
||||
const allowedStates = ['enable', 'disable', 'labs'];
|
||||
if (!allowedStates.includes(featureState)) {
|
||||
console.warn("Feature state '" + featureState + "' is invalid for " + settingName);
|
||||
featureState = "disable"; // to prevent accidental features.
|
||||
}
|
||||
|
||||
return featureState;
|
||||
}
|
||||
}
|
||||
|
||||
// For debugging purposes
|
||||
|
||||
@@ -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"];
|
||||
|
||||
Reference in New Issue
Block a user