Skip to content

Lets increment/set badges on all _Installations #3970

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

Merged
merged 2 commits into from
Jul 3, 2017
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
19 changes: 6 additions & 13 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,8 @@ describe('PushController', () => {
send: function(body, installations) {
var badge = body.data.badge;
installations.forEach((installation) => {
if (installation.deviceType == "ios") {
expect(installation.badge).toEqual(badge);
expect(installation.originalBadge + 1).toEqual(installation.badge);
} else {
expect(installation.badge).toBeUndefined();
}
expect(installation.badge).toEqual(badge);
expect(installation.originalBadge + 1).toEqual(installation.badge);
})
return successfulTransmissions(body, installations);
},
Expand All @@ -203,7 +199,9 @@ describe('PushController', () => {
while(installations.length != 15) {
const installation = new Parse.Object("_Installation");
installation.set("installationId", "installation_" + installations.length);
installation.set("deviceToken","device_token_" + installations.length)
installation.set("deviceToken","device_token_" + installations.length);
installation.set("badge", installations.length);
installation.set("originalBadge", installations.length);
installation.set("deviceType", "android");
installations.push(installation);
}
Expand Down Expand Up @@ -238,12 +236,7 @@ describe('PushController', () => {
expect(results.length).toBe(15);
for (var i = 0; i < 15; i++) {
const installation = results[i];
if (installation.get('deviceType') == 'ios') {
expect(installation.get('badge')).toBe(parseInt(installation.get('originalBadge')) + 1);
} else {
expect(installation.get('badge')).toBe(undefined);
expect(installation.get('originalBadge')).toBe(undefined);
}
expect(installation.get('badge')).toBe(parseInt(installation.get('originalBadge')) + 1);
}
done()
}).catch((err) => {
Expand Down
3 changes: 2 additions & 1 deletion src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,8 @@ export class PostgresStorageAdapter {
const where = buildWhereClause({ schema, index, query })
values.push(...where.values);

const qs = `UPDATE $1:name SET ${updatePatterns.join(',')} WHERE ${where.pattern} RETURNING *`;
const whereClause = where.pattern.length > 0 ? `WHERE ${where.pattern}` : '';
const qs = `UPDATE $1:name SET ${updatePatterns.join(',')} ${whereClause} RETURNING *`;
debug('update: ', qs, values);
return this._client.any(qs, values);
}
Expand Down
1 change: 0 additions & 1 deletion src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class PushController {
const updateWhere = deepcopy(where);

badgeUpdate = () => {
updateWhere.deviceType = 'ios';
// Build a real RestQuery so we can use it in RestWrite
const restQuery = new RestQuery(config, master(config), '_Installation', updateWhere);
return restQuery.buildRestWhere().then(() => {
Expand Down
5 changes: 1 addition & 4 deletions src/Push/PushWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const UNSUPPORTED_BADGE_KEY = "unsupported";

function groupByBadge(installations) {
return installations.reduce((map, installation) => {
let badge = installation.badge + '';
if (installation.deviceType != "ios") {
badge = UNSUPPORTED_BADGE_KEY;
}
const badge = installation.badge + '';
map[badge] = map[badge] || [];
map[badge].push(installation);
return map;
Expand Down