Skip to content

Commit 6676c6a

Browse files
authored
Let multiple installations be updates if no critical values are set (#3040)
* Let multiple installations be updates if no critical values are set * nits
1 parent b6fb3d8 commit 6676c6a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

spec/PushController.spec.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,68 @@ describe('PushController', () => {
238238

239239
});
240240

241+
it('properly set badges to 1 with complex query #2903 #3022', (done) => {
242+
243+
var payload = {
244+
data: {
245+
alert: "Hello World!",
246+
badge: 1,
247+
}
248+
}
249+
var installations = [];
250+
while(installations.length != 10) {
251+
var installation = new Parse.Object("_Installation");
252+
installation.set("installationId", "installation_"+installations.length);
253+
installation.set("deviceToken","device_token_"+installations.length)
254+
installation.set("badge", installations.length);
255+
installation.set("originalBadge", installations.length);
256+
installation.set("deviceType", "ios");
257+
installations.push(installation);
258+
}
259+
let matchedInstallationsCount = 0;
260+
var pushAdapter = {
261+
send: function(body, installations) {
262+
matchedInstallationsCount += installations.length;
263+
var badge = body.data.badge;
264+
installations.forEach((installation) => {
265+
expect(installation.badge).toEqual(badge);
266+
expect(1).toEqual(installation.badge);
267+
})
268+
return successfulTransmissions(body, installations);
269+
},
270+
getValidPushTypes: function() {
271+
return ["ios"];
272+
}
273+
}
274+
275+
var config = new Config(Parse.applicationId);
276+
var auth = {
277+
isMaster: true
278+
}
279+
280+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
281+
Parse.Object.saveAll(installations).then((installations) => {
282+
let objectIds = installations.map(installation => {
283+
return installation.id;
284+
})
285+
let where = {
286+
objectId: {'$in': objectIds.slice(0, 5)}
287+
}
288+
return pushController.sendPush(payload, where, config, auth);
289+
}).then(() => {
290+
expect(matchedInstallationsCount).toBe(5);
291+
let query = new Parse.Query(Parse.Installation);
292+
query.equalTo('badge', 1);
293+
return query.find({useMasterKey: true});
294+
}).then((installations) => {
295+
expect(installations.length).toBe(5);
296+
done();
297+
}).catch(() => {
298+
fail("should not fail");
299+
done();
300+
});
301+
});
302+
241303
it('properly creates _PushStatus', (done) => {
242304

243305
var installations = [];

src/LiveQuery/ParseCloudCodePublisher.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ParsePubSub } from './ParsePubSub';
2+
import Parse from 'parse/node';
23
import logger from '../logger';
34

45
class ParseCloudCodePublisher {

src/RestWrite.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ RestWrite.prototype.handleInstallation = function() {
624624
installationId = installationId.toLowerCase();
625625
}
626626

627+
// Updating _Installation but not updating anything critical
628+
if (this.query && !this.data.deviceToken
629+
&& !installationId && !this.data.deviceType) {
630+
return;
631+
}
632+
627633
var promise = Promise.resolve();
628634

629635
var idMatch; // Will be a match on either objectId or installationId

0 commit comments

Comments
 (0)