PushRules settings: BF adding a keyword when the keywords rule is OFF
parent
c3469b5b51
commit
2dd2acd4e0
|
@ -83,12 +83,12 @@ module.exports = React.createClass({
|
||||||
var newPushRuleVectorState = event.target.className.split("-")[1];
|
var newPushRuleVectorState = event.target.className.split("-")[1];
|
||||||
|
|
||||||
if ("keywords" === vectorRuleId) {
|
if ("keywords" === vectorRuleId) {
|
||||||
this._changeKeywordsPushRuleVectorState(newPushRuleVectorState)
|
this._setKeywordsPushRuleVectorState(newPushRuleVectorState)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var rule = this.getRule(vectorRuleId);
|
var rule = this.getRule(vectorRuleId);
|
||||||
if (rule) {
|
if (rule) {
|
||||||
this._changePushRuleVectorState(rule, newPushRuleVectorState);
|
this._setPushRuleVectorState(rule, newPushRuleVectorState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -134,7 +134,7 @@ module.exports = React.createClass({
|
||||||
return array;
|
return array;
|
||||||
},[]);
|
},[]);
|
||||||
|
|
||||||
self._updateKeywords(newKeywords);
|
self._setKeywords(newKeywords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -186,7 +186,7 @@ module.exports = React.createClass({
|
||||||
return stateKind;
|
return stateKind;
|
||||||
},
|
},
|
||||||
|
|
||||||
_changePushRuleVectorState: function(rule, newPushRuleVectorState) {
|
_setPushRuleVectorState: function(rule, newPushRuleVectorState) {
|
||||||
// For now, we support only enabled/disabled for hs default rules
|
// For now, we support only enabled/disabled for hs default rules
|
||||||
// Translate ON, LOUD, OFF to one of the 2.
|
// Translate ON, LOUD, OFF to one of the 2.
|
||||||
if (rule && rule.vectorState !== newPushRuleVectorState) {
|
if (rule && rule.vectorState !== newPushRuleVectorState) {
|
||||||
|
@ -202,7 +202,7 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_changeKeywordsPushRuleVectorState: function(newPushRuleVectorState) {
|
_setKeywordsPushRuleVectorState: function(newPushRuleVectorState) {
|
||||||
// Is there really a change?
|
// Is there really a change?
|
||||||
if (this.state.vectorContentRules.vectorState === newPushRuleVectorState
|
if (this.state.vectorContentRules.vectorState === newPushRuleVectorState
|
||||||
|| this.state.vectorContentRules.rules.length === 0) {
|
|| this.state.vectorContentRules.rules.length === 0) {
|
||||||
|
@ -221,8 +221,7 @@ module.exports = React.createClass({
|
||||||
for (var i in this.state.vectorContentRules.rules) {
|
for (var i in this.state.vectorContentRules.rules) {
|
||||||
var rule = this.state.vectorContentRules.rules[i];
|
var rule = this.state.vectorContentRules.rules[i];
|
||||||
|
|
||||||
var enabled;
|
var enabled, actions;
|
||||||
var actions;
|
|
||||||
switch (newPushRuleVectorState) {
|
switch (newPushRuleVectorState) {
|
||||||
case PushRuleVectorState.ON:
|
case PushRuleVectorState.ON:
|
||||||
if (rule.actions.length !== 1) {
|
if (rule.actions.length !== 1) {
|
||||||
|
@ -271,7 +270,7 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateKeywords: function(newKeywords) {
|
_setKeywords: function(newKeywords) {
|
||||||
this.setState({
|
this.setState({
|
||||||
phase: this.phases.LOADING
|
phase: this.phases.LOADING
|
||||||
});
|
});
|
||||||
|
@ -314,30 +313,40 @@ module.exports = React.createClass({
|
||||||
// Then, add the new ones
|
// Then, add the new ones
|
||||||
q.all(removeDeferreds).done(function(resps) {
|
q.all(removeDeferreds).done(function(resps) {
|
||||||
var deferreds = [];
|
var deferreds = [];
|
||||||
|
|
||||||
|
var pushRuleVectorStateKind = self.state.vectorContentRules.vectorState;
|
||||||
|
if (pushRuleVectorStateKind === PushRuleVectorState.OFF) {
|
||||||
|
// When the current global keywords rule is OFF, we need to look at
|
||||||
|
// the flavor of rules in 'vectorContentRules' to apply the same actions
|
||||||
|
// when creating the new rule.
|
||||||
|
// Thus, this new rule will join the 'vectorContentRules' set.
|
||||||
|
if (self.state.vectorContentRules.rules.length) {
|
||||||
|
pushRuleVectorStateKind = self._pushRuleVectorStateKind(self.state.vectorContentRules.rules[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// ON is default
|
||||||
|
pushRuleVectorStateKind = PushRuleVectorState.ON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var i in newKeywords) {
|
for (var i in newKeywords) {
|
||||||
var keyword = newKeywords[i];
|
var keyword = newKeywords[i];
|
||||||
|
|
||||||
var pushRuleVectorStateKind = self.state.vectorContentRules.vectorState;
|
if (vectorContentRulesPatterns.indexOf(keyword) < 0) {
|
||||||
if (pushRuleVectorStateKind === PushRuleVectorState.OFF) {
|
if (self.state.vectorContentRules.vectorState !== PushRuleVectorState.OFF) {
|
||||||
// When the current global keywords rule is OFF, we need to look at
|
deferreds.push(cli.addPushRule
|
||||||
// the flavor of rules in 'vectorContentRules' to apply the same actions
|
('global', 'content', keyword, {
|
||||||
// when creating the new rule.
|
actions: self._actionsFor(pushRuleVectorStateKind),
|
||||||
// Thus, this new rule will join the 'vectorContentRules' set.
|
pattern: keyword
|
||||||
if (self.state.vectorContentRules.rules.length) {
|
}));
|
||||||
pushRuleVectorStateKind = self._pushRuleVectorStateKind(self.state.vectorContentRules.rules[0]);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// ON is default
|
deferreds.push(self._addDisabledPushRule('global', 'content', keyword, {
|
||||||
pushRuleVectorStateKind = PushRuleVectorState.ON;
|
actions: self._actionsFor(pushRuleVectorStateKind),
|
||||||
|
pattern: keyword
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vectorContentRulesPatterns.indexOf(keyword) < 0) {
|
|
||||||
deferreds.push(cli.addPushRule('global', 'content', keyword, {
|
|
||||||
actions: self._actionsFor(pushRuleVectorStateKind),
|
|
||||||
pattern: keyword
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
q.all(deferreds).done(function(resps) {
|
q.all(deferreds).done(function(resps) {
|
||||||
|
@ -346,6 +355,24 @@ module.exports = React.createClass({
|
||||||
}, onError);
|
}, onError);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Create a push rule but disabled
|
||||||
|
_addDisabledPushRule: function(scope, kind, ruleId, body) {
|
||||||
|
var cli = MatrixClientPeg.get();
|
||||||
|
var deferred = q.defer();
|
||||||
|
|
||||||
|
cli.addPushRule(scope, kind, ruleId, body).done(function() {
|
||||||
|
cli.setPushRuleEnabled(scope, kind, ruleId, false).done(function() {
|
||||||
|
deferred.resolve();
|
||||||
|
}, function(err) {
|
||||||
|
deferred.reject(err);
|
||||||
|
});
|
||||||
|
}, function(err) {
|
||||||
|
deferred.reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
|
||||||
_refreshFromServer: function() {
|
_refreshFromServer: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
MatrixClientPeg.get().getPushRules().done(function(rulesets) {
|
MatrixClientPeg.get().getPushRules().done(function(rulesets) {
|
||||||
|
|
Loading…
Reference in New Issue