From a3d39c1a68cecb2e7347960c5a9e89569b773d50 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Fri, 28 Apr 2017 12:41:34 -0300 Subject: [PATCH 1/3] Sends pushes only when a deviceToken is set This is intended to solve a bug where some push notifications stuck in sending state --- spec/PushController.spec.js | 35 +++++++++++++++++++++++++++++++ src/Controllers/PushController.js | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/spec/PushController.spec.js b/spec/PushController.spec.js index 1eb1607daf..a1ec8dfb7e 100644 --- a/spec/PushController.spec.js +++ b/spec/PushController.spec.js @@ -657,4 +657,39 @@ describe('PushController', () => { done(); }); }); + + it('sends push only when a deviceToken is set', (done) => { + var config = new Config(Parse.applicationId); + var auth = { + isMaster: true + } + var pushAdapter = { + send: function(body, installations) { + return successfulTransmissions(body, installations); + }, + getValidPushTypes: function() { + return ["ios", "android"]; + } + } + + var pushController = new PushController(); + const payload = { + data: { + alert: 'hello', + }, + push_time: new Date().getTime() + } + + var pushController = new PushController(); + reconfigureServer({ + push: { adapter: pushAdapter } + }).then(() => { + return pushController.sendPush(payload, {}, config, auth); + }).then(() => { + done(); + }, (err) => { + jfail(err); + done(); + }); + }); }); diff --git a/src/Controllers/PushController.js b/src/Controllers/PushController.js index 4e25b7ad52..eb5a707067 100644 --- a/src/Controllers/PushController.js +++ b/src/Controllers/PushController.js @@ -15,6 +15,11 @@ export class PushController { // Replace the expiration_time and push_time with a valid Unix epoch milliseconds time body.expiration_time = PushController.getExpirationTime(body); body.push_time = PushController.getPushTime(body); + // Intend to allow pushes only to valid installations + var hasDeviceToken = where.hasOwnProperty('deviceToken'); + if (!hasDeviceToken) { + where["deviceToken"] = {"$exists":true}; + } // TODO: If the req can pass the checking, we return immediately instead of waiting // pushes to be sent. We probably change this behaviour in the future. let badgeUpdate = () => { From c8358b851bd11ed5add56784c24657838e503215 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Sat, 29 Apr 2017 06:18:26 -0300 Subject: [PATCH 2/3] Fix an already defined instance variable --- spec/PushController.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/PushController.spec.js b/spec/PushController.spec.js index a1ec8dfb7e..e8956ee0d9 100644 --- a/spec/PushController.spec.js +++ b/spec/PushController.spec.js @@ -680,7 +680,6 @@ describe('PushController', () => { push_time: new Date().getTime() } - var pushController = new PushController(); reconfigureServer({ push: { adapter: pushAdapter } }).then(() => { From d5315dbef476ef2ef857cc29214ece75fd6bda10 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Sun, 30 Apr 2017 12:47:42 -0300 Subject: [PATCH 3/3] Update CONTRIBUTING.md Includes info for running parse-server on master --- CONTRIBUTING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3e0d81de39..c29e98ea45 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,23 @@ We really want Parse to be yours, to see it grow and thrive in the open source community. +##### Parse-server running on master + +Get started by cloning the [parser-server-example](https://github.com/parse-community/parse-server-example) repository and running `npm install` inside it. Update `parse-clients-config.json` inside the repo. + +Then add parse-server from master branch as a submodule + +``` +git submodule add https://github.com/parse-community/parse-server + +``` + +Now link parse-server to use the repo instead of the package + +``` +npm link parse-server ./parse-server +``` + ##### Please Do's * Take testing seriously! Aim to increase the test coverage with every pull request.