web-manager 3.1.12 → 3.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +13 -23
  2. package/lib/account.js +19 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -164,14 +164,12 @@ function Manager() {
164
164
  }
165
165
 
166
166
  Manager.prototype.setEventListeners = function() {
167
- // console.log('--------setEventListeners');
167
+ var This = this;
168
+
168
169
  if (!utilities.get(this, 'properties.page.status.eventHandlersSet', false)) {
169
170
  this.properties.page.status.eventHandlersSet = true;
170
- var This = this;
171
- // document.addEventListener('click', function (event) {
171
+
172
172
  document.addEventListener('click', function (event) {
173
- // console.log('Clicked.... NEW');
174
- // This.log('Clicked', event.target);
175
173
  // auth events
176
174
  if (event.target.matches('.auth-signin-email-btn')) {
177
175
  This.auth().signIn('email');
@@ -187,16 +185,18 @@ function Manager() {
187
185
  This.auth().forgot();
188
186
  } else if (event.target.matches('#prechat-btn')) {
189
187
  load_tawk(This, This.properties.options);
190
- }
191
-
192
- // push notification events
193
- if (event.target.matches('.auth-subscribe-notifications-btn')) {
194
- //@@@NOTIFICATIONS
188
+ } else if (event.target.matches('.auth-subscribe-notifications-btn')) {
195
189
  This.notifications().subscribe()
196
- .catch(function (e) {
197
- console.error(e);
198
- });
199
190
  }
191
+
192
+ // Autorequest
193
+ if (!This._notificationRequested && This.properties.options.pushNotifications.autoRequest) {
194
+ This._notificationRequested = true;
195
+
196
+ setTimeout(function () {
197
+ This.notifications().subscribe()
198
+ }, This.properties.options.pushNotifications.autoRequest * 1000);
199
+ }
200
200
 
201
201
  }, false);
202
202
  }
@@ -1221,16 +1221,6 @@ function Manager() {
1221
1221
  //@@@NOTIFICATIONS
1222
1222
  // _setupTokenRefreshHandler(This);
1223
1223
 
1224
- if (options_user.pushNotifications.autoRequest) {
1225
- setTimeout(function () {
1226
- //@@@NOTIFICATIONS
1227
- This.notifications().subscribe()
1228
- .catch(function (e) {
1229
- console.error(e);
1230
- });
1231
- }, options_user.pushNotifications.autoRequest * 1000);
1232
- }
1233
-
1234
1224
  try {
1235
1225
  // Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
1236
1226
  firebase.messaging().onMessage(function (payload) {
package/lib/account.js CHANGED
@@ -151,6 +151,25 @@ Account.prototype.delete = function (options) {
151
151
  });
152
152
  }
153
153
 
154
+ Account.prototype.resolve = function (account, options) {
155
+ var self = this;
156
+ return new Promise(function(resolve, reject) {
157
+ var currentUser = firebase.auth().currentUser;
158
+
159
+ // If there is no user logged in or we choose not to fetch the account, resolve a default account
160
+ if (!currentUser || !currentUser.uid || options.fetchNewAccount === false) {
161
+ return resolve(self._resolveAccount(currentUser, account, options));
162
+ }
163
+
164
+ // Otherwise, fetch the account from the database and resolve it
165
+ firebase.firestore().doc('users/' + currentUser.uid)
166
+ .get()
167
+ .then(function (doc) {
168
+ return resolve(self._resolveAccount(currentUser, doc.data(), options));
169
+ })
170
+ });
171
+ }
172
+
154
173
  Account.prototype.resolve = function (account, options) {
155
174
  var self = this;
156
175
  return new Promise(function(resolve, reject) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.12",
3
+ "version": "3.1.14",
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": {