strongloop/loopback-component-push

GCM push notifcations not sending full data dictionary

Closed this issue · 3 comments

I've set up to push notifications to Android devices after having already set them up for iOS.
However, when the notifications come down to the Android app, the data dictionary is missing most of the values

{object=2562, type=NewQuestionAlert, contentAvailable=true, collapse_key=do_not_collapse}

when the notification object is

var note = new loopbackPush.Notification({
  expirationInterval: 3600,
  contentAvailable: true,
  badge: badge,
  alert: message,
  type: type,
  object: object
});

I determined the root of the problem seems to be in the gcm.js file's _createMessage function when copying data from the notification object to the message object.

Object.keys(notification).forEach(function (key) {

This is only iterating through three keys at the base level of the object, where as all the key/value pairs et when creating the notification are stored deeper in __data.

Object.keys(notification.__data).forEach(function (key) {

seems to be the quickest way to get it to iterate through the correct keys and put them in the message object, meaning it comes down correctly

{deviceToken=adevicetoken, object=2562, type=NewQuestionAlert, alert=This is some text, badge=15, deviceType=android, expirationInterval=3600, created=2015-12-22T05:08:35.569Z, contentAvailable=true, collapse_key=do_not_collapse}

But I'm not sure if this is the best solution to the problem.

Would you like to submit a PR for your fix? We can verify your proposal there instead.

@superkhau this is a duplicate of #82 which has a PR waiting since yesterday.

@seriousben TY, closing as a duplicate then.