PushRules settings: update keywords list hs side
parent
10d3076d6b
commit
1c03c208e1
|
@ -59,6 +59,7 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
keywordsDialogDiv: "",
|
keywordsDialogDiv: "",
|
||||||
|
newKeywords: undefined,
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this._refreshFromServer();
|
this._refreshFromServer();
|
||||||
|
@ -92,7 +93,7 @@ module.exports = React.createClass({
|
||||||
switch (newPushRuleState) {
|
switch (newPushRuleState) {
|
||||||
case PushRuleState.ON:
|
case PushRuleState.ON:
|
||||||
if (rule.actions.length !== 1) {
|
if (rule.actions.length !== 1) {
|
||||||
actions = ['notify'];
|
actions = this._actionsFor(PushRuleState.ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.vectorContentRules.state === PushRuleState.OFF) {
|
if (this.state.vectorContentRules.state === PushRuleState.OFF) {
|
||||||
|
@ -102,10 +103,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
case PushRuleState.STRONG:
|
case PushRuleState.STRONG:
|
||||||
if (rule.actions.length !== 3) {
|
if (rule.actions.length !== 3) {
|
||||||
actions = ['notify',
|
actions = this._actionsFor(PushRuleState.STRONG);
|
||||||
{'set_tweak': 'sound', 'value': 'default'},
|
|
||||||
{'set_tweak': 'highlight', 'value': 'true'}
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.vectorContentRules.state === PushRuleState.OFF) {
|
if (this.state.vectorContentRules.state === PushRuleState.OFF) {
|
||||||
|
@ -158,13 +156,60 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onKeywordsClicked: function(event) {
|
onKeywordsClicked: function(event) {
|
||||||
|
var self = this;
|
||||||
|
this.newKeywords = undefined;
|
||||||
|
|
||||||
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
||||||
Modal.createDialog(QuestionDialog, {
|
Modal.createDialog(QuestionDialog, {
|
||||||
title: "Keywords",
|
title: "Keywords",
|
||||||
description: this.keywordsDialogDiv,
|
description: this.keywordsDialogDiv,
|
||||||
onFinished: function onFinished(should_leave) {
|
onFinished: function onFinished(should_leave) {
|
||||||
if (should_leave) {
|
|
||||||
// TODO
|
if (should_leave && self.newKeywords) {
|
||||||
|
var cli = MatrixClientPeg.get();
|
||||||
|
var deferreds = [];
|
||||||
|
|
||||||
|
var newKeywords = self.newKeywords.split(',');
|
||||||
|
for (var i in newKeywords) {
|
||||||
|
newKeywords[i] = newKeywords[i].trim();
|
||||||
|
}
|
||||||
|
self.setState({
|
||||||
|
phase: self.phases.LOADING
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove per-word push rules of keywords that are no more in the list
|
||||||
|
var vectorContentRulesPatterns = [];
|
||||||
|
for (var i in self.state.vectorContentRules.rules) {
|
||||||
|
var rule = self.state.vectorContentRules.rules[i];
|
||||||
|
|
||||||
|
vectorContentRulesPatterns.push(rule.pattern);
|
||||||
|
|
||||||
|
if (-1 === newKeywords.indexOf(rule.pattern)) {
|
||||||
|
deferreds.push(cli.deletePushRule('global', rule.kind, rule.rule_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the new ones
|
||||||
|
for (var i in newKeywords) {
|
||||||
|
var keyword = newKeywords[i];
|
||||||
|
|
||||||
|
if (-1 === vectorContentRulesPatterns.indexOf(keyword)) {
|
||||||
|
deferreds.push(cli.addPushRule('global', 'content', keyword, {
|
||||||
|
actions: self._actionsFor(self.state.vectorContentRules.state),
|
||||||
|
pattern: keyword
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
q.all(deferreds).done(function(resps) {
|
||||||
|
self._refreshFromServer();
|
||||||
|
}, function(error) {
|
||||||
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
|
Modal.createDialog(ErrorDialog, {
|
||||||
|
title: "Can't update keywords",
|
||||||
|
description: error.toString()
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -178,6 +223,18 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_actionsFor: function(pushRuleState) {
|
||||||
|
if (pushRuleState === PushRuleState.ON) {
|
||||||
|
return ['notify'];
|
||||||
|
}
|
||||||
|
else if (pushRuleState === PushRuleState.STRONG) {
|
||||||
|
return ['notify',
|
||||||
|
{'set_tweak': 'sound', 'value': 'default'},
|
||||||
|
{'set_tweak': 'highlight', 'value': 'true'}
|
||||||
|
];;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_refreshFromServer: function() {
|
_refreshFromServer: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -441,6 +498,8 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (this.state.phase === this.phases.LOADING) {
|
if (this.state.phase === this.phases.LOADING) {
|
||||||
var Loader = sdk.getComponent("elements.Spinner");
|
var Loader = sdk.getComponent("elements.Spinner");
|
||||||
return (
|
return (
|
||||||
|
@ -465,13 +524,17 @@ module.exports = React.createClass({
|
||||||
keywords = "";
|
keywords = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var onKeywordsChange = function(e) {
|
||||||
|
self.newKeywords = e.target.value;
|
||||||
|
};
|
||||||
|
|
||||||
this.keywordsDialogDiv = (
|
this.keywordsDialogDiv = (
|
||||||
<div>
|
<div>
|
||||||
<div className="mx_UserNotifSettings_keywordsLabel">
|
<div className="mx_UserNotifSettings_keywordsLabel">
|
||||||
<label htmlFor="keywords">Enter keywords separated by a comma:</label>
|
<label htmlFor="keywords">Enter keywords separated by a comma:</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input id="keywords" ref="keywords" className="mx_UserNotifSettings_keywordsInput" defaultValue={keywords} autoFocus={true} size="64"/>
|
<input id="keywords" ref="keywords" className="mx_UserNotifSettings_keywordsInput" defaultValue={keywords} autoFocus={true} size="64" onChange={onKeywordsChange}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue