diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index 117a2948d..ce4efc694 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -49,6 +49,7 @@ module.exports = React.createClass({ getInitialState: function() { return { phase: this.phases.LOADING, + masterPushRule: undefined, // The master rule ('.m.rule.master') vectorPushRules: [], // HS default push rules displayed in Vector UI vectorContentRules: { // Keyword push rules displayed in Vector UI state: PushRuleState.ON, @@ -66,6 +67,17 @@ module.exports = React.createClass({ }, onEnableNotificationsChange: function(event) { + var self = this; + this.setState({ + phase: this.phases.LOADING + }); + + MatrixClientPeg.get().setPushRuleEnabled('global', self.state.masterPushRule.kind, self.state.masterPushRule.rule_id, !event.target.checked).done(function() { + self._refreshFromServer(); + }); + }, + + onEnableDesktopNotificationsChange: function(event) { UserSettingsStore.setEnableNotifications(event.target.checked); }, @@ -427,7 +439,12 @@ module.exports = React.createClass({ self.state.externalContentRules = contentRules.other; } - // Build the rules displayed by Vector UI + // Get the master rule if any defined by the hs + if (defaultRules.master.length > 0) { + self.state.masterPushRule = defaultRules.master[0]; + } + + // Build the rules displayed in Vector UI matrix table self.state.vectorPushRules = []; var rule, state; @@ -590,6 +607,38 @@ module.exports = React.createClass({ ); } + if (this.state.masterPushRule) { + var masterPushRuleDiv = ( +
+
+ +
+
+ +
+
+ ); + } + + // When enabled, the master rule inhibits all existing rules + if (this.state.masterPushRule.enabled) { + return ( +
+ {masterPushRuleDiv} + +
+ All notifications are currently disabled for all devices. +
+
+ ); + } + // Build the list of keywords rules that have been defined outside Vector UI var externalKeyWords = []; for (var i in this.state.externalContentRules) { @@ -603,18 +652,21 @@ module.exports = React.createClass({ return (
+ + {masterPushRuleDiv} +
- + onChange={ this.onEnableDesktopNotificationsChange } />
-