@optimiser/common 1.0.370 → 1.0.372
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/event.js +49 -21
- package/package.json +1 -1
package/dist/lib/event.js
CHANGED
|
@@ -76,15 +76,16 @@ var Event = /** @class */ (function () {
|
|
|
76
76
|
var _this = this;
|
|
77
77
|
return __generator(this, function (_a) {
|
|
78
78
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
79
|
-
var notificationDataObj, userObj, userDeviceInfoObj, message, response, error_1, uniqueID, params;
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
var notificationDataObj, userObj, userDeviceInfoObj, notificationCount, message, response, error_1, uniqueID, params;
|
|
80
|
+
var _a, _b;
|
|
81
|
+
return __generator(this, function (_c) {
|
|
82
|
+
switch (_c.label) {
|
|
82
83
|
case 0:
|
|
83
|
-
if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/,
|
|
84
|
+
if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 9];
|
|
84
85
|
notificationDataObj = data.PushNotificationObj;
|
|
85
86
|
return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
|
|
86
87
|
case 1:
|
|
87
|
-
userObj =
|
|
88
|
+
userObj = _c.sent();
|
|
88
89
|
if (userObj && userObj.endpoint && userObj.keys && data.PushNotificationObj) {
|
|
89
90
|
data.PushNotificationObj["endpoint"] = userObj.endpoint;
|
|
90
91
|
data.PushNotificationObj["keys"] = userObj.keys;
|
|
@@ -93,12 +94,34 @@ var Event = /** @class */ (function () {
|
|
|
93
94
|
delete data.PushNotificationObj;
|
|
94
95
|
}
|
|
95
96
|
console.log("notificationDataObj Before calling fcm send--------", notificationDataObj);
|
|
96
|
-
if (!this.FCMMobileServiceAccountKey) return [3 /*break*/,
|
|
97
|
+
if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 8];
|
|
97
98
|
return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
|
|
98
99
|
case 2:
|
|
99
|
-
userDeviceInfoObj =
|
|
100
|
+
userDeviceInfoObj = _c.sent();
|
|
100
101
|
console.log("userDeviceInfoObj", userDeviceInfoObj);
|
|
101
|
-
if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/,
|
|
102
|
+
if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/, 7];
|
|
103
|
+
return [4 /*yield*/, db.collection('Notification').aggregate([{
|
|
104
|
+
$match: {
|
|
105
|
+
'Users': { $elemMatch: { 'UserID': new mongodb_1.ObjectId(userId) } },
|
|
106
|
+
'IsActive': true
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
$facet: {
|
|
110
|
+
TotalUnseenNoti: [{
|
|
111
|
+
$unwind: "$Users"
|
|
112
|
+
}, {
|
|
113
|
+
$match: { "Users.UserID": new mongodb_1.ObjectId(userId), "Users.IsNew": true }
|
|
114
|
+
}, {
|
|
115
|
+
$count: 'count'
|
|
116
|
+
}]
|
|
117
|
+
}
|
|
118
|
+
}])];
|
|
119
|
+
case 3:
|
|
120
|
+
notificationCount = _c.sent();
|
|
121
|
+
if ((notificationDataObj === null || notificationDataObj === void 0 ? void 0 : notificationDataObj.isBackgroundPushnotification) != true) {
|
|
122
|
+
console.log("notificationCount", (_a = notificationCount[0].TotalUnseenNoti[0]) === null || _a === void 0 ? void 0 : _a.count);
|
|
123
|
+
notificationDataObj['notificationCount'] = (_b = notificationCount[0].TotalUnseenNoti[0]) === null || _b === void 0 ? void 0 : _b.count;
|
|
124
|
+
}
|
|
102
125
|
message = {
|
|
103
126
|
token: userDeviceInfoObj.deviceToken,
|
|
104
127
|
notification: {
|
|
@@ -121,25 +144,30 @@ var Event = /** @class */ (function () {
|
|
|
121
144
|
},
|
|
122
145
|
data: { data: JSON.stringify(notificationDataObj) } // changes done by komal, to get data attr val in notification
|
|
123
146
|
};
|
|
147
|
+
//changes by sunny ,send background notifcation
|
|
148
|
+
if (notificationDataObj && (notificationDataObj === null || notificationDataObj === void 0 ? void 0 : notificationDataObj.isBackgroundPushnotification) == true) {
|
|
149
|
+
delete message.notification;
|
|
150
|
+
console.log("message.notification deleted");
|
|
151
|
+
}
|
|
124
152
|
console.log("FCM message payload------>", message);
|
|
125
153
|
console.log("notificationDataObj inside if condition------>", JSON.stringify(notificationDataObj));
|
|
126
|
-
|
|
127
|
-
case 3:
|
|
128
|
-
_a.trys.push([3, 5, , 6]);
|
|
129
|
-
return [4 /*yield*/, admin.messaging().send(message)];
|
|
154
|
+
_c.label = 4;
|
|
130
155
|
case 4:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return [3 /*break*/, 6];
|
|
156
|
+
_c.trys.push([4, 6, , 7]);
|
|
157
|
+
return [4 /*yield*/, admin.messaging().send(message)];
|
|
134
158
|
case 5:
|
|
135
|
-
|
|
159
|
+
response = _c.sent();
|
|
160
|
+
console.log('Successfully sent FCM notify(Mobile) message:', response);
|
|
161
|
+
return [3 /*break*/, 7];
|
|
162
|
+
case 6:
|
|
163
|
+
error_1 = _c.sent();
|
|
136
164
|
console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
|
|
137
|
-
return [3 /*break*/,
|
|
138
|
-
case
|
|
139
|
-
case 7:
|
|
140
|
-
console.log('Attention!!-- We are not sending mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
|
|
141
|
-
_a.label = 8;
|
|
165
|
+
return [3 /*break*/, 7];
|
|
166
|
+
case 7: return [3 /*break*/, 9];
|
|
142
167
|
case 8:
|
|
168
|
+
console.log('Attention!!-- We are not sending mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
|
|
169
|
+
_c.label = 9;
|
|
170
|
+
case 9:
|
|
143
171
|
// if (userId && data.SocketObj && !data.SocketObj.userId) {
|
|
144
172
|
//QPC-7064, Ankush changes added
|
|
145
173
|
if (userId && data.SocketObj && data.SocketObj.userId != userId) {
|