Skip to content

Sends pushes only when a deviceToken is set #3764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 34 additions & 0 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,38 @@ 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()
}

reconfigureServer({
push: { adapter: pushAdapter }
}).then(() => {
return pushController.sendPush(payload, {}, config, auth);
}).then(() => {
done();
}, (err) => {
jfail(err);
done();
});
});
});
5 changes: 5 additions & 0 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down