Cleanup tasks in the Settings code (#12125)

* inline call to `SettingsStore.isEnabled`

* Remove confusing `SettingsStore.isEnabled`

This was basically the same as `SettingsStore.canSetValue` only more confusing,
so let's get rid of it.

* Add `configDisablesSetting` value for Settings

The current magic where this only works for features (but not beta features!)
is, well, magical. And I need more flexibility here.

* Remove redundant levels constant `LEVELS_FEATURE`

I don't know if this was ever intended to have different semantics to
`LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG`, but if it was, those semantics
shuold have been written down. They now seem to be used entirely
interchangably.
This commit is contained in:
Richard van der Hoff 2024-01-11 09:49:00 +00:00 committed by GitHub
parent c2b5c1fe96
commit 65d6bfe6e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 60 deletions

View file

@ -320,19 +320,6 @@ export default class SettingsStore {
}
}
/**
* Determines if a setting is enabled.
* If a setting is disabled then it should normally be hidden from the user to de-clutter the user interface.
* This rule is intentionally ignored for labs flags to unveil what features are available with
* the right server support.
* @param {string} settingName The setting to look up.
* @return {boolean} True if the setting is enabled.
*/
public static isEnabled(settingName: string): boolean {
if (!SETTINGS[settingName]) return false;
return !SETTINGS[settingName].controller?.settingDisabled ?? true;
}
/**
* Retrieves the reason a setting is disabled if one is assigned.
* If a setting is not disabled, or no reason is given by the `SettingController`,
@ -516,6 +503,15 @@ export default class SettingsStore {
* Determines if the current user is permitted to set the given setting at the given
* level for a particular room. The room ID is optional if the setting is not being
* set for a particular room, otherwise it should be supplied.
*
* This takes into account both the value of {@link SettingController#settingDisabled} of the
* `SettingController`, if any; and, for settings where {@link IBaseSetting#configDisablesSetting} is true,
* whether the setting has been given a value in `config.json`.
*
* Typically, if the user cannot set the setting, it should be hidden, to declutter the UI;
* however some settings (typically, the labs flags) are exposed but greyed out, to unveil
* what features are available with the right server support.
*
* @param {string} settingName The name of the setting to check.
* @param {String} roomId The room ID to check in, may be null.
* @param {SettingLevel} level The level to
@ -528,12 +524,12 @@ export default class SettingsStore {
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
}
if (!SettingsStore.isEnabled(settingName)) {
if (SETTINGS[settingName].controller?.settingDisabled) {
return false;
}
// When non-beta features are specified in the config.json, we force them as enabled or disabled.
if (SettingsStore.isFeature(settingName) && !SETTINGS[settingName]?.betaInfo) {
if (SETTINGS[settingName]?.configDisablesSetting) {
const configVal = SettingsStore.getValueAt(SettingLevel.CONFIG, settingName, roomId, true, true);
if (configVal === true || configVal === false) return false;
}