From 4f47907abfcf1b987973e87ab55a682b88ad0356 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 11 Aug 2021 23:33:10 +0100 Subject: [PATCH] Show disabled spaces section in preferences regardless --- .../tabs/user/PreferencesUserSettingsTab.tsx | 18 +++++++++++++----- src/settings/Settings.tsx | 1 + src/settings/SettingsStore.ts | 4 ++++ .../controllers/IncompatibleController.ts | 6 +++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 27758a5205..74cdc2ea2d 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -285,8 +285,16 @@ export default class PreferencesUserSettingsTab extends React.Component { + private renderGroup( + settingIds: string[], + level = SettingLevel.ACCOUNT, + includeDisabled = false, + ): React.ReactNodeArray { + if (!includeDisabled) { + settingIds = settingIds.filter(SettingsStore.isEnabled); + } + + return settingIds.map(i => { return ; }); } @@ -333,10 +341,10 @@ export default class PreferencesUserSettingsTab extends React.Component - { SpaceStore.spacesEnabled &&
+
{ _t("Spaces") } - { this.renderGroup(PreferencesUserSettingsTab.SPACES_SETTINGS) } -
} + { this.renderGroup(PreferencesUserSettingsTab.SPACES_SETTINGS, SettingLevel.ACCOUNT, true) } +
{ _t("Communities") } diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 9d4592e5d7..419139c4e7 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -729,6 +729,7 @@ export const SETTINGS: {[setting: string]: ISetting} = { description: _td("All rooms you're in will appear in Home."), supportedLevels: LEVELS_ACCOUNT_SETTINGS, default: false, + controller: new IncompatibleController("showCommunitiesInsteadOfSpaces", null), }, "showCommunitiesInsteadOfSpaces": { displayName: _td("Display Communities instead of Spaces"), diff --git a/src/settings/SettingsStore.ts b/src/settings/SettingsStore.ts index c5b83cbcd0..9487feff5e 100644 --- a/src/settings/SettingsStore.ts +++ b/src/settings/SettingsStore.ts @@ -467,6 +467,10 @@ export default class SettingsStore { throw new Error("Setting '" + settingName + "' does not appear to be a setting."); } + if (!SettingsStore.isEnabled(settingName)) { + 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) { const configVal = SettingsStore.getValueAt(SettingLevel.CONFIG, settingName, roomId, true, true); diff --git a/src/settings/controllers/IncompatibleController.ts b/src/settings/controllers/IncompatibleController.ts index 3a7d6ab7d7..aa064219f9 100644 --- a/src/settings/controllers/IncompatibleController.ts +++ b/src/settings/controllers/IncompatibleController.ts @@ -26,7 +26,7 @@ import SettingsStore from "../SettingsStore"; export default class IncompatibleController extends SettingController { public constructor( private settingName: string, - private forcedValue = false, + private forcedValue: any = false, private incompatibleValue: any = true, ) { super(); @@ -44,6 +44,10 @@ export default class IncompatibleController extends SettingController { return null; // no override } + public get settingDisabled(): boolean { + return this.incompatibleSetting; + } + public get incompatibleSetting(): boolean { return SettingsStore.getValue(this.settingName) === this.incompatibleValue; }