From 84509087aca78549d6d3489c95d38f3b51132120 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 31 Jul 2019 16:20:54 +0100 Subject: [PATCH 1/7] Prepare changelog for v2.3.0-rc.1 --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b89b762a203..fed892f26ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +Changes in [2.3.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v2.3.0-rc.1) (2019-07-31) +========================================================================================================== +[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v2.2.0...v2.3.0-rc.1) + + * Add support for IS v2 API with authentication + [\#1002](https://github.com/matrix-org/matrix-js-sdk/pull/1002) + * Tombstone bugfixes + [\#1001](https://github.com/matrix-org/matrix-js-sdk/pull/1001) + * Support for MSC2140 (terms of service for IS/IM) + [\#988](https://github.com/matrix-org/matrix-js-sdk/pull/988) + * Add a request method to /devices + [\#994](https://github.com/matrix-org/matrix-js-sdk/pull/994) + Changes in [2.2.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v2.2.0) (2019-07-18) ================================================================================================ [Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v2.2.0-rc.2...v2.2.0) From aa8c2ca277e68cd8e8882ca0bce8eb3e6a99e578 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 31 Jul 2019 16:20:54 +0100 Subject: [PATCH 2/7] v2.3.0-rc.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b8b19d8a1be..108d462caa6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "2.2.0", + "version": "2.3.0-rc.1", "description": "Matrix Client-Server SDK for Javascript", "main": "index.js", "scripts": { From 3b225651cc4b4345a2f6386569b3d17679f957e4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 31 Jul 2019 10:52:44 -0600 Subject: [PATCH 3/7] Support rewriting push rules when our internal defaults change and change our internal default for tombstones --- src/base-apis.js | 5 ++++- src/pushprocessor.js | 31 +++++++++++++++++++++++++++++++ src/sync.js | 6 ++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index 988d3738c54..6a3d59083ac 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -29,6 +29,7 @@ import logger from './logger'; const httpApi = require("./http-api"); const utils = require("./utils"); +const PushProcessor = require("./pushprocessor"); function termsUrlForService(serviceType, baseUrl) { switch (serviceType) { @@ -1477,7 +1478,9 @@ MatrixBaseApis.prototype.setPusher = function(pusher, callback) { * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixBaseApis.prototype.getPushRules = function(callback) { - return this._http.authedRequest(callback, "GET", "/pushrules/"); + return this._http.authedRequest(callback, "GET", "/pushrules/").then(rules => { + return PushProcessor.rewriteDefaultRules(rules); + }); }; /** diff --git a/src/pushprocessor.js b/src/pushprocessor.js index 54202b412a5..0cc915f0cd5 100644 --- a/src/pushprocessor.js +++ b/src/pushprocessor.js @@ -43,6 +43,11 @@ const DEFAULT_OVERRIDE_RULES = [ key: "type", pattern: "m.room.tombstone", }, + { + kind: "event_match", + key: "state_key", + pattern: "", + } ], actions: [ "notify", @@ -455,6 +460,32 @@ PushProcessor.actionListToActionsObject = function(actionlist) { return actionobj; }; +/** + * Rewrites conditions on a client's push rules to match the defaults + * where applicable. Useful for upgrading push rules to more strict + * conditions when the server is falling behind on defaults. + * @param {object} incomingRules The client's existing push rules + * @returns {object} The rewritten rules + */ +PushProcessor.rewriteDefaultRules = function(incomingRules) { + const newRules = JSON.parse(JSON.stringify(incomingRules)); // deep clone + + // Fix default override rules + newRules.global.override = newRules.global.override.map(r => { + const defaultRule = DEFAULT_OVERRIDE_RULES.find(d => d.rule_id === r.rule_id); + if (!defaultRule) return r; + + // Copy over the actions, default, and conditions. Don't touch the user's + // preference. + r.default = defaultRule.default; + r.conditions = defaultRule.conditions; + r.actions = defaultRule.actions; + return r; + }); + + return newRules; +}; + /** * @typedef {Object} PushAction * @type {Object} diff --git a/src/sync.js b/src/sync.js index 12775903e57..765bf73b614 100644 --- a/src/sync.js +++ b/src/sync.js @@ -32,6 +32,7 @@ const Group = require('./models/group'); const utils = require("./utils"); const Filter = require("./filter"); const EventTimeline = require("./models/event-timeline"); +const PushProcessor = require("./pushprocessor"); import logger from '../src/logger'; import {InvalidStoreError} from './errors'; @@ -1030,8 +1031,9 @@ SyncApi.prototype._processSyncResponse = async function( // honour push rules that were previously cached. Base rules // will be updated when we recieve push rules via getPushRules // (see SyncApi.prototype.sync) before syncing over the network. - if (accountDataEvent.getType() == 'm.push_rules') { - client.pushRules = accountDataEvent.getContent(); + if (accountDataEvent.getType() === 'm.push_rules') { + const rules = accountDataEvent.getContent(); + client.pushRules = PushProcessor.rewriteDefaultRules(rules); } client.emit("accountData", accountDataEvent); return accountDataEvent; From a3f1da1981323fa016c28cd7e7454a6c8ccacd2b Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 31 Jul 2019 11:00:38 -0600 Subject: [PATCH 4/7] Appease the linter --- src/pushprocessor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pushprocessor.js b/src/pushprocessor.js index 0cc915f0cd5..550f7178629 100644 --- a/src/pushprocessor.js +++ b/src/pushprocessor.js @@ -47,7 +47,7 @@ const DEFAULT_OVERRIDE_RULES = [ kind: "event_match", key: "state_key", pattern: "", - } + }, ], actions: [ "notify", From 6799c2992134034aea2bedc1be2f6f271f4f5a0a Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 31 Jul 2019 11:00:44 -0600 Subject: [PATCH 5/7] Appease the tests --- src/pushprocessor.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pushprocessor.js b/src/pushprocessor.js index 550f7178629..0cf05cacf0f 100644 --- a/src/pushprocessor.js +++ b/src/pushprocessor.js @@ -468,7 +468,13 @@ PushProcessor.actionListToActionsObject = function(actionlist) { * @returns {object} The rewritten rules */ PushProcessor.rewriteDefaultRules = function(incomingRules) { - const newRules = JSON.parse(JSON.stringify(incomingRules)); // deep clone + let newRules = JSON.parse(JSON.stringify(incomingRules)); // deep clone + + // These lines are mostly to make the tests happy. We shouldn't run into these + // properties missing in practice. + if (!newRules) newRules = {}; + if (!newRules.global) newRules.global = {}; + if (!newRules.global.override) newRules.global.override = []; // Fix default override rules newRules.global.override = newRules.global.override.map(r => { From 87bf07f95ee4d902f5d09cb61e8c99b53b5240a4 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 5 Aug 2019 11:46:46 +0100 Subject: [PATCH 6/7] Prepare changelog for v2.3.0 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fed892f26ea..9eb262d86a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +Changes in [2.3.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v2.3.0) (2019-08-05) +================================================================================================ +[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v2.3.0-rc.1...v2.3.0) + + * [release] Support rewriting push rules when our internal defaults change + [\#1008](https://github.com/matrix-org/matrix-js-sdk/pull/1008) + Changes in [2.3.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v2.3.0-rc.1) (2019-07-31) ========================================================================================================== [Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v2.2.0...v2.3.0-rc.1) From 06adc34fb39159fac9dc05fa6b9cabae741bc9ca Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 5 Aug 2019 11:46:46 +0100 Subject: [PATCH 7/7] v2.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 108d462caa6..aa82c9c5110 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "2.3.0-rc.1", + "version": "2.3.0", "description": "Matrix Client-Server SDK for Javascript", "main": "index.js", "scripts": {