From f6177cd7b561ce544cce646ceee7f6bf288c8f11 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 29 Oct 2017 01:51:02 -0600 Subject: [PATCH 1/6] Use granular settings instead of synced settings Signed-off-by: Travis Ralston --- src/components/structures/BottomLeftMenu.js | 4 ++-- src/components/views/context_menus/MessageContextMenu.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/structures/BottomLeftMenu.js b/src/components/structures/BottomLeftMenu.js index 4014261caa..5511cc8c8a 100644 --- a/src/components/structures/BottomLeftMenu.js +++ b/src/components/structures/BottomLeftMenu.js @@ -21,7 +21,7 @@ import sdk from 'matrix-react-sdk'; import dis from 'matrix-react-sdk/lib/dispatcher'; import Velocity from 'velocity-vector'; import 'velocity-vector/velocity.ui'; -import UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; +import SettingsStore from "matrix-react-sdk/lib/settings/SettingsStore"; const CALLOUT_ANIM_DURATION = 1000; @@ -170,7 +170,7 @@ module.exports = React.createClass({ const GroupsButton = sdk.getComponent('elements.GroupsButton'); const SettingsButton = sdk.getComponent('elements.SettingsButton'); - const groupsButton = UserSettingsStore.isFeatureEnabled('feature_groups') ? + const groupsButton = SettingsStore.isFeatureEnabled('feature_groups') ? : null; return ( diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index a07d11626d..d8f9a4daa2 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -24,7 +24,7 @@ const sdk = require('matrix-react-sdk'); import { _t } from 'matrix-react-sdk/lib/languageHandler'; const Modal = require('matrix-react-sdk/lib/Modal'); const Resend = require("matrix-react-sdk/lib/Resend"); -import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; +import SettingsStore from "matrix-react-sdk/lib/settings/SettingsStore"; module.exports = React.createClass({ displayName: 'MessageContextMenu', @@ -67,7 +67,7 @@ module.exports = React.createClass({ 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 (!UserSettingsStore.isFeatureEnabled("feature_pinning")) canPin = false; + if (!SettingsStore.isFeatureEnabled("feature_pinning")) canPin = false; this.setState({canRedact, canPin}); }, From ccf52b2a69ff656c622e266f031f2115186bf4a0 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 29 Oct 2017 17:05:27 -0600 Subject: [PATCH 2/6] Convert local settings to granular settings Signed-off-by: Travis Ralston --- src/vector/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index a08397ce5a..0d42dda651 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -67,7 +67,6 @@ sdk.loadSkin(require('../component-index')); var VectorConferenceHandler = require('../VectorConferenceHandler'); import Promise from 'bluebird'; var request = require('browser-request'); -import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; import * as languageHandler from 'matrix-react-sdk/lib/languageHandler'; // Also import _t directly so we can call it just `_t` as this is what gen-i18n.js expects import { _t } from 'matrix-react-sdk/lib/languageHandler'; @@ -78,6 +77,7 @@ import {parseQs, parseQsFromFragment} from './url_utils'; import Platform from './platform'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; +import SettingsStore from "../../../matrix-react-sdk/src/settings/SettingsStore"; var lastLocationHashSet = null; @@ -328,7 +328,7 @@ async function loadApp() { } async function loadLanguage() { - const prefLang = UserSettingsStore.getLocalSetting('language'); + const prefLang = SettingsStore.getValue("language"); let langs = []; if (!prefLang) { From f1c81be6334018cbbc2082f253484595e4c2f9b8 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 29 Oct 2017 22:18:34 -0600 Subject: [PATCH 3/6] Import the right SettingsStore Signed-off-by: Travis Ralston --- src/vector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.js b/src/vector/index.js index 0d42dda651..144df9b542 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -77,7 +77,7 @@ import {parseQs, parseQsFromFragment} from './url_utils'; import Platform from './platform'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; -import SettingsStore from "../../../matrix-react-sdk/src/settings/SettingsStore"; +import SettingsStore from "matrix-react-sdk/lib/settings/SettingsStore"; var lastLocationHashSet = null; From 63607f29e79f713dd750dda9d5b8f3ae79984ee4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 4 Nov 2017 22:27:34 -0700 Subject: [PATCH 4/6] Use SettingsStore for notification settings Signed-off-by: Travis Ralstron --- .../views/settings/Notifications.js | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index fa3f48c1cf..fe6e677651 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -20,11 +20,12 @@ import sdk from 'matrix-react-sdk'; import { _t, _tJsx } from 'matrix-react-sdk/lib/languageHandler'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; import UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; +import SettingsStore, {SettingLevel} from "matrix-react-sdk/lib/settings/SettingsStore"; import Modal from 'matrix-react-sdk/lib/Modal'; import { - NotificationUtils, - VectorPushRulesDefinitions, - PushRuleVectorState, + NotificationUtils, + VectorPushRulesDefinitions, + PushRuleVectorState, ContentRules } from '../../../notifications'; @@ -112,12 +113,33 @@ module.exports = React.createClass({ }, onEnableDesktopNotificationsChange: function(event) { - UserSettingsStore.setEnableNotifications(event.target.checked); + SettingsStore.setValue( + "notificationsEnabled", null, + SettingLevel.DEVICE, + event.target.checked, + ).finally(() => { + this.forceUpdate(); + }); }, onEnableDesktopNotificationBodyChange: function(event) { - UserSettingsStore.setEnableNotificationBody(event.target.checked); - this.forceUpdate(); + SettingsStore.setValue( + "notificationBodyEnabled", null, + SettingLevel.DEVICE, + event.target.checked, + ).finally(() => { + this.forceUpdate(); + }); + }, + + onEnableAudioNotificationsChange: function(event) { + SettingsStore.setValue( + "audioNotificationsEnabled", null, + SettingLevel.DEVICE, + event.target.checked, + ).finally(() => { + this.forceUpdate(); + }); }, onEnableEmailNotificationsChange: function(address, event) { @@ -433,7 +455,7 @@ module.exports = React.createClass({ needsUpdate.push( function(kind, rule) { return cli.setPushRuleActions( 'global', kind, LEGACY_RULES[rule.rule_id], portLegacyActions(rule.actions) - ).then(() => + ).then(() => cli.deletePushRule('global', kind, rule.rule_id) ).catch( (e) => { console.warn(`Error when porting legacy rule: ${e}`); @@ -446,7 +468,7 @@ module.exports = React.createClass({ if (needsUpdate.length > 0) { // If some of the rules need to be ported then wait for the porting // to happen and then fetch the rules again. - return Promise.all(needsUpdate).then(() => + return Promise.all(needsUpdate).then(() => cli.getPushRules() ); } else { @@ -694,13 +716,13 @@ module.exports = React.createClass({ render: function() { const self = this; - + let spinner; if (this.state.phase === this.phases.LOADING) { const Loader = sdk.getComponent("elements.Spinner"); spinner = ; } - + let masterPushRuleDiv; if (this.state.masterPushRule) { masterPushRuleDiv = ( @@ -710,7 +732,7 @@ module.exports = React.createClass({ ref="enableNotifications" type="checkbox" checked={ !this.state.masterPushRule.enabled } - onChange={ this.onEnableNotificationsChange } + onChange={ this.onEnableNotificationsChange } />
@@ -824,7 +846,7 @@ module.exports = React.createClass({
@@ -839,7 +861,7 @@ module.exports = React.createClass({
@@ -854,11 +876,8 @@ module.exports = React.createClass({ { - UserSettingsStore.setEnableAudioNotifications(e.target.checked); - this.forceUpdate(); - }} /> + checked={ SettingsStore.getValue("audioNotificationsEnabled") } + onChange={ this.onEnableAudioNotificationsChange } />