Skip to content

Change pushHash with stringified data #2397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 9 additions & 1 deletion src/pushStatusHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,7 +44,7 @@ export default function pushStatusHandler(config) {
expiry: body.expiration_time,
status: "pending",
numSent: 0,
pushHash: md5Hash(data.alert || ''),
pushHash,
// lockdown!
ACL: {}
}
Expand Down