Improve parsing of keyword notification rules

For notification rules, the absence of a value on a 'highlight' tweak means
that the highlight should happen; this was previously confusing us.

Use the action parser from NotificationUtils to simplify the code.

Fixes https://github.com/vector-im/vector-web/issues/1330
This commit is contained in:
Richard van der Hoff 2016-04-14 22:45:00 +01:00
parent 5450223cc7
commit 121fe34180
3 changed files with 163 additions and 9 deletions

View file

@ -17,6 +17,7 @@ limitations under the License.
'use strict';
var StandardActions = require('./StandardActions');
var NotificationUtils = require('./NotificationUtils');
var states = {
/** The push rule is disabled */
@ -58,20 +59,24 @@ module.exports = {
*
* Determines whether a content rule is in the PushRuleVectorState.ON
* category or in PushRuleVectorState.LOUD, regardless of its enabled
* state. Returns undefined if it does not match these categories.
* state. Returns null if it does not match these categories.
*/
contentRuleVectorStateKind: function(rule) {
var stateKind;
var decoded = NotificationUtils.decodeActions(rule.actions);
if (!decoded) {
return null;
}
// Count tweaks to determine if it is a ON or LOUD rule
var tweaks = 0;
for (var j in rule.actions) {
var action = rule.actions[j];
if (action.set_tweak === 'sound' ||
(action.set_tweak === 'highlight' && action.value)) {
tweaks++;
}
if (decoded.sound) {
tweaks++;
}
if (decoded.highlight) {
tweaks++;
}
var stateKind = null;
switch (tweaks) {
case 0:
stateKind = this.ON;