diff --git a/lib/pushprocessor.js b/lib/pushprocessor.js index 432f39066..0580286f2 100644 --- a/lib/pushprocessor.js +++ b/lib/pushprocessor.js @@ -243,25 +243,11 @@ 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 {}; } - 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) { @@ -285,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} @@ -298,3 +306,4 @@ function PushProcessor(client) { /** The PushProcessor class. */ module.exports = PushProcessor; + 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; }