From 10bb3f6a2fe830a7b0adfb9c5733f97879d359d9 Mon Sep 17 00:00:00 2001 From: Mathieu Legault Date: Tue, 27 Sep 2016 09:03:40 -0400 Subject: [PATCH] Added push_hash to the body data sent to the push adapter In order to track which notifications is being opened, we need to send push_hash to the adapter. --- src/Controllers/PushController.js | 5 +++-- src/StatusHandler.js | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Controllers/PushController.js b/src/Controllers/PushController.js index 84e2a79d4b..40d85c9f31 100644 --- a/src/Controllers/PushController.js +++ b/src/Controllers/PushController.js @@ -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(); @@ -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) => { diff --git a/src/StatusHandler.js b/src/StatusHandler.js index 8d7718dfc1..4ec466094c 100644 --- a/src/StatusHandler.js +++ b/src/StatusHandler.js @@ -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, @@ -123,8 +126,8 @@ export function pushStatusHandler(config) { expiry: body.expiration_time, status: "pending", numSent: 0, + numOpened: 0, pushHash, - // lockdown! ACL: {} } @@ -189,6 +192,7 @@ export function pushStatusHandler(config) { return Object.freeze({ objectId, setInitial, + pushHash, setRunning, complete, fail