@optimiser/common 1.0.372 → 1.0.374
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 +22 -45
- package/package.json +1 -1
package/dist/lib/event.js
CHANGED
|
@@ -76,16 +76,15 @@ 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,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
switch (_c.label) {
|
|
79
|
+
var notificationDataObj, userObj, userDeviceInfoObj, message, response, error_1, uniqueID, params;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
83
82
|
case 0:
|
|
84
|
-
if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/,
|
|
83
|
+
if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 8];
|
|
85
84
|
notificationDataObj = data.PushNotificationObj;
|
|
86
85
|
return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
|
|
87
86
|
case 1:
|
|
88
|
-
userObj =
|
|
87
|
+
userObj = _a.sent();
|
|
89
88
|
if (userObj && userObj.endpoint && userObj.keys && data.PushNotificationObj) {
|
|
90
89
|
data.PushNotificationObj["endpoint"] = userObj.endpoint;
|
|
91
90
|
data.PushNotificationObj["keys"] = userObj.keys;
|
|
@@ -94,34 +93,12 @@ var Event = /** @class */ (function () {
|
|
|
94
93
|
delete data.PushNotificationObj;
|
|
95
94
|
}
|
|
96
95
|
console.log("notificationDataObj Before calling fcm send--------", notificationDataObj);
|
|
97
|
-
if (!this.FCMMobileServiceAccountKey) return [3 /*break*/,
|
|
96
|
+
if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 7];
|
|
98
97
|
return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
|
|
99
98
|
case 2:
|
|
100
|
-
userDeviceInfoObj =
|
|
99
|
+
userDeviceInfoObj = _a.sent();
|
|
101
100
|
console.log("userDeviceInfoObj", userDeviceInfoObj);
|
|
102
|
-
if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/,
|
|
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
|
-
}
|
|
101
|
+
if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/, 6];
|
|
125
102
|
message = {
|
|
126
103
|
token: userDeviceInfoObj.deviceToken,
|
|
127
104
|
notification: {
|
|
@@ -146,28 +123,28 @@ var Event = /** @class */ (function () {
|
|
|
146
123
|
};
|
|
147
124
|
//changes by sunny ,send background notifcation
|
|
148
125
|
if (notificationDataObj && (notificationDataObj === null || notificationDataObj === void 0 ? void 0 : notificationDataObj.isBackgroundPushnotification) == true) {
|
|
149
|
-
delete message.notification;
|
|
126
|
+
delete message.notification && delete message.android.notification; // added by komal, notifications under android has been deleted for backgorund notifications
|
|
150
127
|
console.log("message.notification deleted");
|
|
151
128
|
}
|
|
152
129
|
console.log("FCM message payload------>", message);
|
|
153
130
|
console.log("notificationDataObj inside if condition------>", JSON.stringify(notificationDataObj));
|
|
154
|
-
|
|
155
|
-
case
|
|
156
|
-
|
|
131
|
+
_a.label = 3;
|
|
132
|
+
case 3:
|
|
133
|
+
_a.trys.push([3, 5, , 6]);
|
|
157
134
|
return [4 /*yield*/, admin.messaging().send(message)];
|
|
158
|
-
case
|
|
159
|
-
response =
|
|
135
|
+
case 4:
|
|
136
|
+
response = _a.sent();
|
|
160
137
|
console.log('Successfully sent FCM notify(Mobile) message:', response);
|
|
161
|
-
return [3 /*break*/,
|
|
162
|
-
case
|
|
163
|
-
error_1 =
|
|
138
|
+
return [3 /*break*/, 6];
|
|
139
|
+
case 5:
|
|
140
|
+
error_1 = _a.sent();
|
|
164
141
|
console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
|
|
165
|
-
return [3 /*break*/,
|
|
166
|
-
case
|
|
167
|
-
case
|
|
142
|
+
return [3 /*break*/, 6];
|
|
143
|
+
case 6: return [3 /*break*/, 8];
|
|
144
|
+
case 7:
|
|
168
145
|
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
|
-
|
|
170
|
-
case
|
|
146
|
+
_a.label = 8;
|
|
147
|
+
case 8:
|
|
171
148
|
// if (userId && data.SocketObj && !data.SocketObj.userId) {
|
|
172
149
|
//QPC-7064, Ankush changes added
|
|
173
150
|
if (userId && data.SocketObj && data.SocketObj.userId != userId) {
|