From dd6a62c398e23bcae539bfd24391b00f907b5b4b Mon Sep 17 00:00:00 2001 From: Antoine Lenoir Date: Tue, 26 Jul 2016 16:15:03 +0200 Subject: [PATCH 1/4] Change pushHash with stringify data --- src/pushStatusHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pushStatusHandler.js b/src/pushStatusHandler.js index f75660879a..78d8da19de 100644 --- a/src/pushStatusHandler.js +++ b/src/pushStatusHandler.js @@ -36,7 +36,7 @@ export default function pushStatusHandler(config) { expiry: body.expiration_time, status: "pending", numSent: 0, - pushHash: md5Hash(data.alert || ''), + pushHash: md5Hash(payloadString || ''), // lockdown! ACL: {} } From 18d5e055af64b29495ff021ac62c97a56a66c6f3 Mon Sep 17 00:00:00 2001 From: Antoine Lenoir Date: Wed, 27 Jul 2016 11:18:53 +0200 Subject: [PATCH 2/4] stringify data.alert for pushHash --- src/pushStatusHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pushStatusHandler.js b/src/pushStatusHandler.js index 78d8da19de..c32dae8ca8 100644 --- a/src/pushStatusHandler.js +++ b/src/pushStatusHandler.js @@ -36,7 +36,7 @@ export default function pushStatusHandler(config) { expiry: body.expiration_time, status: "pending", numSent: 0, - pushHash: md5Hash(payloadString || ''), + pushHash: md5Hash(JSON.stringify(data.alert) || ''), // lockdown! ACL: {} } From e40e5eb2feaad5362c81c75d6c3c57b28cefb38d Mon Sep 17 00:00:00 2001 From: Antoine Lenoir Date: Tue, 9 Aug 2016 16:17:34 +0200 Subject: [PATCH 3/4] stringify data.alert if object for pushHash --- src/pushStatusHandler.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pushStatusHandler.js b/src/pushStatusHandler.js index c32dae8ca8..37fef865b1 100644 --- a/src/pushStatusHandler.js +++ b/src/pushStatusHandler.js @@ -25,6 +25,14 @@ export default function pushStatusHandler(config) { let now = new Date(); let data = body.data || {}; let payloadString = JSON.stringify(data); + let pushHash; + if (typeof data.alert === 'string') { + pushHash = md5Hash(data.alert); + } else if (typeof data.alert === 'object') { + pushHash = md5Hash(JSON.stringify(data.alert)); + } else { + pushHash = 'd41d8cd98f00b204e9800998ecf8427e'; + } let object = { objectId, createdAt: now, @@ -36,7 +44,7 @@ export default function pushStatusHandler(config) { expiry: body.expiration_time, status: "pending", numSent: 0, - pushHash: md5Hash(JSON.stringify(data.alert) || ''), + pushHash: pushHash, // lockdown! ACL: {} } From 7ca61906b3e67e580ba42d298a6a0d5690bea32d Mon Sep 17 00:00:00 2001 From: Antoine Lenoir Date: Tue, 9 Aug 2016 17:10:29 +0200 Subject: [PATCH 4/4] test push notification when data.alert is an object --- spec/PushController.spec.js | 41 +++++++++++++++++++++++++++++++++++++ src/pushStatusHandler.js | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/spec/PushController.spec.js b/spec/PushController.spec.js index 344ffcfd85..e40195daf2 100644 --- a/spec/PushController.spec.js +++ b/spec/PushController.spec.js @@ -397,6 +397,47 @@ describe('PushController', () => { }); }); + it_exclude_dbs(['postgres'])('should support object type for alert', (done) => { + var payload = {data: { + alert: { + 'loc-key': 'hello_world', + }, + }} + + var pushAdapter = { + send: function(body, installations) { + return successfulTransmissions(body, installations); + }, + 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, defaultConfiguration.push); + pushController.sendPush(payload, where, config, auth).then((result) => { + done(); + }).catch((err) => { + fail('should not fail'); + done(); + }); + }); + it('should flatten', () => { var res = pushStatusHandler.flatten([1, [2], [[3, 4], 5], [[[6]]]]) expect(res).toEqual([1,2,3,4,5,6]); diff --git a/src/pushStatusHandler.js b/src/pushStatusHandler.js index 37fef865b1..f8c95d635a 100644 --- a/src/pushStatusHandler.js +++ b/src/pushStatusHandler.js @@ -44,7 +44,7 @@ export default function pushStatusHandler(config) { expiry: body.expiration_time, status: "pending", numSent: 0, - pushHash: pushHash, + pushHash, // lockdown! ACL: {} }