Added notif settings for "Messages sent by bot" (https://github.com/vector-im/vector-web/issues/692)

In order to do that, the rules definitions have been update to support "dont_notify" hs default push rules
pull/716/head
manuroe 2016-01-21 16:16:44 +01:00
parent 1a248c8e5c
commit 029cf754ee
1 changed files with 118 additions and 39 deletions

View File

@ -54,8 +54,7 @@ var VectorPushRulesDefinitions = {
conditions: [{ conditions: [{
"kind": "contains_display_name" "kind": "contains_display_name"
}], }],
hsDefaultRuleVectorState: PushRuleVectorState.LOUD, vectorStateToActions: { // The actions for each vector state
vectorStateToActions: {
on: [ on: [
"notify" "notify"
], ],
@ -69,7 +68,12 @@ var VectorPushRulesDefinitions = {
"set_tweak":"highlight" "set_tweak":"highlight"
} }
] ]
} },
vectorStateToHsDefaultRuleEnabled: { // If it exists, the hs default push rule enabled expected value for each vector state
on: undefined, // ON (and its actions) does not corresponds to the default hs push rule, so NA
loud: true, // LOUD corresponds to the default rule when its enabled value is true
off: false // OFF corresponds to the default rule when its enabled value is false
},
}, },
// Messages just sent to the user in a 1:1 room // Messages just sent to the user in a 1:1 room
@ -80,7 +84,6 @@ var VectorPushRulesDefinitions = {
"is": "2", "is": "2",
"kind": "room_member_count" "kind": "room_member_count"
}], }],
hsDefaultRuleVectorState: PushRuleVectorState.LOUD,
vectorStateToActions: { vectorStateToActions: {
on: [ on: [
"notify" "notify"
@ -92,6 +95,11 @@ var VectorPushRulesDefinitions = {
"value": "default" "value": "default"
} }
] ]
},
vectorStateToHsDefaultRuleEnabled: {
on: undefined,
loud: true,
off: false
} }
}, },
@ -103,7 +111,6 @@ var VectorPushRulesDefinitions = {
"kind": "room_member_count" "kind": "room_member_count"
}], }],
hsDefaultRuleId: undefined, // Matrix does not define a default hs push rule for group hsDefaultRuleId: undefined, // Matrix does not define a default hs push rule for group
hsDefaultRuleVectorState: PushRuleVectorState.on,
vectorStateToActions: { vectorStateToActions: {
on: [ on: [
"notify" "notify"
@ -115,6 +122,11 @@ var VectorPushRulesDefinitions = {
"value": "default" "value": "default"
} }
] ]
},
vectorStateToHsDefaultRuleEnabled: {
on: true,
loud: undefined,
off: false
} }
}, },
@ -139,7 +151,6 @@ var VectorPushRulesDefinitions = {
"pattern": "" // It is updated at runtime the user id "pattern": "" // It is updated at runtime the user id
} }
], ],
hsDefaultRuleVectorState: PushRuleVectorState.LOUD,
vectorStateToActions: { vectorStateToActions: {
on: [ on: [
"notify" "notify"
@ -151,11 +162,16 @@ var VectorPushRulesDefinitions = {
"value": "default" "value": "default"
} }
] ]
},
vectorStateToHsDefaultRuleEnabled: {
on: undefined,
loud: true,
off: false
} }
}, },
// When people join or leave a room // When people join or leave a room
/*"im.vector.rule.member_event": { "im.vector.rule.member_event": {
hsDefaultRuleId: ".m.rule.member_event", hsDefaultRuleId: ".m.rule.member_event",
description: "When people join or leave a room", description: "When people join or leave a room",
conditions: [{ conditions: [{
@ -163,7 +179,6 @@ var VectorPushRulesDefinitions = {
"kind": "event_match", "kind": "event_match",
"key": "type" "key": "type"
}], }],
hsDefaultRuleVectorState: PushRuleVectorState.ON,
vectorStateToActions: { vectorStateToActions: {
on: [ on: [
"notify" "notify"
@ -175,8 +190,13 @@ var VectorPushRulesDefinitions = {
"value": "default" "value": "default"
} }
] ]
},
vectorStateToHsDefaultRuleEnabled: {
on: true,
loud: undefined,
off: false
} }
},*/ },
// Incoming call // Incoming call
"im.vector.rule.call": { "im.vector.rule.call": {
@ -187,7 +207,6 @@ var VectorPushRulesDefinitions = {
"kind": "event_match", "kind": "event_match",
"key": "type" "key": "type"
}], }],
hsDefaultRuleVectorState: PushRuleVectorState.LOUD,
vectorStateToActions: { vectorStateToActions: {
on: [ on: [
"notify" "notify"
@ -198,9 +217,43 @@ var VectorPushRulesDefinitions = {
"set_tweak": "sound", "set_tweak": "sound",
"value": "ring" "value": "ring"
} }
] ],
},
vectorStateToHsDefaultRuleEnabled: {
on: undefined,
loud: true,
off: false
} }
}, },
// Notifications from bots
"im.vector.rule.notices": {
hsDefaultRuleId: ".m.rule.suppress_notices",
description: "Messages sent by bot",
conditions: [{
"kind": "event_match",
"key": "content.msgtype",
"pattern": "m.notice"
}],
vectorStateToActions: {
on: undefined, // ON for vector UI means that the .m.rule.suppress_notices rule is disabled.
loud: [
"notify",
{
"set_tweak": "sound",
"value": "ring"
}
],
off: [
"dont_notify"
]
},
vectorStateToHsDefaultRuleEnabled: {
on: false, // .m.rule.suppress_notices is a "negative" rule, we have to invert its enabled value for vector UI
loud: undefined,
off: true
}
}
}; };
module.exports = React.createClass({ module.exports = React.createClass({
@ -369,28 +422,26 @@ module.exports = React.createClass({
var ruleDefinition = VectorPushRulesDefinitions[rule.vectorRuleId]; var ruleDefinition = VectorPushRulesDefinitions[rule.vectorRuleId];
if (rule.rule) { if (rule.rule) {
if (newPushRuleVectorState === PushRuleVectorState.OFF) { if (undefined !== ruleDefinition.vectorStateToHsDefaultRuleEnabled[newPushRuleVectorState] && rule.hsDefaultRule) {
// The new state corresponds to the default hs rule
// Enable or disable it according to the rule definition
deferreds.push(cli.setPushRuleEnabled('global', rule.hsDefaultRule.kind, ruleDefinition.hsDefaultRuleId,
ruleDefinition.vectorStateToHsDefaultRuleEnabled[newPushRuleVectorState]));
// Remove the vector rule if any // Remove the vector rule if any
if (!rule.isHSDefaultRule) { if (!rule.isHSDefaultRule) {
deferreds.push(cli.deletePushRule('global', rule.rule.kind, rule.rule.rule_id)) deferreds.push(cli.deletePushRule('global', rule.rule.kind, rule.rule.rule_id))
} }
// And disable the hs default rule
deferreds.push(cli.setPushRuleEnabled('global', 'underride', ruleDefinition.hsDefaultRuleId, false));
} }
else { else {
// The new state (and its implied actions) does not correspond to a default hs rule
// or the HS does not expose this default rule.
if (rule.isHSDefaultRule) { if (rule.isHSDefaultRule) {
// If the new state corresponds to the hs default rule actions, enable it // Create a new rule that will override the default one
// Else create a new rule that will override it
if (newPushRuleVectorState === ruleDefinition.hsDefaultRuleVectorState) {
deferreds.push(cli.setPushRuleEnabled('global', rule.rule.kind, rule.rule.rule_id, true));
}
else {
deferreds.push(this._addOverridingVectorPushRule(rule.vectorRuleId, newPushRuleVectorState)); deferreds.push(this._addOverridingVectorPushRule(rule.vectorRuleId, newPushRuleVectorState));
} }
}
else { else {
// Change the actions of the overriding Vector rule // Change the actions of the existing overriding Vector rule
deferreds.push(this._updatePushRuleActions(rule.rule, ruleDefinition.vectorStateToActions[newPushRuleVectorState])); deferreds.push(this._updatePushRuleActions(rule.rule, ruleDefinition.vectorStateToActions[newPushRuleVectorState]));
} }
} }
@ -614,8 +665,9 @@ module.exports = React.createClass({
'.m.rule.contains_display_name': 'vector', '.m.rule.contains_display_name': 'vector',
'.m.rule.room_one_to_one': 'vector', '.m.rule.room_one_to_one': 'vector',
'.m.rule.invite_for_me': 'vector', '.m.rule.invite_for_me': 'vector',
//'.m.rule.member_event': 'vector', '.m.rule.member_event': 'vector',
'.m.rule.call': 'vector' '.m.rule.call': 'vector',
'.m.rule.suppress_notices': 'vector'
// Others go to others // Others go to others
}; };
@ -741,8 +793,9 @@ module.exports = React.createClass({
'im.vector.rule.room_one_to_one', 'im.vector.rule.room_one_to_one',
'im.vector.rule.room_group', 'im.vector.rule.room_group',
'im.vector.rule.invite_for_me', 'im.vector.rule.invite_for_me',
//'im.vector.rule.member_event', 'im.vector.rule.member_event',
'im.vector.rule.call' 'im.vector.rule.call',
'im.vector.rule.notices'
]; ];
for (var i in vectorRuleIds) { for (var i in vectorRuleIds) {
var vectorRuleId = vectorRuleIds[i]; var vectorRuleId = vectorRuleIds[i];
@ -767,19 +820,46 @@ module.exports = React.createClass({
isHSDefaultRule = true; isHSDefaultRule = true;
} }
// Translate the rule actions into vector state // Translate the rule actions and its enabled value into vector state
var vectorState = PushRuleVectorState.OFF; var vectorState;
if (rule && rule.enabled) { if (rule) {
if (JSON.stringify(rule.actions) === JSON.stringify(ruleDefinition.vectorStateToActions[PushRuleVectorState.ON])) { for (var stateKey in PushRuleVectorState) {
vectorState = PushRuleVectorState.ON; var state = PushRuleVectorState[stateKey];
var vectorStateToActions = ruleDefinition.vectorStateToActions[state];
if (!vectorStateToActions) {
// No defined actions means that this vector state expects a disabled default hs rule
if (isHSDefaultRule && rule.enabled === ruleDefinition.vectorStateToHsDefaultRuleEnabled[state]) {
vectorState = state;
break;
} }
else if (JSON.stringify(rule.actions) === JSON.stringify(ruleDefinition.vectorStateToActions[PushRuleVectorState.LOUD])) {
vectorState = PushRuleVectorState.LOUD;
} }
else { else {
console.error("Cannot translate rule actionsinto Vector rule state"); // The actions must match to the ones expected by vector state
if (JSON.stringify(rule.actions) === JSON.stringify(vectorStateToActions)) {
if (isHSDefaultRule) {
// In the case of a default hs push rule, the enabled value must also match
if (rule.enabled === ruleDefinition.vectorStateToHsDefaultRuleEnabled[state]) {
vectorState = state;
break;
} }
} }
else {
vectorState = state;
break;
}
}
}
}
if (!vectorState) {
console.error("Cannot translate rule actions into Vector rule state. Rule: " + rule);
vectorState = PushRuleVectorState.OFF;
}
}
else {
vectorState = PushRuleVectorState.OFF;
}
self.state.vectorPushRules.push({ self.state.vectorPushRules.push({
"vectorRuleId": vectorRuleId, "vectorRuleId": vectorRuleId,
@ -794,7 +874,6 @@ module.exports = React.createClass({
// Build the rules not managed by Vector UI // Build the rules not managed by Vector UI
var otherRulesDescriptions = { var otherRulesDescriptions = {
'.m.rule.suppress_notices': "Suppress notifications from bots",
'.m.rule.message': "Notify for all other messages/rooms", '.m.rule.message': "Notify for all other messages/rooms",
'.m.rule.fallback': "Notify me for anything else" '.m.rule.fallback': "Notify me for anything else"
}; };