Expose hidden notification rules in UI

Adds UI control for 3 hidden notification rules:

* Messages containing @room
* Encrypted one-to-one messages
* Encrypted group messages

This should help to clarify some mysterious notification behavior, as it wasn't
obvious that these rules existed.

Fixes vector-im/riot-web#7833.

Signed-off-by: J. Ryan Stinnett <jryans@gmail.com>
This commit is contained in:
J. Ryan Stinnett 2018-12-11 19:01:27 +00:00
parent ab6566980f
commit 04c30181c6
4 changed files with 57 additions and 7 deletions

View file

@ -483,8 +483,11 @@ module.exports = React.createClass({
// The default push rules displayed by Vector UI // The default push rules displayed by Vector UI
'.m.rule.contains_display_name': 'vector', '.m.rule.contains_display_name': 'vector',
'.m.rule.contains_user_name': 'vector', '.m.rule.contains_user_name': 'vector',
'.m.rule.roomnotif': 'vector',
'.m.rule.room_one_to_one': 'vector', '.m.rule.room_one_to_one': 'vector',
'.m.rule.encrypted_room_one_to_one': 'vector',
'.m.rule.message': 'vector', '.m.rule.message': 'vector',
'.m.rule.encrypted': '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',
@ -534,9 +537,12 @@ module.exports = React.createClass({
const vectorRuleIds = [ const vectorRuleIds = [
'.m.rule.contains_display_name', '.m.rule.contains_display_name',
'.m.rule.contains_user_name', '.m.rule.contains_user_name',
'.m.rule.roomnotif',
'_keywords', '_keywords',
'.m.rule.room_one_to_one', '.m.rule.room_one_to_one',
'.m.rule.encrypted_room_one_to_one',
'.m.rule.message', '.m.rule.message',
'.m.rule.encrypted',
'.m.rule.invite_for_me', '.m.rule.invite_for_me',
//'im.vector.rule.member_event', //'im.vector.rule.member_event',
'.m.rule.call', '.m.rule.call',

View file

@ -295,8 +295,11 @@
"Waiting for response from server": "Waiting for response from server", "Waiting for response from server": "Waiting for response from server",
"Messages containing my display name": "Messages containing my display name", "Messages containing my display name": "Messages containing my display name",
"Messages containing my user name": "Messages containing my user name", "Messages containing my user name": "Messages containing my user name",
"Messages containing @room": "Messages containing @room",
"Messages in one-to-one chats": "Messages in one-to-one chats", "Messages in one-to-one chats": "Messages in one-to-one chats",
"Encrypted messages in one-to-one chats": "Encrypted messages in one-to-one chats",
"Messages in group chats": "Messages in group chats", "Messages in group chats": "Messages in group chats",
"Encrypted messages in group chats": "Encrypted messages in group chats",
"When I'm invited to a room": "When I'm invited to a room", "When I'm invited to a room": "When I'm invited to a room",
"Call invitation": "Call invitation", "Call invitation": "Call invitation",
"Messages sent by bot": "Messages sent by bot", "Messages sent by bot": "Messages sent by bot",

View file

@ -24,6 +24,7 @@ module.exports = {
ACTION_NOTIFY: encodeActions({notify: true}), ACTION_NOTIFY: encodeActions({notify: true}),
ACTION_NOTIFY_DEFAULT_SOUND: encodeActions({notify: true, sound: "default"}), ACTION_NOTIFY_DEFAULT_SOUND: encodeActions({notify: true, sound: "default"}),
ACTION_NOTIFY_RING_SOUND: encodeActions({notify: true, sound: "ring"}), ACTION_NOTIFY_RING_SOUND: encodeActions({notify: true, sound: "ring"}),
ACTION_HIGHLIGHT: encodeActions({notify: true, highlight: true}),
ACTION_HIGHLIGHT_DEFAULT_SOUND: encodeActions({notify: true, sound: "default", highlight: true}), ACTION_HIGHLIGHT_DEFAULT_SOUND: encodeActions({notify: true, sound: "default", highlight: true}),
ACTION_DONT_NOTIFY: encodeActions({notify: false}), ACTION_DONT_NOTIFY: encodeActions({notify: false}),
ACTION_DISABLED: null, ACTION_DISABLED: null,

View file

@ -20,6 +20,7 @@ import { _td } from '../languageHandler';
const StandardActions = require('./StandardActions'); const StandardActions = require('./StandardActions');
const PushRuleVectorState = require('./PushRuleVectorState'); const PushRuleVectorState = require('./PushRuleVectorState');
const { decodeActions } = require('./NotificationUtils');
class VectorPushRuleDefinition { class VectorPushRuleDefinition {
constructor(opts) { constructor(opts) {
@ -31,13 +32,11 @@ class VectorPushRuleDefinition {
// Translate the rule actions and its enabled value into vector state // Translate the rule actions and its enabled value into vector state
ruleToVectorState(rule) { ruleToVectorState(rule) {
let enabled = false; let enabled = false;
let actions = null;
if (rule) { if (rule) {
enabled = rule.enabled; enabled = rule.enabled;
actions = rule.actions;
} }
for (const stateKey in PushRuleVectorState.states) { for (const stateKey in PushRuleVectorState.states) { // eslint-disable-line guard-for-in
const state = PushRuleVectorState.states[stateKey]; const state = PushRuleVectorState.states[stateKey];
const vectorStateToActions = this.vectorStateToActions[state]; const vectorStateToActions = this.vectorStateToActions[state];
@ -47,15 +46,21 @@ class VectorPushRuleDefinition {
return state; return state;
} }
} else { } else {
// The actions must match to the ones expected by vector state // The actions must match to the ones expected by vector state.
if (enabled && JSON.stringify(rule.actions) === JSON.stringify(vectorStateToActions)) { // Use `decodeActions` on both sides to canonicalize things like
// value: true vs. unspecified for highlight (which defaults to
// true, making them equivalent.
if (enabled &&
JSON.stringify(decodeActions(rule.actions)) ===
JSON.stringify(decodeActions(vectorStateToActions))) {
return state; return state;
} }
} }
} }
console.error("Cannot translate rule actions into Vector rule state. Rule: " + console.error(`Cannot translate rule actions into Vector rule state. ` +
JSON.stringify(rule)); `Rule: ${JSON.stringify(rule)}, ` +
`Expected: ${JSON.stringify(this.vectorStateToActions)}`);
return undefined; return undefined;
} }
} }
@ -86,6 +91,17 @@ module.exports = {
}, },
}), }),
// Messages containing @room
".m.rule.roomnotif": new VectorPushRuleDefinition({
kind: "override",
description: _td("Messages containing @room"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: { // The actions for each vector state, or null to disable the rule.
on: StandardActions.ACTION_NOTIFY,
loud: StandardActions.ACTION_HIGHLIGHT,
off: StandardActions.ACTION_DISABLED,
},
}),
// Messages just sent to the user in a 1:1 room // Messages just sent to the user in a 1:1 room
".m.rule.room_one_to_one": new VectorPushRuleDefinition({ ".m.rule.room_one_to_one": new VectorPushRuleDefinition({
kind: "underride", kind: "underride",
@ -97,6 +113,17 @@ module.exports = {
}, },
}), }),
// Encrypted messages just sent to the user in a 1:1 room
".m.rule.encrypted_room_one_to_one": new VectorPushRuleDefinition({
kind: "underride",
description: _td("Encrypted messages in one-to-one chats"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
on: StandardActions.ACTION_NOTIFY,
loud: StandardActions.ACTION_NOTIFY_DEFAULT_SOUND,
off: StandardActions.ACTION_DONT_NOTIFY,
},
}),
// Messages just sent to a group chat room // Messages just sent to a group chat room
// 1:1 room messages are catched by the .m.rule.room_one_to_one rule if any defined // 1:1 room messages are catched by the .m.rule.room_one_to_one rule if any defined
// By opposition, all other room messages are from group chat rooms. // By opposition, all other room messages are from group chat rooms.
@ -110,6 +137,19 @@ module.exports = {
}, },
}), }),
// Encrypted messages just sent to a group chat room
// Encrypted 1:1 room messages are catched by the .m.rule.encrypted_room_one_to_one rule if any defined
// By opposition, all other room messages are from group chat rooms.
".m.rule.encrypted": new VectorPushRuleDefinition({
kind: "underride",
description: _td("Encrypted messages in group chats"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
on: StandardActions.ACTION_NOTIFY,
loud: StandardActions.ACTION_NOTIFY_DEFAULT_SOUND,
off: StandardActions.ACTION_DONT_NOTIFY,
},
}),
// Invitation for the user // Invitation for the user
".m.rule.invite_for_me": new VectorPushRuleDefinition({ ".m.rule.invite_for_me": new VectorPushRuleDefinition({
kind: "underride", kind: "underride",