From 4ebe5283bd1f1e0558d037c73ea2eac3f05c1935 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 31 Jul 2020 18:04:38 -0300 Subject: [PATCH] [FIX] Multiple push notifications sent via native drivers (#18442) --- app/push/server/apn.js | 10 ++++++++-- app/push/server/gcm.js | 3 ++- app/push/server/push.js | 3 --- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/push/server/apn.js b/app/push/server/apn.js index f661da45cda..693f8dcc052 100644 --- a/app/push/server/apn.js +++ b/app/push/server/apn.js @@ -1,4 +1,5 @@ import apn from 'apn'; +import { EJSON } from 'meteor/ejson'; import { logger } from './logger'; @@ -34,7 +35,7 @@ export const sendAPN = ({ userToken, notification, _removeToken }) => { } // Allow the user to set payload data - note.payload = notification.payload || {}; + note.payload = notification.payload ? { ejson: EJSON.stringify(notification.payload) } : {}; note.payload.messageFrom = notification.from; note.priority = priority; @@ -111,5 +112,10 @@ export const initAPN = ({ options, absoluteUrl }) => { } // Rig apn connection - apnConnection = new apn.Provider(options.apn); + try { + apnConnection = new apn.Provider(options.apn); + } catch (e) { + console.error('Error trying to initialize APN'); + console.error(e); + } }; diff --git a/app/push/server/gcm.js b/app/push/server/gcm.js index 5d7c11d04cb..05acee5b881 100644 --- a/app/push/server/gcm.js +++ b/app/push/server/gcm.js @@ -1,4 +1,5 @@ import gcm from 'node-gcm'; +import { EJSON } from 'meteor/ejson'; import { logger } from './logger'; @@ -21,7 +22,7 @@ export const sendGCM = function({ userTokens, notification, _replaceToken, _remo logger.debug('sendGCM', userTokens, notification); // Allow user to set payload - const data = notification.payload || {}; + const data = notification.payload ? { ejson: EJSON.stringify(notification.payload) } : {}; data.title = notification.title; data.message = notification.text; diff --git a/app/push/server/push.js b/app/push/server/push.js index 3c61b9aef55..b0d7abed1ad 100644 --- a/app/push/server/push.js +++ b/app/push/server/push.js @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { EJSON } from 'meteor/ejson'; import { Match, check } from 'meteor/check'; import { Mongo } from 'meteor/mongo'; import { HTTP } from 'meteor/http'; @@ -80,8 +79,6 @@ export class PushClass { sendNotificationNative(app, notification, countApn, countGcm) { logger.debug('send to token', app.token); - notification.payload = notification.payload ? { ejson: EJSON.stringify(notification.payload) } : {}; - if (app.token.apn) { countApn.push(app._id); // Send to APN