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

@ -40,8 +40,6 @@ interface IProps {
interface IState { interface IState {
value: boolean; value: boolean;
/** true if `SettingsStore.isEnabled` returned false. */
disabled: boolean;
} }
export default class SettingsFlag extends React.Component<IProps, IState> { export default class SettingsFlag extends React.Component<IProps, IState> {
@ -52,7 +50,6 @@ export default class SettingsFlag extends React.Component<IProps, IState> {
this.state = { this.state = {
value: this.getSettingValue(), value: this.getSettingValue(),
disabled: this.isSettingDisabled(),
}; };
} }
@ -72,15 +69,9 @@ export default class SettingsFlag extends React.Component<IProps, IState> {
this.props.isExplicit, this.props.isExplicit,
); );
} }
private isSettingDisabled(): boolean {
return !SettingsStore.isEnabled(this.props.name);
}
private onSettingChange = (): void => { private onSettingChange = (): void => {
this.setState({ this.setState({
value: this.getSettingValue(), value: this.getSettingValue(),
disabled: this.isSettingDisabled(),
}); });
}; };
@ -104,14 +95,13 @@ export default class SettingsFlag extends React.Component<IProps, IState> {
}; };
public render(): React.ReactNode { public render(): React.ReactNode {
const canChange = SettingsStore.canSetValue(this.props.name, this.props.roomId ?? null, this.props.level); const disabled = !SettingsStore.canSetValue(this.props.name, this.props.roomId ?? null, this.props.level);
if (!canChange && this.props.hideIfCannotSet) return null; if (disabled && this.props.hideIfCannotSet) return null;
const label = this.props.label ?? SettingsStore.getDisplayName(this.props.name, this.props.level); const label = this.props.label ?? SettingsStore.getDisplayName(this.props.name, this.props.level);
const description = SettingsStore.getDescription(this.props.name); const description = SettingsStore.getDescription(this.props.name);
const shouldWarn = SettingsStore.shouldHaveWarning(this.props.name); const shouldWarn = SettingsStore.shouldHaveWarning(this.props.name);
const disabled = this.state.disabled || !canChange;
if (this.props.useCheckbox) { if (this.props.useCheckbox) {
return ( return (

View file

@ -62,7 +62,7 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
} }
let noSendUnverifiedSetting: JSX.Element | undefined; let noSendUnverifiedSetting: JSX.Element | undefined;
if (SettingsStore.isEnabled("blacklistUnverifiedDevices")) { if (SettingsStore.canSetValue("blacklistUnverifiedDevices", null, SettingLevel.DEVICE)) {
noSendUnverifiedSetting = ( noSendUnverifiedSetting = (
<SettingsFlag <SettingsFlag
name="blacklistUnverifiedDevices" name="blacklistUnverifiedDevices"

View file

@ -38,5 +38,5 @@ const E2eAdvancedPanel: React.FC = () => {
export default E2eAdvancedPanel; export default E2eAdvancedPanel;
export function isE2eAdvancedPanelPossible(): boolean { export function isE2eAdvancedPanelPossible(): boolean {
return SettingsStore.isEnabled(SETTING_MANUALLY_VERIFY_ALL_SESSIONS); return SettingsStore.canSetValue(SETTING_MANUALLY_VERIFY_ALL_SESSIONS, null, SettingLevel.DEVICE);
} }

View file

@ -427,7 +427,10 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
const canEnableEncryption = !isEncrypted && !isEncryptionForceDisabled && hasEncryptionPermission; const canEnableEncryption = !isEncrypted && !isEncryptionForceDisabled && hasEncryptionPermission;
let encryptionSettings: JSX.Element | undefined; let encryptionSettings: JSX.Element | undefined;
if (isEncrypted && SettingsStore.isEnabled("blacklistUnverifiedDevices")) { if (
isEncrypted &&
SettingsStore.canSetValue("blacklistUnverifiedDevices", this.props.room.roomId, SettingLevel.ROOM_DEVICE)
) {
encryptionSettings = ( encryptionSettings = (
<SettingsFlag <SettingsFlag
name="blacklistUnverifiedDevices" name="blacklistUnverifiedDevices"

View file

@ -67,7 +67,6 @@ const LEVELS_ROOM_SETTINGS_WITH_ROOM = [
SettingLevel.ROOM, SettingLevel.ROOM,
]; ];
const LEVELS_ACCOUNT_SETTINGS = [SettingLevel.DEVICE, SettingLevel.ACCOUNT, SettingLevel.CONFIG]; const LEVELS_ACCOUNT_SETTINGS = [SettingLevel.DEVICE, SettingLevel.ACCOUNT, SettingLevel.CONFIG];
const LEVELS_FEATURE = [SettingLevel.DEVICE, SettingLevel.CONFIG];
const LEVELS_DEVICE_ONLY_SETTINGS = [SettingLevel.DEVICE]; const LEVELS_DEVICE_ONLY_SETTINGS = [SettingLevel.DEVICE];
const LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG = [SettingLevel.DEVICE, SettingLevel.CONFIG]; const LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG = [SettingLevel.DEVICE, SettingLevel.CONFIG];
const LEVELS_UI_FEATURE = [ const LEVELS_UI_FEATURE = [
@ -125,6 +124,17 @@ export type SettingValueType =
export interface IBaseSetting<T extends SettingValueType = SettingValueType> { export interface IBaseSetting<T extends SettingValueType = SettingValueType> {
isFeature?: false | undefined; isFeature?: false | undefined;
/**
* If true, then the presence of this setting in `config.json` will disable the option in the UI.
*
* In other words, we prevent the user overriding the setting if an explicit value is given in `config.json`;
* though note that users who have already set a non-default value before `config.json` is update will continue
* to use that value (and, indeed, won't be able to change it!)
*
* Obviously, this only really makes sense if `supportedLevels` includes {@link SettingLevel.CONFIG}.
*/
configDisablesSetting?: true;
// Display names are strongly recommended for clarity. // Display names are strongly recommended for clarity.
// Display name can also be an object for different levels. // Display name can also be an object for different levels.
displayName?: displayName?:
@ -192,7 +202,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
isFeature: true, isFeature: true,
labsGroup: LabGroup.VoiceAndVideo, labsGroup: LabGroup.VoiceAndVideo,
displayName: _td("labs|video_rooms"), displayName: _td("labs|video_rooms"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
// Reload to ensure that the left panel etc. get remounted // Reload to ensure that the left panel etc. get remounted
controller: new ReloadOnChangeController(), controller: new ReloadOnChangeController(),
@ -230,7 +240,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
[Features.NotificationSettings2]: { [Features.NotificationSettings2]: {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Experimental, labsGroup: LabGroup.Experimental,
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|notification_settings"), displayName: _td("labs|notification_settings"),
default: false, default: false,
betaInfo: { betaInfo: {
@ -249,62 +259,70 @@ export const SETTINGS: { [setting: string]: ISetting } = {
"feature_msc3531_hide_messages_pending_moderation": { "feature_msc3531_hide_messages_pending_moderation": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Moderation, labsGroup: LabGroup.Moderation,
configDisablesSetting: true,
// Requires a reload since this setting is cached in EventUtils // Requires a reload since this setting is cached in EventUtils
controller: new ReloadOnChangeController(), controller: new ReloadOnChangeController(),
displayName: _td("labs|msc3531_hide_messages_pending_moderation"), displayName: _td("labs|msc3531_hide_messages_pending_moderation"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_report_to_moderators": { "feature_report_to_moderators": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Moderation, labsGroup: LabGroup.Moderation,
configDisablesSetting: true,
displayName: _td("labs|report_to_moderators"), displayName: _td("labs|report_to_moderators"),
description: _td("labs|report_to_moderators_description"), description: _td("labs|report_to_moderators_description"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_latex_maths": { "feature_latex_maths": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
configDisablesSetting: true,
displayName: _td("labs|latex_maths"), displayName: _td("labs|latex_maths"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_pinning": { "feature_pinning": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
configDisablesSetting: true,
displayName: _td("labs|pinning"), displayName: _td("labs|pinning"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_wysiwyg_composer": { "feature_wysiwyg_composer": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
configDisablesSetting: true,
displayName: _td("labs|wysiwyg_composer"), displayName: _td("labs|wysiwyg_composer"),
description: _td("labs|feature_wysiwyg_composer_description"), description: _td("labs|feature_wysiwyg_composer_description"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_mjolnir": { "feature_mjolnir": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Moderation, labsGroup: LabGroup.Moderation,
configDisablesSetting: true,
displayName: _td("labs|mjolnir"), displayName: _td("labs|mjolnir"),
description: _td("labs|currently_experimental"), description: _td("labs|currently_experimental"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_custom_themes": { "feature_custom_themes": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Themes, labsGroup: LabGroup.Themes,
configDisablesSetting: true,
displayName: _td("labs|custom_themes"), displayName: _td("labs|custom_themes"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"feature_dehydration": { "feature_dehydration": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Encryption, labsGroup: LabGroup.Encryption,
configDisablesSetting: true,
displayName: _td("labs|dehydration"), displayName: _td("labs|dehydration"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"useOnlyCurrentProfiles": { "useOnlyCurrentProfiles": {
@ -323,22 +341,25 @@ export const SETTINGS: { [setting: string]: ISetting } = {
"feature_html_topic": { "feature_html_topic": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Rooms, labsGroup: LabGroup.Rooms,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|html_topic"), displayName: _td("labs|html_topic"),
default: false, default: false,
}, },
"feature_bridge_state": { "feature_bridge_state": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Rooms, labsGroup: LabGroup.Rooms,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|bridge_state"), displayName: _td("labs|bridge_state"),
default: false, default: false,
}, },
"feature_jump_to_date": { "feature_jump_to_date": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
configDisablesSetting: true,
displayName: _td("labs|jump_to_date"), displayName: _td("labs|jump_to_date"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
controller: new ServerSupportUnstableFeatureController( controller: new ServerSupportUnstableFeatureController(
"feature_jump_to_date", "feature_jump_to_date",
@ -368,6 +389,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
"feature_sliding_sync": { "feature_sliding_sync": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Developer, labsGroup: LabGroup.Developer,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|sliding_sync"), displayName: _td("labs|sliding_sync"),
description: _td("labs|sliding_sync_description"), description: _td("labs|sliding_sync_description"),
@ -382,32 +404,36 @@ export const SETTINGS: { [setting: string]: ISetting } = {
}, },
"feature_element_call_video_rooms": { "feature_element_call_video_rooms": {
isFeature: true, isFeature: true,
supportedLevels: LEVELS_FEATURE,
labsGroup: LabGroup.VoiceAndVideo, labsGroup: LabGroup.VoiceAndVideo,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|element_call_video_rooms"), displayName: _td("labs|element_call_video_rooms"),
controller: new ReloadOnChangeController(), controller: new ReloadOnChangeController(),
default: false, default: false,
}, },
"feature_group_calls": { "feature_group_calls": {
isFeature: true, isFeature: true,
supportedLevels: LEVELS_FEATURE,
labsGroup: LabGroup.VoiceAndVideo, labsGroup: LabGroup.VoiceAndVideo,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|group_calls"), displayName: _td("labs|group_calls"),
controller: new ReloadOnChangeController(), controller: new ReloadOnChangeController(),
default: false, default: false,
}, },
"feature_disable_call_per_sender_encryption": { "feature_disable_call_per_sender_encryption": {
isFeature: true, isFeature: true,
supportedLevels: LEVELS_FEATURE,
labsGroup: LabGroup.VoiceAndVideo, labsGroup: LabGroup.VoiceAndVideo,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|feature_disable_call_per_sender_encryption"), displayName: _td("labs|feature_disable_call_per_sender_encryption"),
default: false, default: false,
}, },
"feature_allow_screen_share_only_mode": { "feature_allow_screen_share_only_mode": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.VoiceAndVideo,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
description: _td("labs|under_active_development"), description: _td("labs|under_active_development"),
labsGroup: LabGroup.VoiceAndVideo,
displayName: _td("labs|allow_screen_share_only_mode"), displayName: _td("labs|allow_screen_share_only_mode"),
controller: new ReloadOnChangeController(), controller: new ReloadOnChangeController(),
default: false, default: false,
@ -415,7 +441,8 @@ export const SETTINGS: { [setting: string]: ISetting } = {
"feature_location_share_live": { "feature_location_share_live": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|location_share_live"), displayName: _td("labs|location_share_live"),
description: _td("labs|location_share_live_description"), description: _td("labs|location_share_live_description"),
shouldWarn: true, shouldWarn: true,
@ -424,7 +451,8 @@ export const SETTINGS: { [setting: string]: ISetting } = {
"feature_dynamic_room_predecessors": { "feature_dynamic_room_predecessors": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Rooms, labsGroup: LabGroup.Rooms,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|dynamic_room_predecessors"), displayName: _td("labs|dynamic_room_predecessors"),
description: _td("labs|dynamic_room_predecessors_description"), description: _td("labs|dynamic_room_predecessors_description"),
shouldWarn: true, shouldWarn: true,
@ -433,7 +461,8 @@ export const SETTINGS: { [setting: string]: ISetting } = {
[Features.VoiceBroadcast]: { [Features.VoiceBroadcast]: {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|voice_broadcast"), displayName: _td("labs|voice_broadcast"),
default: false, default: false,
}, },
@ -445,7 +474,8 @@ export const SETTINGS: { [setting: string]: ISetting } = {
[Features.OidcNativeFlow]: { [Features.OidcNativeFlow]: {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Developer, labsGroup: LabGroup.Developer,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|oidc_native_flow"), displayName: _td("labs|oidc_native_flow"),
description: _td("labs|oidc_native_flow_description"), description: _td("labs|oidc_native_flow_description"),
default: false, default: false,
@ -454,6 +484,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
// use the rust matrix-sdk-crypto-js for crypto. // use the rust matrix-sdk-crypto-js for crypto.
isFeature: true, isFeature: true,
labsGroup: LabGroup.Developer, labsGroup: LabGroup.Developer,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|rust_crypto"), displayName: _td("labs|rust_crypto"),
description: _td("labs|under_active_development"), description: _td("labs|under_active_development"),
@ -470,9 +501,10 @@ export const SETTINGS: { [setting: string]: ISetting } = {
"feature_render_reaction_images": { "feature_render_reaction_images": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
configDisablesSetting: true,
displayName: _td("labs|render_reaction_images"), displayName: _td("labs|render_reaction_images"),
description: _td("labs|render_reaction_images_description"), description: _td("labs|render_reaction_images_description"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
/** /**
@ -521,33 +553,37 @@ export const SETTINGS: { [setting: string]: ISetting } = {
}, },
"feature_hidebold": { "feature_hidebold": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Rooms,
configDisablesSetting: true,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("labs|hidebold"), displayName: _td("labs|hidebold"),
labsGroup: LabGroup.Rooms,
default: false, default: false,
}, },
"feature_ask_to_join": { "feature_ask_to_join": {
default: false,
displayName: _td("labs|ask_to_join"),
isFeature: true, isFeature: true,
labsGroup: LabGroup.Rooms, labsGroup: LabGroup.Rooms,
supportedLevels: LEVELS_FEATURE, configDisablesSetting: true,
default: false,
displayName: _td("labs|ask_to_join"),
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
}, },
"feature_new_room_decoration_ui": { "feature_new_room_decoration_ui": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Rooms, labsGroup: LabGroup.Rooms,
configDisablesSetting: true,
displayName: _td("labs|new_room_decoration_ui"), displayName: _td("labs|new_room_decoration_ui"),
description: _td("labs|under_active_development"), description: _td("labs|under_active_development"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
controller: new ReloadOnChangeController(), controller: new ReloadOnChangeController(),
}, },
"feature_notifications": { "feature_notifications": {
isFeature: true, isFeature: true,
labsGroup: LabGroup.Messaging, labsGroup: LabGroup.Messaging,
configDisablesSetting: true,
displayName: _td("labs|notifications"), displayName: _td("labs|notifications"),
description: _td("labs|unrealiable_e2e"), description: _td("labs|unrealiable_e2e"),
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: false, default: false,
}, },
"useCompactLayout": { "useCompactLayout": {

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. * 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`, * 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 * 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 * 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. * 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} settingName The name of the setting to check.
* @param {String} roomId The room ID to check in, may be null. * @param {String} roomId The room ID to check in, may be null.
* @param {SettingLevel} level The level to * @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."); throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
} }
if (!SettingsStore.isEnabled(settingName)) { if (SETTINGS[settingName].controller?.settingDisabled) {
return false; return false;
} }
// When non-beta features are specified in the config.json, we force them as enabled or disabled. // 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); const configVal = SettingsStore.getValueAt(SettingLevel.CONFIG, settingName, roomId, true, true);
if (configVal === true || configVal === false) return false; if (configVal === true || configVal === false) return false;
} }

View file

@ -42,7 +42,6 @@ describe("PreferencesUserSettingsTab", () => {
beforeEach(() => { beforeEach(() => {
stubClient(); stubClient();
jest.spyOn(SettingsStore, "setValue"); jest.spyOn(SettingsStore, "setValue");
jest.spyOn(SettingsStore, "canSetValue").mockReturnValue(true);
jest.spyOn(window, "matchMedia").mockReturnValue({ matches: false } as MediaQueryList); jest.spyOn(window, "matchMedia").mockReturnValue({ matches: false } as MediaQueryList);
}); });