From 5c59a2ea3e48a60f7354fb0b03aebb7a890316ec Mon Sep 17 00:00:00 2001 From: manuroe Date: Mon, 11 Jan 2016 17:00:05 +0100 Subject: [PATCH] Fixed MatrixClient pushRules method and ivar clash. Added MatrixClient.setPushRuleEnabled method. --- lib/client.js | 20 +++++++++++++++++++- lib/sync.js | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index afd652f47..71f38c26b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2180,7 +2180,7 @@ MatrixClient.prototype.loginWithToken = function(token, callback) { * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype.pushRules = function(callback) { +MatrixClient.prototype.getPushRules = function(callback) { return this._http.authedRequest(callback, "GET", "/pushrules/"); }; @@ -2221,6 +2221,24 @@ MatrixClient.prototype.deletePushRule = function(scope, kind, ruleId, callback) return this._http.authedRequest(callback, "DELETE", path); }; +/** + * Enable or disable a push notification rule. + * @param {string} scope + * @param {string} kind + * @param {string} ruleId + * @param {boolean} enabled + * @param {module:client.callback} callback Optional. + * @return {module:client.Promise} Resolves: result object + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixClient.prototype.setPushRuleEnabled = function(scope, kind, ruleId, enabled, callback) { + var path = utils.encodeUri("/pushrules/" + scope + "/$kind/$ruleId/enabled", { + $kind: kind, + $ruleId: ruleId + }); + return this._http.authedRequest(callback, "PUT", path, undefined, enabled ? 'true' : 'false'); +}; + /** * Perform a server-side search for messages containing the given text. * @param {Object} opts Options for the search. diff --git a/lib/sync.js b/lib/sync.js index 545197b2d..4381582ec 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -267,7 +267,7 @@ SyncApi.prototype.sync = function() { attempt = attempt || 0; attempt += 1; - client.pushRules().done(function(result) { + client.getPushRules().done(function(result) { console.log("Got push rules"); client.pushRules = result; getFilter(); // Now get the filter