Skip to content
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

Full query support for badge Increment (#931) #983

Merged
merged 1 commit into from
Mar 11, 2016
Merged
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
41 changes: 41 additions & 0 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var PushController = require('../src/Controllers/PushController').PushController;

var Config = require('../src/Config');
Expand Down Expand Up @@ -220,5 +221,45 @@ describe('PushController', () => {
});

});

it('should support full RESTQuery for increment', (done) => {
var payload = {data: {
alert: "Hello World!",
badge: 'Increment',
}}

var pushAdapter = {
send: function(body, installations) {
return Promise.resolve();
},
getValidPushTypes: function() {
return ["ios"];
}
}

var config = new Config(Parse.applicationId);
var auth = {
isMaster: true
}

let where = {
'deviceToken': {
'$inQuery': {
'where': {
'deviceType': 'ios'
},
className: '_Installation'
}
}
}

var pushController = new PushController(pushAdapter, Parse.applicationId);
pushController.sendPush(payload, where, config, auth).then((result) => {
done();
}).catch((err) => {
fail('should not fail');
done();
});
});

});
17 changes: 14 additions & 3 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AdaptableController from './AdaptableController';
import { PushAdapter } from '../Adapters/Push/PushAdapter';
import deepcopy from 'deepcopy';
import features from '../features';
import RestQuery from '../RestQuery';

const FEATURE_NAME = 'push';
const UNSUPPORTED_BADGE_KEY = "unsupported";
Expand Down Expand Up @@ -63,11 +64,21 @@ export class PushController extends AdaptableController {
throw "Invalid value for badge, expected number or 'Increment'";
}
let updateWhere = deepcopy(where);
updateWhere.deviceType = 'ios'; // Only on iOS!

badgeUpdate = () => {
return config.database.adaptiveCollection("_Installation")
.then(coll => coll.updateMany(updateWhere, op));
let badgeQuery = new RestQuery(config, auth, '_Installation', updateWhere);
return badgeQuery.buildRestWhere().then(() => {
let restWhere = deepcopy(badgeQuery.restWhere);
// Force iOS only devices
if (!restWhere['$and']) {
restWhere['$and'] = [badgeQuery.restWhere];
}
restWhere['$and'].push({
'deviceType': 'ios'
});
return config.database.adaptiveCollection("_Installation")
.then(coll => coll.updateMany(restWhere, op));
})
}
}

Expand Down
24 changes: 15 additions & 9 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}) {
// 'results' and 'count'.
// TODO: consolidate the replaceX functions
RestQuery.prototype.execute = function() {
return Promise.resolve().then(() => {
return this.buildRestWhere();
}).then(() => {
return this.runFind();
}).then(() => {
return this.runCount();
}).then(() => {
return this.handleInclude();
}).then(() => {
return this.response;
});
};

RestQuery.prototype.buildRestWhere = function() {
return Promise.resolve().then(() => {
return this.getUserAndRoleACL();
}).then(() => {
Expand All @@ -125,16 +139,8 @@ RestQuery.prototype.execute = function() {
return this.replaceInQuery();
}).then(() => {
return this.replaceNotInQuery();
}).then(() => {
return this.runFind();
}).then(() => {
return this.runCount();
}).then(() => {
return this.handleInclude();
}).then(() => {
return this.response;
});
};
}

// Uses the Auth object to get the list of roles, adds the user id
RestQuery.prototype.getUserAndRoleACL = function() {
Expand Down