PushRules settings: BF adding a keyword when the keywords rule is OFF
This commit is contained in:
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,8 +313,6 @@ 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 = [];
|
||||||
for (var i in newKeywords) {
|
|
||||||
var keyword = newKeywords[i];
|
|
||||||
|
|
||||||
var pushRuleVectorStateKind = self.state.vectorContentRules.vectorState;
|
var pushRuleVectorStateKind = self.state.vectorContentRules.vectorState;
|
||||||
if (pushRuleVectorStateKind === PushRuleVectorState.OFF) {
|
if (pushRuleVectorStateKind === PushRuleVectorState.OFF) {
|
||||||
|
@ -332,12 +329,24 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var i in newKeywords) {
|
||||||
|
var keyword = newKeywords[i];
|
||||||
|
|
||||||
if (vectorContentRulesPatterns.indexOf(keyword) < 0) {
|
if (vectorContentRulesPatterns.indexOf(keyword) < 0) {
|
||||||
deferreds.push(cli.addPushRule('global', 'content', keyword, {
|
if (self.state.vectorContentRules.vectorState !== PushRuleVectorState.OFF) {
|
||||||
|
deferreds.push(cli.addPushRule
|
||||||
|
('global', 'content', keyword, {
|
||||||
actions: self._actionsFor(pushRuleVectorStateKind),
|
actions: self._actionsFor(pushRuleVectorStateKind),
|
||||||
pattern: keyword
|
pattern: keyword
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
deferreds.push(self._addDisabledPushRule('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