1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-17 21:42:17 +03:00

Merge pull request #170 from matrix-org/dbkr/push_update_rules_expose_func

Update our push rules when they come down stream
This commit is contained in:
Richard van der Hoff
2016-08-16 17:10:14 +01:00
committed by GitHub
2 changed files with 27 additions and 15 deletions

View File

@@ -243,25 +243,11 @@ function PushProcessor(client) {
return matchingRuleFromKindSet(ev, rulesets.global); 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 pushActionsForEventAndRulesets = function(ev, rulesets) {
var rule = matchingRuleForEventWithRulesets(ev, rulesets); var rule = matchingRuleForEventWithRulesets(ev, rulesets);
if (!rule) { return {}; } 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 // Some actions are implicit in some situations: we add those here
if (actionObj.tweaks.highlight === undefined) { 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 * @typedef {Object} PushAction
* @type {Object} * @type {Object}
@@ -298,3 +306,4 @@ function PushProcessor(client) {
/** The PushProcessor class. */ /** The PushProcessor class. */
module.exports = PushProcessor; module.exports = PushProcessor;

View File

@@ -613,6 +613,9 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
client.store.storeAccountDataEvents(events); client.store.storeAccountDataEvents(events);
events.forEach( events.forEach(
function(accountDataEvent) { function(accountDataEvent) {
if (accountDataEvent.getType() == 'm.push_rules') {
client.pushRules = accountDataEvent.getContent();
}
client.emit("accountData", accountDataEvent); client.emit("accountData", accountDataEvent);
return accountDataEvent; return accountDataEvent;
} }