Skip to content

Commit ad52ed6

Browse files
authored
Lets increment/set badges on all _Installations (#3970)
* Lets increment/set badges on all _Installations * Makes sure PG update where query is properly formed with empty query
1 parent 5931aa8 commit ad52ed6

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

spec/PushController.spec.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,8 @@ describe('PushController', () => {
172172
send: function(body, installations) {
173173
var badge = body.data.badge;
174174
installations.forEach((installation) => {
175-
if (installation.deviceType == "ios") {
176-
expect(installation.badge).toEqual(badge);
177-
expect(installation.originalBadge + 1).toEqual(installation.badge);
178-
} else {
179-
expect(installation.badge).toBeUndefined();
180-
}
175+
expect(installation.badge).toEqual(badge);
176+
expect(installation.originalBadge + 1).toEqual(installation.badge);
181177
})
182178
return successfulTransmissions(body, installations);
183179
},
@@ -203,7 +199,9 @@ describe('PushController', () => {
203199
while(installations.length != 15) {
204200
const installation = new Parse.Object("_Installation");
205201
installation.set("installationId", "installation_" + installations.length);
206-
installation.set("deviceToken","device_token_" + installations.length)
202+
installation.set("deviceToken","device_token_" + installations.length);
203+
installation.set("badge", installations.length);
204+
installation.set("originalBadge", installations.length);
207205
installation.set("deviceType", "android");
208206
installations.push(installation);
209207
}
@@ -238,12 +236,7 @@ describe('PushController', () => {
238236
expect(results.length).toBe(15);
239237
for (var i = 0; i < 15; i++) {
240238
const installation = results[i];
241-
if (installation.get('deviceType') == 'ios') {
242-
expect(installation.get('badge')).toBe(parseInt(installation.get('originalBadge')) + 1);
243-
} else {
244-
expect(installation.get('badge')).toBe(undefined);
245-
expect(installation.get('originalBadge')).toBe(undefined);
246-
}
239+
expect(installation.get('badge')).toBe(parseInt(installation.get('originalBadge')) + 1);
247240
}
248241
done()
249242
}).catch((err) => {

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ export class PostgresStorageAdapter {
10911091
const where = buildWhereClause({ schema, index, query })
10921092
values.push(...where.values);
10931093

1094-
const qs = `UPDATE $1:name SET ${updatePatterns.join(',')} WHERE ${where.pattern} RETURNING *`;
1094+
const whereClause = where.pattern.length > 0 ? `WHERE ${where.pattern}` : '';
1095+
const qs = `UPDATE $1:name SET ${updatePatterns.join(',')} ${whereClause} RETURNING *`;
10951096
debug('update: ', qs, values);
10961097
return this._client.any(qs, values);
10971098
}

src/Controllers/PushController.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class PushController {
3636
const updateWhere = deepcopy(where);
3737

3838
badgeUpdate = () => {
39-
updateWhere.deviceType = 'ios';
4039
// Build a real RestQuery so we can use it in RestWrite
4140
const restQuery = new RestQuery(config, master(config), '_Installation', updateWhere);
4241
return restQuery.buildRestWhere().then(() => {

src/Push/PushWorker.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ const UNSUPPORTED_BADGE_KEY = "unsupported";
1414

1515
function groupByBadge(installations) {
1616
return installations.reduce((map, installation) => {
17-
let badge = installation.badge + '';
18-
if (installation.deviceType != "ios") {
19-
badge = UNSUPPORTED_BADGE_KEY;
20-
}
17+
const badge = installation.badge + '';
2118
map[badge] = map[badge] || [];
2219
map[badge].push(installation);
2320
return map;

0 commit comments

Comments
 (0)