diff --git a/src/FromWidgetPostMessageApi.js b/src/FromWidgetPostMessageApi.js index 1b4aa19ebf..d5d7c08d50 100644 --- a/src/FromWidgetPostMessageApi.js +++ b/src/FromWidgetPostMessageApi.js @@ -197,7 +197,7 @@ export default class FromWidgetPostMessageApi { const integId = (data && data.integId) ? data.integId : null; // TODO: Open the right integration manager for the widget - if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) { + if (SettingsStore.getValue("feature_many_integration_managers")) { IntegrationManagers.sharedInstance().openAll( MatrixClientPeg.get().getRoom(RoomViewStore.getRoomId()), `type_${integType}`, diff --git a/src/components/structures/LeftPanel.tsx b/src/components/structures/LeftPanel.tsx index bc17bbe23f..a0d7f3d9ea 100644 --- a/src/components/structures/LeftPanel.tsx +++ b/src/components/structures/LeftPanel.tsx @@ -377,7 +377,7 @@ export default class LeftPanel extends React.Component { const tagPanel = !this.state.showTagPanel ? null : (
- {SettingsStore.isFeatureEnabled("feature_custom_tags") ? : null} + {SettingsStore.getValue("feature_custom_tags") ? : null}
); diff --git a/src/components/views/avatars/MemberStatusMessageAvatar.js b/src/components/views/avatars/MemberStatusMessageAvatar.js index eef3f86d9a..d5d927106c 100644 --- a/src/components/views/avatars/MemberStatusMessageAvatar.js +++ b/src/components/views/avatars/MemberStatusMessageAvatar.js @@ -53,7 +53,7 @@ export default class MemberStatusMessageAvatar extends React.Component { if (this.props.member.userId !== MatrixClientPeg.get().getUserId()) { throw new Error("Cannot use MemberStatusMessageAvatar on anyone but the logged in user"); } - if (!SettingsStore.isFeatureEnabled("feature_custom_status")) { + if (!SettingsStore.getValue("feature_custom_status")) { return; } const { user } = this.props.member; @@ -105,7 +105,7 @@ export default class MemberStatusMessageAvatar extends React.Component { resizeMethod={this.props.resizeMethod} />; - if (!SettingsStore.isFeatureEnabled("feature_custom_status")) { + if (!SettingsStore.getValue("feature_custom_status")) { return avatar; } diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index 59e3d4c230..6fa54058a0 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -81,7 +81,7 @@ export default createReactClass({ let canPin = room.currentState.mayClientSendStateEvent('m.room.pinned_events', cli); // HACK: Intentionally say we can't pin if the user doesn't want to use the functionality - if (!SettingsStore.isFeatureEnabled("feature_pinning")) canPin = false; + if (!SettingsStore.getValue("feature_pinning")) canPin = false; this.setState({canRedact, canPin}); }, diff --git a/src/components/views/dialogs/RoomSettingsDialog.js b/src/components/views/dialogs/RoomSettingsDialog.js index 7ad1001f75..613708e436 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.js +++ b/src/components/views/dialogs/RoomSettingsDialog.js @@ -87,7 +87,7 @@ export default class RoomSettingsDialog extends React.Component { , )); - if (SettingsStore.isFeatureEnabled("feature_bridge_state")) { + if (SettingsStore.getValue("feature_bridge_state")) { tabs.push(new Tab( ROOM_BRIDGES_TAB, _td("Bridges"), diff --git a/src/components/views/dialogs/UserSettingsDialog.js b/src/components/views/dialogs/UserSettingsDialog.js index 1f1a8d1523..820de713c1 100644 --- a/src/components/views/dialogs/UserSettingsDialog.js +++ b/src/components/views/dialogs/UserSettingsDialog.js @@ -54,7 +54,7 @@ export default class UserSettingsDialog extends React.Component { super(); this.state = { - mjolnirEnabled: SettingsStore.isFeatureEnabled("feature_mjolnir"), + mjolnirEnabled: SettingsStore.getValue("feature_mjolnir"), }; } diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 75946f19c1..a52dea3e0a 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -311,7 +311,7 @@ export default class AppTile extends React.Component { this.props.onEditClick(); } else { // TODO: Open the right manager for the widget - if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) { + if (SettingsStore.getValue("feature_many_integration_managers")) { IntegrationManagers.sharedInstance().openAll( this.props.room, 'type_' + this.props.app.type, diff --git a/src/components/views/elements/InlineSpinner.js b/src/components/views/elements/InlineSpinner.js index 89b5e6f19d..ce3c738f3b 100644 --- a/src/components/views/elements/InlineSpinner.js +++ b/src/components/views/elements/InlineSpinner.js @@ -28,7 +28,7 @@ export default createReactClass({ const imgClass = this.props.imgClassName || ""; let imageSource; - if (SettingsStore.isFeatureEnabled('feature_new_spinner')) { + if (SettingsStore.getValue('feature_new_spinner')) { imageSource = require("../../../../res/img/spinner.svg"); } else { imageSource = require("../../../../res/img/spinner.gif"); diff --git a/src/components/views/elements/ManageIntegsButton.js b/src/components/views/elements/ManageIntegsButton.js index ac8a98a94a..0990218c65 100644 --- a/src/components/views/elements/ManageIntegsButton.js +++ b/src/components/views/elements/ManageIntegsButton.js @@ -34,7 +34,7 @@ export default class ManageIntegsButton extends React.Component { if (!managers.hasManager()) { managers.openNoManagerDialog(); } else { - if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) { + if (SettingsStore.getValue("feature_many_integration_managers")) { managers.openAll(this.props.room); } else { managers.getPrimaryManager().open(this.props.room); diff --git a/src/components/views/elements/Spinner.js b/src/components/views/elements/Spinner.js index 033d4d13f4..4d2dcea90a 100644 --- a/src/components/views/elements/Spinner.js +++ b/src/components/views/elements/Spinner.js @@ -22,7 +22,7 @@ import SettingsStore from "../../../settings/SettingsStore"; const Spinner = ({w = 32, h = 32, imgClassName, message}) => { let imageSource; - if (SettingsStore.isFeatureEnabled('feature_new_spinner')) { + if (SettingsStore.getValue('feature_new_spinner')) { imageSource = require("../../../../res/img/spinner.svg"); } else { imageSource = require("../../../../res/img/spinner.gif"); diff --git a/src/components/views/messages/MessageEvent.js b/src/components/views/messages/MessageEvent.js index eb74270762..c3e5af2eb6 100644 --- a/src/components/views/messages/MessageEvent.js +++ b/src/components/views/messages/MessageEvent.js @@ -95,7 +95,7 @@ export default createReactClass({ } } - if (SettingsStore.isFeatureEnabled("feature_mjolnir")) { + if (SettingsStore.getValue("feature_mjolnir")) { const key = `mx_mjolnir_render_${this.props.mxEvent.getRoomId()}__${this.props.mxEvent.getId()}`; const allowRender = localStorage.getItem(key) === "true"; diff --git a/src/components/views/right_panel/UserInfo.js b/src/components/views/right_panel/UserInfo.js index b52792b3d1..71ee86a1ea 100644 --- a/src/components/views/right_panel/UserInfo.js +++ b/src/components/views/right_panel/UserInfo.js @@ -1428,7 +1428,7 @@ const UserInfoHeader = ({onClose, member, e2eStatus}) => { presenceLastActiveAgo = member.user.lastActiveAgo; presenceCurrentlyActive = member.user.currentlyActive; - if (SettingsStore.isFeatureEnabled("feature_custom_status")) { + if (SettingsStore.getValue("feature_custom_status")) { statusMessage = member.user._unstable_statusMessage; } } diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 06dfffad30..8cf7a54da2 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -130,7 +130,7 @@ export default createReactClass({ }, _launchManageIntegrations: function() { - if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) { + if (SettingsStore.getValue("feature_many_integration_managers")) { IntegrationManagers.sharedInstance().openAll(); } else { IntegrationManagers.sharedInstance().getPrimaryManager().open(this.props.room, 'add_integ'); diff --git a/src/components/views/rooms/AuxPanel.js b/src/components/views/rooms/AuxPanel.js index ad66f0e151..521aeec406 100644 --- a/src/components/views/rooms/AuxPanel.js +++ b/src/components/views/rooms/AuxPanel.js @@ -104,7 +104,7 @@ export default createReactClass({ }, _rateLimitedUpdate: new RateLimitedFunc(function() { - if (SettingsStore.isFeatureEnabled("feature_state_counters")) { + if (SettingsStore.getValue("feature_state_counters")) { this.setState({counters: this._computeCounters()}); } }, 500), @@ -112,7 +112,7 @@ export default createReactClass({ _computeCounters: function() { let counters = []; - if (this.props.room && SettingsStore.isFeatureEnabled("feature_state_counters")) { + if (this.props.room && SettingsStore.getValue("feature_state_counters")) { const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter'); stateEvs.sort((a, b) => { return a.getStateKey() < b.getStateKey(); @@ -206,7 +206,7 @@ export default createReactClass({ />; let stateViews = null; - if (this.state.counters && SettingsStore.isFeatureEnabled("feature_state_counters")) { + if (this.state.counters && SettingsStore.getValue("feature_state_counters")) { let counters = []; this.state.counters.forEach((counter, idx) => { diff --git a/src/components/views/rooms/MemberTile.js b/src/components/views/rooms/MemberTile.js index 3be378b341..ebb8b7999d 100644 --- a/src/components/views/rooms/MemberTile.js +++ b/src/components/views/rooms/MemberTile.js @@ -50,7 +50,7 @@ export default createReactClass({ componentDidMount() { const cli = MatrixClientPeg.get(); - if (SettingsStore.isFeatureEnabled("feature_custom_status")) { + if (SettingsStore.getValue("feature_custom_status")) { const { user } = this.props.member; if (user) { user.on("User._unstable_statusMessage", this._onStatusMessageCommitted); @@ -209,7 +209,7 @@ export default createReactClass({ const presenceState = member.user ? member.user.presence : null; let statusMessage = null; - if (member.user && SettingsStore.isFeatureEnabled("feature_custom_status")) { + if (member.user && SettingsStore.getValue("feature_custom_status")) { statusMessage = this.state.statusMessage; } diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 1dedd53d00..fe5b12c1c0 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -226,7 +226,7 @@ export default createReactClass({ title={_t("Settings")} />; } - if (this.props.onPinnedClick && SettingsStore.isFeatureEnabled('feature_pinning')) { + if (this.props.onPinnedClick && SettingsStore.getValue('feature_pinning')) { let pinsIndicator = null; if (this._hasUnreadPins()) { pinsIndicator = (
); diff --git a/src/components/views/rooms/Stickerpicker.js b/src/components/views/rooms/Stickerpicker.js index b48790a9cf..dba25a94cf 100644 --- a/src/components/views/rooms/Stickerpicker.js +++ b/src/components/views/rooms/Stickerpicker.js @@ -363,7 +363,7 @@ export default class Stickerpicker extends React.Component { */ _launchManageIntegrations() { // TODO: Open the right integration manager for the widget - if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) { + if (SettingsStore.getValue("feature_many_integration_managers")) { IntegrationManagers.sharedInstance().openAll( this.props.room, `type_${WidgetType.STICKERPICKER.preferred}`, diff --git a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx index c646025bbe..c9ec4a6bc7 100644 --- a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx @@ -237,7 +237,7 @@ export default class AppearanceUserSettingsTab extends React.Component; } } diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts index 4d1e1d5bad..9534fccc4c 100644 --- a/src/hooks/useSettings.ts +++ b/src/hooks/useSettings.ts @@ -36,11 +36,11 @@ export const useSettingValue = (settingName: string, roomId: string = null, excl // Hook to fetch whether a feature is enabled and dynamically update when that changes export const useFeatureEnabled = (featureName: string, roomId: string = null) => { - const [enabled, setEnabled] = useState(SettingsStore.isFeatureEnabled(featureName, roomId)); + const [enabled, setEnabled] = useState(SettingsStore.getValue(featureName, roomId)); useEffect(() => { const ref = SettingsStore.watchSetting(featureName, roomId, () => { - setEnabled(SettingsStore.isFeatureEnabled(featureName, roomId)); + setEnabled(SettingsStore.getValue(featureName, roomId)); }); // clean-up return () => { diff --git a/src/rageshake/submit-rageshake.ts b/src/rageshake/submit-rageshake.ts index 76b0444052..80034691c8 100644 --- a/src/rageshake/submit-rageshake.ts +++ b/src/rageshake/submit-rageshake.ts @@ -143,7 +143,7 @@ export default async function sendBugReport(bugReportEndpoint: string, opts: IOp } // add labs options - const enabledLabs = SettingsStore.getLabsFeatures().filter(f => SettingsStore.isFeatureEnabled(f)); + const enabledLabs = SettingsStore.getLabsFeatures().filter(f => SettingsStore.getValue(f)); if (enabledLabs.length) { body.append('enabled_labs', enabledLabs.join(', ')); } diff --git a/src/settings/SettingsStore.ts b/src/settings/SettingsStore.ts index e64de8af16..6c1f9b8411 100644 --- a/src/settings/SettingsStore.ts +++ b/src/settings/SettingsStore.ts @@ -240,19 +240,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 +250,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 { - // 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 +300,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 @@ -611,24 +558,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 diff --git a/src/stores/CustomRoomTagStore.js b/src/stores/CustomRoomTagStore.js index 1f24dc589a..39177181b4 100644 --- a/src/stores/CustomRoomTagStore.js +++ b/src/stores/CustomRoomTagStore.js @@ -137,7 +137,7 @@ class CustomRoomTagStore extends EventEmitter { } _getUpdatedTags() { - if (!SettingsStore.isFeatureEnabled("feature_custom_tags")) { + if (!SettingsStore.getValue("feature_custom_tags")) { return {}; // none } diff --git a/src/stores/room-list/RoomListStore.ts b/src/stores/room-list/RoomListStore.ts index f4c2d5050e..0f3138fe9e 100644 --- a/src/stores/room-list/RoomListStore.ts +++ b/src/stores/room-list/RoomListStore.ts @@ -136,7 +136,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient { } private async readAndCacheSettingsFromStore() { - const tagsEnabled = SettingsStore.isFeatureEnabled("feature_custom_tags"); + const tagsEnabled = SettingsStore.getValue("feature_custom_tags"); await this.updateState({ tagsEnabled, }); diff --git a/src/stores/room-list/previews/ReactionEventPreview.ts b/src/stores/room-list/previews/ReactionEventPreview.ts index c8f2be9a6e..95cdc01c66 100644 --- a/src/stores/room-list/previews/ReactionEventPreview.ts +++ b/src/stores/room-list/previews/ReactionEventPreview.ts @@ -24,8 +24,8 @@ import DMRoomMap from "../../../utils/DMRoomMap"; export class ReactionEventPreview implements IPreview { public getTextFor(event: MatrixEvent, tagId?: TagID): string { - const showDms = SettingsStore.isFeatureEnabled("feature_roomlist_preview_reactions_dms"); - const showAll = SettingsStore.isFeatureEnabled("feature_roomlist_preview_reactions_all"); + const showDms = SettingsStore.getValue("feature_roomlist_preview_reactions_dms"); + const showAll = SettingsStore.getValue("feature_roomlist_preview_reactions_all"); if (!showAll && (!showDms || DMRoomMap.shared().getUserIdForRoomId(event.getRoomId()))) return null;