From 0ba1a1dabc445d429c610f4f6e2ed265fa65f150 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 15 Aug 2016 18:40:12 +0100 Subject: [PATCH 1/3] Update our push rules when they come down stream Also expose a useful function from pushprocessor. Fixes https://github.com/vector-im/vector-web/issues/1495 --- lib/pushprocessor.js | 29 +++++++++++++++-------------- lib/sync.js | 3 +++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/pushprocessor.js b/lib/pushprocessor.js index 432f39066..06bd20fe9 100644 --- a/lib/pushprocessor.js +++ b/lib/pushprocessor.js @@ -17,6 +17,20 @@ limitations under the License. * @module pushprocessor */ +function actionListToActionsObject(actionlist) { + var actionobj = { 'notify': false, 'tweaks': {} }; + for (var i = 0; i < actionlist.length; ++i) { + var action = actionlist[i]; + if (action === 'notify') { + actionobj.notify = true; + } else if (typeof action === 'object') { + if (action.value === undefined) { action.value = true; } + actionobj.tweaks[action.set_tweak] = action.value; + } + } + return actionobj; +}; + /** * Construct a Push Processor. * @constructor @@ -243,20 +257,6 @@ function PushProcessor(client) { return matchingRuleFromKindSet(ev, rulesets.global); }; - var actionListToActionsObject = function(actionlist) { - var actionobj = { 'notify': false, 'tweaks': {} }; - for (var i = 0; i < actionlist.length; ++i) { - var action = actionlist[i]; - if (action === 'notify') { - actionobj.notify = true; - } else if (typeof action === 'object') { - if (action.value === undefined) { action.value = true; } - actionobj.tweaks[action.set_tweak] = action.value; - } - } - return actionobj; - }; - var pushActionsForEventAndRulesets = function(ev, rulesets) { var rule = matchingRuleForEventWithRulesets(ev, rulesets); if (!rule) { return {}; } @@ -298,3 +298,4 @@ function PushProcessor(client) { /** The PushProcessor class. */ module.exports = PushProcessor; +module.exports.actionListToActionsObject = actionListToActionsObject; diff --git a/lib/sync.js b/lib/sync.js index fcc992746..91bb0cc51 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -613,6 +613,9 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) { client.store.storeAccountDataEvents(events); events.forEach( function(accountDataEvent) { + if (accountDataEvent.getType() == 'm.push_rules') { + client.pushRules = accountDataEvent.getContent(); + } client.emit("accountData", accountDataEvent); return accountDataEvent; } From 267e009ae36946066b547909485ec80f6edd23c4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 15 Aug 2016 18:55:09 +0100 Subject: [PATCH 2/3] Make lint pass Although with slightly redundant doc :/ --- lib/pushprocessor.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/pushprocessor.js b/lib/pushprocessor.js index 06bd20fe9..7c6aa69da 100644 --- a/lib/pushprocessor.js +++ b/lib/pushprocessor.js @@ -17,6 +17,14 @@ limitations under the License. * @module pushprocessor */ +/** + * Convert a list of actions into a object with the actions as keys and their values + * eg. [ 'notify', { set_tweak: 'sound', value: 'default' } ] + * becomes { notify: true, tweaks: { sound: 'default' } } + * @param {array} actionlist The actions list + * + * @return {object} A object with key 'notify' (true or false) and an object of actions + */ function actionListToActionsObject(actionlist) { var actionobj = { 'notify': false, 'tweaks': {} }; for (var i = 0; i < actionlist.length; ++i) { @@ -29,7 +37,7 @@ function actionListToActionsObject(actionlist) { } } return actionobj; -}; +} /** * Construct a Push Processor. @@ -298,4 +306,11 @@ function PushProcessor(client) { /** The PushProcessor class. */ module.exports = PushProcessor; + +/** + * See above + * @param {array} actionlist The actions list + * + * @return {object} See above + */ module.exports.actionListToActionsObject = actionListToActionsObject; From cc72d35c6b175ef030eb777cbea1a4f77ba3b881 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 16 Aug 2016 17:02:18 +0100 Subject: [PATCH 3/3] Move definition So we don't have to fudge the jsdoc to make the linter happy --- lib/pushprocessor.js | 53 +++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/lib/pushprocessor.js b/lib/pushprocessor.js index 7c6aa69da..0580286f2 100644 --- a/lib/pushprocessor.js +++ b/lib/pushprocessor.js @@ -17,28 +17,6 @@ limitations under the License. * @module pushprocessor */ -/** - * Convert a list of actions into a object with the actions as keys and their values - * eg. [ 'notify', { set_tweak: 'sound', value: 'default' } ] - * becomes { notify: true, tweaks: { sound: 'default' } } - * @param {array} actionlist The actions list - * - * @return {object} A object with key 'notify' (true or false) and an object of actions - */ -function actionListToActionsObject(actionlist) { - var actionobj = { 'notify': false, 'tweaks': {} }; - for (var i = 0; i < actionlist.length; ++i) { - var action = actionlist[i]; - if (action === 'notify') { - actionobj.notify = true; - } else if (typeof action === 'object') { - if (action.value === undefined) { action.value = true; } - actionobj.tweaks[action.set_tweak] = action.value; - } - } - return actionobj; -} - /** * Construct a Push Processor. * @constructor @@ -269,7 +247,7 @@ function PushProcessor(client) { var rule = matchingRuleForEventWithRulesets(ev, rulesets); if (!rule) { return {}; } - var actionObj = actionListToActionsObject(rule.actions); + var actionObj = PushProcessor.actionListToActionsObject(rule.actions); // Some actions are implicit in some situations: we add those here if (actionObj.tweaks.highlight === undefined) { @@ -293,6 +271,28 @@ function PushProcessor(client) { }; } +/** + * Convert a list of actions into a object with the actions as keys and their values + * eg. [ 'notify', { set_tweak: 'sound', value: 'default' } ] + * becomes { notify: true, tweaks: { sound: 'default' } } + * @param {array} actionlist The actions list + * + * @return {object} A object with key 'notify' (true or false) and an object of actions + */ +PushProcessor.actionListToActionsObject = function(actionlist) { + var actionobj = { 'notify': false, 'tweaks': {} }; + for (var i = 0; i < actionlist.length; ++i) { + var action = actionlist[i]; + if (action === 'notify') { + actionobj.notify = true; + } else if (typeof action === 'object') { + if (action.value === undefined) { action.value = true; } + actionobj.tweaks[action.set_tweak] = action.value; + } + } + return actionobj; +}; + /** * @typedef {Object} PushAction * @type {Object} @@ -307,10 +307,3 @@ function PushProcessor(client) { /** The PushProcessor class. */ module.exports = PushProcessor; -/** - * See above - * @param {array} actionlist The actions list - * - * @return {object} See above - */ -module.exports.actionListToActionsObject = actionListToActionsObject;