PushRules settings: if a newly typed keyword was part of a push rule not managed by the Vector UI, delete the rule and create it compliant with Vector parameters

This commit is contained in:
manuroe 2016-01-13 12:00:04 +01:00
parent 1c03c208e1
commit e5b7a47fee
1 changed files with 29 additions and 14 deletions

View File

@ -167,7 +167,7 @@ module.exports = React.createClass({
if (should_leave && self.newKeywords) { if (should_leave && self.newKeywords) {
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
var deferreds = []; var removeDeferreds = [];
var newKeywords = self.newKeywords.split(','); var newKeywords = self.newKeywords.split(',');
for (var i in newKeywords) { for (var i in newKeywords) {
@ -185,11 +185,31 @@ module.exports = React.createClass({
vectorContentRulesPatterns.push(rule.pattern); vectorContentRulesPatterns.push(rule.pattern);
if (-1 === newKeywords.indexOf(rule.pattern)) { if (-1 === newKeywords.indexOf(rule.pattern)) {
deferreds.push(cli.deletePushRule('global', rule.kind, rule.rule_id)); removeDeferreds.push(cli.deletePushRule('global', rule.kind, rule.rule_id));
} }
} }
// Add the new ones // If the keyword is part of `externalContentRules`, remove the rule
// before recreating it in the right Vector path
for (var i in self.state.externalContentRules) {
var rule = self.state.externalContentRules[i];
if (-1 !== newKeywords.indexOf(rule.pattern)) {
removeDeferreds.push(cli.deletePushRule('global', rule.kind, rule.rule_id));
}
}
var onError = function(error) {
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Can't update keywords",
description: error.toString()
});
}
// Then, add the new ones
q.all(removeDeferreds).done(function(resps) {
var deferreds = [];
for (var i in newKeywords) { for (var i in newKeywords) {
var keyword = newKeywords[i]; var keyword = newKeywords[i];
@ -203,13 +223,8 @@ module.exports = React.createClass({
q.all(deferreds).done(function(resps) { q.all(deferreds).done(function(resps) {
self._refreshFromServer(); self._refreshFromServer();
}, function(error) { }, onError);
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); }, onError);
Modal.createDialog(ErrorDialog, {
title: "Can't update keywords",
description: error.toString()
});
});
} }
} }
}); });