My current project involves the use of an NPM package called fcm-push
in order to send FCM notifications to different mobile devices based on specific messages. Everything works fine when the message is successfully sent, but if the sending fails due to the FCM token being flagged as "NotRegistered," I need to remove that token from the user's profile.
The issue I'm facing is that even though the callback function for Meteor.users.update
is triggered when the message fails to send, the token is not removed from the user profile. Any advice on how to adjust the database operation so that the update process is successful would be greatly appreciated.
[INFO] -- 10:59:23 | "Error" | Data: {
"data": "NotRegistered",
"haltDate": "2017-03-31T10:59:23.660Z"
} | User: cHkDSqQBMVc:APA91bFXCwp1-nxi2xxVEZARAMHs48kLm6FN0tbgmjv1lP1-LsBty_6gCFqGqDxGV9JrpCDG9pVFIxUz-77-6QxbIMa2OWmG4xoN2-E_8UoD_xe8MVoDb-DZY_KSZcMh4Bg_5F18ltg0
return fcm.send(fcmMessage).then((data) => {
var processEndDate = new Date();
console.log("Response Data "+data+" ------ "+startDate+" --> "+processEndDate);
loggerA.info("Response", {data: data, startDate: startDate, endDate: processEndDate}, token);
return {
method: 'SendMessage',
status: JobberServer.Status.SUCCESS,
dateEnd: processEndDate,
response: data
};
}).catch((err) => {
loggerA.info("Error", {data: err, haltDate: startDate}, token);
Meteor.users.update({_id: targetId}, {$pull: {"profile.fcmTokens": {id: token}}}, {multi: true}, function (err, docsModified) {
loggerA.info("Deregister Op", {token: token, res: err, noOfDereggedTokens: docsModified}, "NAN");
});
return {
method: 'SendMessage',
status: JobberServer.Status.FAIL,
dateEnd: null,
response: err
}
});