Skip to content
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

Added push_hash to the body data sent to the push adapter #2791

Closed
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
5 changes: 3 additions & 2 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class PushController extends AdaptableController {
});
}
}
let pushStatus = pushStatusHandler(config);
let pushStatus = pushStatusHandler(body, config);
return Promise.resolve().then(() => {
return pushStatus.setInitial(body, where);
return pushStatus.setInitial(where);
}).then(() => {
onPushStatusSaved(pushStatus.objectId);
return badgeUpdate();
Expand All @@ -105,6 +105,7 @@ export class PushController extends AdaptableController {
}

sendToAdapter(body, installations, pushStatus, config) {
body.data["push_hash"] = pushStatus.pushHash;
if (body.data && body.data.badge && typeof body.data.badge == 'string' && body.data.badge.toLowerCase() == "increment") {
// Collect the badges to reduce the # of calls
let badgeInstallationsMap = installations.reduce((map, installation) => {
Expand Down
28 changes: 16 additions & 12 deletions src/StatusHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,27 @@ export function jobStatusHandler(config) {
});
}

export function pushStatusHandler(config) {
export function pushStatusHandler(body = {}, config) {

let pushStatus;
let objectId = newObjectId();
let database = config.database;
let handler = statusHandler(PUSH_STATUS_COLLECTION, database);
let setInitial = function(body = {}, where, options = {source: 'rest'}) {

let data = body.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 setInitial = function(where, options = {source: 'rest'}) {
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 @@ -123,8 +126,8 @@ export function pushStatusHandler(config) {
expiry: body.expiration_time,
status: "pending",
numSent: 0,
numOpened: 0,
pushHash,
// lockdown!
ACL: {}
}

Expand Down Expand Up @@ -189,6 +192,7 @@ export function pushStatusHandler(config) {
return Object.freeze({
objectId,
setInitial,
pushHash,
setRunning,
complete,
fail
Expand Down