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
This commit is contained in:
committed by
Florent Vilmart
parent
e6d31a07ab
commit
452887bd05
@@ -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', () => {
|
it('should flatten', () => {
|
||||||
var res = pushStatusHandler.flatten([1, [2], [[3, 4], 5], [[[6]]]])
|
var res = pushStatusHandler.flatten([1, [2], [[3, 4], 5], [[[6]]]])
|
||||||
expect(res).toEqual([1,2,3,4,5,6]);
|
expect(res).toEqual([1,2,3,4,5,6]);
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ export default function pushStatusHandler(config) {
|
|||||||
let now = new Date();
|
let now = new Date();
|
||||||
let data = body.data || {};
|
let data = body.data || {};
|
||||||
let payloadString = JSON.stringify(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 = {
|
let object = {
|
||||||
objectId,
|
objectId,
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
@@ -36,7 +44,7 @@ export default function pushStatusHandler(config) {
|
|||||||
expiry: body.expiration_time,
|
expiry: body.expiration_time,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
numSent: 0,
|
numSent: 0,
|
||||||
pushHash: md5Hash(data.alert || ''),
|
pushHash,
|
||||||
// lockdown!
|
// lockdown!
|
||||||
ACL: {}
|
ACL: {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user