web-manager 3.2.70 → 3.2.72

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.
Files changed (2) hide show
  1. package/index.js +25 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1088,13 +1088,13 @@ Manager.prototype.notifications = function(options) {
1088
1088
  },
1089
1089
  )
1090
1090
  .then(function(data) {
1091
- // self.log('Updated token: ', token);
1091
+ // self.log('Updated token:', token);
1092
1092
  saveLocal();
1093
1093
  resolve(true);
1094
1094
  })
1095
1095
  } else {
1096
1096
  saveLocal();
1097
- // self.log('Skip sync, server data exists.');
1097
+ // self.log('Skip sync because server data exists');
1098
1098
  resolve(false);
1099
1099
  }
1100
1100
  }
@@ -1109,7 +1109,7 @@ Manager.prototype.notifications = function(options) {
1109
1109
  saveServer({exists: false})
1110
1110
  })
1111
1111
  } else {
1112
- // self.log('Skip sync, recently done.');
1112
+ // self.log('Skip sync because recently done');
1113
1113
  resolve(false);
1114
1114
  }
1115
1115
 
@@ -1196,10 +1196,29 @@ function subscriptionManager(self, options_user) {
1196
1196
  // Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
1197
1197
  try {
1198
1198
  firebase.messaging().onMessage(function (payload) {
1199
- new Notification(payload.notification.title, payload.notification)
1199
+ // Get the notification data
1200
+ var notification = payload.notification;
1201
+ var data = payload.data;
1202
+
1203
+ // Get the click action
1204
+ var clickAction = notification.click_action || data.click_action;
1205
+
1206
+ // Log
1207
+ console.log('Message received', payload, clickAction);
1208
+
1209
+ // Display notification
1210
+ new Notification(notification.title, notification)
1200
1211
  .onclick = function(event) {
1201
- event.preventDefault(); // prevent the browser from focusing the Notification's tab
1202
- window.open(payload.notification.click_action, '_blank');
1212
+ // Quit if there is no click action
1213
+ if (!clickAction) {
1214
+ return;
1215
+ }
1216
+
1217
+ // prevent the browser from focusing the Notification's tab
1218
+ event.preventDefault();
1219
+
1220
+ // Open the click action
1221
+ window.open(clickAction, '_blank');
1203
1222
  }
1204
1223
  })
1205
1224
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.2.70",
3
+ "version": "3.2.72",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "index.js",
6
6
  "scripts": {