Skip to content

Commit 452887b

Browse files
alenoirflovilmart
authored andcommitted
Change pushHash with stringified data (#2397)
* Change pushHash with stringify data * stringify data.alert for pushHash * stringify data.alert if object for pushHash * test push notification when data.alert is an object
1 parent e6d31a0 commit 452887b

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

spec/PushController.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,47 @@ describe('PushController', () => {
397397
});
398398
});
399399

400+
it_exclude_dbs(['postgres'])('should support object type for alert', (done) => {
401+
var payload = {data: {
402+
alert: {
403+
'loc-key': 'hello_world',
404+
},
405+
}}
406+
407+
var pushAdapter = {
408+
send: function(body, installations) {
409+
return successfulTransmissions(body, installations);
410+
},
411+
getValidPushTypes: function() {
412+
return ["ios"];
413+
}
414+
}
415+
416+
var config = new Config(Parse.applicationId);
417+
var auth = {
418+
isMaster: true
419+
}
420+
421+
let where = {
422+
'deviceToken': {
423+
'$inQuery': {
424+
'where': {
425+
'deviceType': 'ios'
426+
},
427+
className: '_Installation'
428+
}
429+
}
430+
}
431+
432+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
433+
pushController.sendPush(payload, where, config, auth).then((result) => {
434+
done();
435+
}).catch((err) => {
436+
fail('should not fail');
437+
done();
438+
});
439+
});
440+
400441
it('should flatten', () => {
401442
var res = pushStatusHandler.flatten([1, [2], [[3, 4], 5], [[[6]]]])
402443
expect(res).toEqual([1,2,3,4,5,6]);

src/pushStatusHandler.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export default function pushStatusHandler(config) {
2525
let now = new Date();
2626
let data = body.data || {};
2727
let payloadString = JSON.stringify(data);
28+
let pushHash;
29+
if (typeof data.alert === 'string') {
30+
pushHash = md5Hash(data.alert);
31+
} else if (typeof data.alert === 'object') {
32+
pushHash = md5Hash(JSON.stringify(data.alert));
33+
} else {
34+
pushHash = 'd41d8cd98f00b204e9800998ecf8427e';
35+
}
2836
let object = {
2937
objectId,
3038
createdAt: now,
@@ -36,7 +44,7 @@ export default function pushStatusHandler(config) {
3644
expiry: body.expiration_time,
3745
status: "pending",
3846
numSent: 0,
39-
pushHash: md5Hash(data.alert || ''),
47+
pushHash,
4048
// lockdown!
4149
ACL: {}
4250
}

0 commit comments

Comments
 (0)