@chat21/chat21-ionic 3.0.55 → 3.0.57
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/app/app.component.ts +78 -127
- package/src/chat21-core/providers/abstract/app-storage.service.ts +2 -2
- package/src/chat21-core/providers/firebase/firebase-archivedconversations-handler.ts +1 -1
- package/src/chat21-core/providers/firebase/firebase-auth-service.ts +109 -71
- package/src/chat21-core/providers/firebase/firebase-notifications.ts +10 -16
- package/src/chat21-core/providers/localSessionStorage.ts +155 -154
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/app/app.component.ts
CHANGED
|
@@ -58,6 +58,7 @@ import * as PACKAGE from 'package.json';
|
|
|
58
58
|
|
|
59
59
|
import { Subject } from 'rxjs';
|
|
60
60
|
import { filter, takeUntil } from 'rxjs/operators'
|
|
61
|
+
|
|
61
62
|
// import { filter } from 'rxjs/operators';
|
|
62
63
|
|
|
63
64
|
@Component({
|
|
@@ -73,7 +74,7 @@ export class AppComponent implements OnInit {
|
|
|
73
74
|
// public appIsOnline$: Observable<boolean> = undefined;
|
|
74
75
|
checkInternet: boolean;
|
|
75
76
|
|
|
76
|
-
private
|
|
77
|
+
private BSAuthStateChangedSubscriptionRef: Subscription;
|
|
77
78
|
public sidebarPage: any;
|
|
78
79
|
public notificationsEnabled: boolean;
|
|
79
80
|
public zone: NgZone;
|
|
@@ -99,7 +100,7 @@ export class AppComponent implements OnInit {
|
|
|
99
100
|
public executedInitializeAppByWatchConnection: boolean = false;
|
|
100
101
|
private version: string;
|
|
101
102
|
private unsubscribe$: Subject<any> = new Subject<any>();
|
|
102
|
-
private isOnline: boolean = false;
|
|
103
|
+
// private isOnline: boolean = false;
|
|
103
104
|
|
|
104
105
|
constructor(
|
|
105
106
|
private platform: Platform,
|
|
@@ -162,71 +163,31 @@ export class AppComponent implements OnInit {
|
|
|
162
163
|
this.logger.info('[APP-COMP] ngOnInit this.route.snapshot.params -->', this.route.snapshot.params);
|
|
163
164
|
// this.initializeApp('oninit');
|
|
164
165
|
const token = getParameterByName('jwt')
|
|
165
|
-
this.logger.info('[APP-COMP] ngOnInit token get
|
|
166
|
-
|
|
166
|
+
this.logger.info('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName -->', token);
|
|
167
|
+
|
|
167
168
|
if (token) {
|
|
168
|
-
this.isOnline = false;
|
|
169
|
-
this.logger.log('[APP-COMP]
|
|
169
|
+
// this.isOnline = false;
|
|
170
|
+
// this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with this.isOnline ', this.isOnline)
|
|
171
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName ', token)
|
|
170
172
|
// save token in local storage then
|
|
171
|
-
|
|
173
|
+
|
|
174
|
+
const storedToken = this.appStorageService.getItem('tiledeskToken');
|
|
175
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN storedToken ', storedToken)
|
|
176
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN SAVE THE PARAMS TOKEN ', token)
|
|
177
|
+
if (storedToken !== token) {
|
|
178
|
+
this.appStorageService.setItem('tiledeskToken', token);
|
|
179
|
+
} else {
|
|
180
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN the current user already exist DON\'T SAVE ')
|
|
181
|
+
}
|
|
172
182
|
}
|
|
173
183
|
this.initializeApp('oninit');
|
|
174
|
-
// else {
|
|
175
|
-
// this.isOnline = false;
|
|
176
|
-
// this.logger.log('[APP-COMP] NO AUTLOGIN > RUN INIZIALIZE APP')
|
|
177
|
-
// this.initializeApp('oninit');
|
|
178
|
-
// }
|
|
179
|
-
|
|
180
|
-
// const param = this.param();
|
|
181
|
-
// const token: string = param.get("jwt");
|
|
182
|
-
// this.logger.info('[APP-COMP] ngOnInit token geet from params -->', token);
|
|
183
|
-
|
|
184
|
-
// this.subscription = this.router.events.subscribe((event) => {
|
|
185
|
-
// if (event instanceof NavigationStart) {
|
|
186
|
-
// const current_url = event.url
|
|
187
|
-
// this.logger.info('[APP-COMP] - NavigationStart event current_url ', current_url);
|
|
188
|
-
// if (current_url.includes('jwt')) {
|
|
189
|
-
// this.logger.info('[APP-COMP] - NavigationStart event current_url INCLUDES jwt');
|
|
190
|
-
// const tokenString = current_url.slice(current_url.lastIndexOf('=') + 1)
|
|
191
|
-
// // const token = tokenString.substring(1, tokenString.length - 1)
|
|
192
|
-
// const token = tokenString
|
|
193
|
-
// this.logger.info('[APP-COMP] - NavigationStart event current_url INCLUDES jwt > token ', token);
|
|
194
|
-
// this.signInWithCustomToken("JWT%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MDhhZDAyZDNhNGRjMDAwMzQ0YWRlMTciLCJlbWFpbCI6Im51b3ZvcHJlZ2lub0BtYWlsbmEuY28iLCJmaXJzdG5hbWUiOiJOdW92byIsImxhc3RuYW1lIjoiUHJlZ2lubyIsImVtYWlsdmVyaWZpZWQiOnRydWUsImlhdCI6MTYzNDE5OTU1NiwiYXVkIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJpc3MiOiJodHRwczovL3RpbGVkZXNrLmNvbSIsInN1YiI6InVzZXIiLCJqdGkiOiIwMGQyNTI0MS05MDI4LTRmYTYtYmJhNi0xOGNmZTUwNzdiYTMifQ.4kCuHOyceIMWnlyOiCvQEiDPqDZR8HwYgyQoqMYJxX0")
|
|
195
|
-
// } else {
|
|
196
|
-
// this.logger.info('[APP-COMP] - NavigationStart event current_url NOT INCLUDES jwt');
|
|
197
|
-
// }
|
|
198
|
-
// }
|
|
199
|
-
// });
|
|
200
184
|
|
|
201
|
-
// this.route.queryParams.subscribe(params => {
|
|
202
|
-
// this.logger.log('[APP-COMP] ROUTE QUERY PARAMS params', params)
|
|
203
|
-
// if (params.jwt) {
|
|
204
|
-
// this.isOnline = false;
|
|
205
|
-
// this.logger.log('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKEN params ', params)
|
|
206
|
-
// this.tiledeskAuthService.signInWithCustomToken(params.jwt).then(user => {
|
|
207
|
-
// this.logger.log('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKEN user', user)
|
|
208
|
-
// // if (user) {
|
|
209
|
-
// this.logger.log('[APP-COMP] AUTLOGIN > RUN INIZIALIZE APP')
|
|
210
|
-
// this.initializeApp('oninit');
|
|
211
|
-
// // }
|
|
212
|
-
// this.messagingAuthService.createCustomToken(params.jwt)
|
|
213
|
-
// }).catch(error => {
|
|
214
|
-
// this.logger.error('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKE - ERROR', error)
|
|
215
|
-
// })
|
|
216
|
-
// }
|
|
217
|
-
// else {
|
|
218
|
-
// this.isOnline = false;
|
|
219
|
-
// this.logger.log('[APP-COMP] NO AUTLOGIN > RUN INIZIALIZE APP')
|
|
220
|
-
// this.initializeApp('oninit');
|
|
221
|
-
// }
|
|
222
|
-
// });
|
|
223
185
|
}
|
|
224
186
|
|
|
225
187
|
|
|
226
188
|
signInWithCustomToken(token) {
|
|
227
|
-
|
|
228
|
-
this.
|
|
229
|
-
this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN token', token)
|
|
189
|
+
// this.isOnline = false;
|
|
190
|
+
this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN token', token)
|
|
230
191
|
this.tiledeskAuthService.signInWithCustomToken(token)
|
|
231
192
|
.then((user: any) => {
|
|
232
193
|
this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN user', user)
|
|
@@ -242,8 +203,7 @@ export class AppComponent implements OnInit {
|
|
|
242
203
|
|
|
243
204
|
/** */
|
|
244
205
|
initializeApp(calledby: string) {
|
|
245
|
-
|
|
246
|
-
|
|
206
|
+
console.log('[APP-COMP] - X - initializeApp !!! CALLED-BY: ', calledby);
|
|
247
207
|
this.logger.log('[APP-COMP] appconfig platform is cordova: ', this.platform.is('cordova'))
|
|
248
208
|
|
|
249
209
|
if (!this.platform.is('cordova')) {
|
|
@@ -263,10 +223,6 @@ export class AppComponent implements OnInit {
|
|
|
263
223
|
|
|
264
224
|
this.tenant = appconfig.firebaseConfig.tenant;
|
|
265
225
|
this.logger.info('[APP-COMP] appconfig firebaseConfig tenant: ', this.tenant);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
226
|
this.notificationsEnabled = true;
|
|
271
227
|
this.zone = new NgZone({}); // a cosa serve?
|
|
272
228
|
|
|
@@ -298,35 +254,19 @@ export class AppComponent implements OnInit {
|
|
|
298
254
|
|
|
299
255
|
this.initAuthentication();
|
|
300
256
|
this.initSubscriptions();
|
|
301
|
-
this.initAudio()
|
|
257
|
+
this.initAudio();
|
|
302
258
|
|
|
303
259
|
this.logger.debug('[APP-COMP] initializeApp:: ', this.sidebarNav, this.detailNav);
|
|
304
|
-
|
|
260
|
+
|
|
305
261
|
this.translateToastMsgs();
|
|
306
262
|
|
|
307
263
|
// ---------------------------------------
|
|
308
264
|
// Watch to network status
|
|
309
265
|
// ---------------------------------------
|
|
310
266
|
this.watchToConnectionStatus();
|
|
311
|
-
// this.listenToUserIsSignedIn();
|
|
312
|
-
|
|
313
|
-
|
|
314
267
|
});
|
|
315
268
|
}
|
|
316
269
|
|
|
317
|
-
// listenToUserIsSignedIn() {
|
|
318
|
-
// this.tiledeskAuthService.isOnline$
|
|
319
|
-
// .pipe(filter((isOnline) => isOnline !== null))
|
|
320
|
-
// .subscribe((isOnline: any) => {
|
|
321
|
-
// console.log('[APP-COMP] user isOnline: ', isOnline);
|
|
322
|
-
|
|
323
|
-
// // if (isOnline === false) {
|
|
324
|
-
// // this.events.publish('profileInfoButtonClick:logout', true);
|
|
325
|
-
// // }
|
|
326
|
-
// });
|
|
327
|
-
// }
|
|
328
|
-
|
|
329
|
-
|
|
330
270
|
|
|
331
271
|
watchToConnectionStatus() {
|
|
332
272
|
this.networkService.checkInternetFunc().subscribe(isOnline => {
|
|
@@ -352,7 +292,7 @@ export class AppComponent implements OnInit {
|
|
|
352
292
|
if (elemIonNavchildNodes.length === 0) {
|
|
353
293
|
this.logger.log('[APP-COMP] - watchToConnectionStatus - elemIonNavchildNodes HERE YES', elemIonNavchildNodes);
|
|
354
294
|
|
|
355
|
-
this.initializeApp('checkinternet');
|
|
295
|
+
// this.initializeApp('checkinternet');
|
|
356
296
|
this.executedInitializeAppByWatchConnection = true;
|
|
357
297
|
}
|
|
358
298
|
}, 2000);
|
|
@@ -366,7 +306,7 @@ export class AppComponent implements OnInit {
|
|
|
366
306
|
const childElementCount = elemIonRouterOutlet.childElementCount;
|
|
367
307
|
this.logger.log('[APP-COMP] - watchToConnectionStatus - mobile * childElementCount *', childElementCount)
|
|
368
308
|
if (childElementCount === 1) {
|
|
369
|
-
this.initializeApp('checkinternet');
|
|
309
|
+
// this.initializeApp('checkinternet');
|
|
370
310
|
this.executedInitializeAppByWatchConnection = true;
|
|
371
311
|
}
|
|
372
312
|
}, 2000);
|
|
@@ -415,19 +355,18 @@ export class AppComponent implements OnInit {
|
|
|
415
355
|
/**------- AUTHENTICATION FUNCTIONS --> START <--- +*/
|
|
416
356
|
private initAuthentication() {
|
|
417
357
|
const tiledeskToken = this.appStorageService.getItem('tiledeskToken')
|
|
418
|
-
|
|
358
|
+
console.log('[APP-COMP] >>> INIT-AUTHENTICATION !!! ')
|
|
419
359
|
this.logger.log('[APP-COMP] >>> initAuthentication tiledeskToken ', tiledeskToken)
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
this.logger.log('[APP-COMP] >>> initAuthentication currentUser ', currentUser)
|
|
360
|
+
// const currentUser = JSON.parse(this.appStorageService.getItem('currentUser'));
|
|
361
|
+
// this.logger.log('[APP-COMP] >>> initAuthentication currentUser ', currentUser)
|
|
423
362
|
if (tiledeskToken) {
|
|
424
363
|
this.logger.log('[APP-COMP] >>> initAuthentication I LOG IN WITH A TOKEN EXISTING IN THE LOCAL STORAGE OR WITH A TOKEN PASSED IN THE URL PARAMETERS <<<')
|
|
425
|
-
|
|
426
364
|
this.tiledeskAuthService.signInWithCustomToken(tiledeskToken).then(user => {
|
|
427
365
|
this.logger.log('[APP-COMP] >>> initAuthentication user ', user)
|
|
428
366
|
this.messagingAuthService.createCustomToken(tiledeskToken)
|
|
429
|
-
}).catch(error => {
|
|
430
|
-
|
|
367
|
+
}).catch(error => {
|
|
368
|
+
this.logger.error('[APP-COMP] initAuthentication SIGNINWITHCUSTOMTOKEN error::', error)
|
|
369
|
+
})
|
|
431
370
|
} else {
|
|
432
371
|
this.logger.warn('[APP-COMP] >>> I AM NOT LOGGED IN <<<')
|
|
433
372
|
const that = this;
|
|
@@ -439,24 +378,11 @@ export class AppComponent implements OnInit {
|
|
|
439
378
|
}
|
|
440
379
|
}, 1000);
|
|
441
380
|
}
|
|
442
|
-
|
|
443
|
-
// this.route.queryParams.subscribe(params => {
|
|
444
|
-
// this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN params 1', params)
|
|
445
|
-
// if (params.jwt) {
|
|
446
|
-
// this.isOnline = false;
|
|
447
|
-
// this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN params 2', params)
|
|
448
|
-
// this.tiledeskAuthService.signInWithCustomToken(params.jwt).then(user => {
|
|
449
|
-
// this.messagingAuthService.createCustomToken(params.jwt)
|
|
450
|
-
// }).catch(error => {
|
|
451
|
-
// this.logger.error('[APP-COMP] SIGNINWITHCUSTOMTOKEN error::', error)
|
|
452
|
-
// })
|
|
453
|
-
// }
|
|
454
|
-
// });
|
|
455
381
|
}
|
|
456
382
|
|
|
457
|
-
|
|
383
|
+
checkTokenAndGoOffline() {
|
|
458
384
|
let token = this.appStorageService.getItem('tiledeskToken');
|
|
459
|
-
this.logger.info('[APP-COMP] *****
|
|
385
|
+
this.logger.info('[APP-COMP] ***** checkTokenAndGoOffline - stored token *****', token);
|
|
460
386
|
if (!token) {
|
|
461
387
|
this.goOffLine()
|
|
462
388
|
}
|
|
@@ -470,15 +396,15 @@ export class AppComponent implements OnInit {
|
|
|
470
396
|
* @param user
|
|
471
397
|
*/
|
|
472
398
|
goOnLine = () => {
|
|
473
|
-
this.isOnline = true;
|
|
474
|
-
this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO
|
|
399
|
+
// this.isOnline = true;
|
|
400
|
+
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO-ONLINE isOnline ', this.isOnline);
|
|
475
401
|
|
|
476
402
|
|
|
477
403
|
clearTimeout(this.timeModalLogin);
|
|
478
404
|
const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
|
|
479
405
|
const currentUser = this.tiledeskAuthService.getCurrentUser();
|
|
480
406
|
// this.logger.printDebug('APP-COMP - goOnLine****', currentUser);
|
|
481
|
-
this.logger.log('[APP-COMP] -
|
|
407
|
+
this.logger.log('[APP-COMP] - GO-ONLINE - currentUser ', currentUser);
|
|
482
408
|
this.chatManager.setTiledeskToken(tiledeskToken);
|
|
483
409
|
this.chatManager.setCurrentUser(currentUser);
|
|
484
410
|
// ----------------------------------------------
|
|
@@ -509,8 +435,8 @@ export class AppComponent implements OnInit {
|
|
|
509
435
|
}
|
|
510
436
|
|
|
511
437
|
goOffLine = () => {
|
|
512
|
-
this.logger.log('[APP-COMP] ************** goOffLine:', this.authModal);
|
|
513
|
-
this.isOnline = false;
|
|
438
|
+
this.logger.log('[APP-COMP] ************** goOffLine authModal:', this.authModal);
|
|
439
|
+
// this.isOnline = false;
|
|
514
440
|
// this.conversationsHandlerService.conversations = [];
|
|
515
441
|
|
|
516
442
|
this.chatManager.setTiledeskToken(null);
|
|
@@ -671,20 +597,30 @@ export class AppComponent implements OnInit {
|
|
|
671
597
|
this.logger.log('initialize FROM [APP-COMP] - initSubscriptions');
|
|
672
598
|
|
|
673
599
|
|
|
674
|
-
|
|
675
|
-
|
|
600
|
+
// ---------------------------------------------------------------------------------------------------
|
|
601
|
+
// Protecting from multiple subsciptions due to multiple app initializations (call to initializeApp())
|
|
602
|
+
// Only one subscriber x application allowed
|
|
603
|
+
// ---------------------------------------------------------------------------------------------------
|
|
604
|
+
if (this.BSAuthStateChangedSubscriptionRef) {
|
|
605
|
+
this.logger.log('initialize FROM [APP-COMP] - BSAuthStateChanged ALREADY SUBSCRIBED');
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
this.BSAuthStateChangedSubscriptionRef = this.messagingAuthService.BSAuthStateChanged
|
|
610
|
+
// .pipe(takeUntil(this.unsubscribe$))
|
|
676
611
|
.pipe(filter((state) => state !== null))
|
|
677
612
|
.subscribe((state: any) => {
|
|
678
|
-
|
|
679
|
-
this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged isOnline', this.isOnline);
|
|
613
|
+
console.log('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged state', state);
|
|
614
|
+
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged isOnline', this.isOnline);
|
|
680
615
|
if (state && state === AUTH_STATE_ONLINE) {
|
|
681
|
-
const user = this.tiledeskAuthService.getCurrentUser();
|
|
682
|
-
if (this.isOnline === false) {
|
|
683
|
-
|
|
684
|
-
|
|
616
|
+
// const user = this.tiledeskAuthService.getCurrentUser();
|
|
617
|
+
// if (this.isOnline === false) {
|
|
618
|
+
// if (AUTH_STATE_ONLINE) {
|
|
619
|
+
this.goOnLine();
|
|
620
|
+
// }
|
|
685
621
|
} else if (state === AUTH_STATE_OFFLINE) {
|
|
686
|
-
|
|
687
|
-
this.
|
|
622
|
+
this.checkTokenAndGoOffline() //se c'è un tiledeskToken salvato, allora aspetta, altrimenti vai offline
|
|
623
|
+
// this.goOffLine()
|
|
688
624
|
}
|
|
689
625
|
}, error => {
|
|
690
626
|
this.logger.error('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged * error * ', error)
|
|
@@ -922,20 +858,35 @@ export class AppComponent implements OnInit {
|
|
|
922
858
|
}
|
|
923
859
|
|
|
924
860
|
if (this.appStorageService.getItem('tiledeskToken') === null) {
|
|
925
|
-
|
|
861
|
+
console.log('[APP-COMP] - onStorageChanged tiledeskToken is null - RUN LOGOUT')
|
|
926
862
|
this.tiledeskAuthService.logOut()
|
|
927
863
|
this.messagingAuthService.logout();
|
|
928
864
|
this.events.publish('profileInfoButtonClick:logout', true);
|
|
929
|
-
this.isOnline = false;
|
|
865
|
+
// this.isOnline = false;
|
|
930
866
|
}
|
|
931
867
|
else {
|
|
932
868
|
const currentUser = this.tiledeskAuthService.getCurrentUser();
|
|
869
|
+
console.log('[APP-COMP] - X - onStorageChanged currentUser', currentUser)
|
|
870
|
+
|
|
871
|
+
const currentToken = this.tiledeskAuthService.getTiledeskToken();
|
|
872
|
+
console.log('[APP-COMP] - onStorageChanged currentToken', currentToken)
|
|
873
|
+
if (this.appStorageService.getItem('tiledeskToken') !== null && currentToken !== this.appStorageService.getItem('tiledeskToken')) {
|
|
874
|
+
|
|
875
|
+
console.log('[APP-COMP] - onStorageChanged wentOnline 2')
|
|
876
|
+
// DEALLOCO RISORSE OCCUPATE
|
|
877
|
+
this.messagingAuthService.logout();
|
|
878
|
+
this.appStorageService.removeItem('currentUser')
|
|
879
|
+
this.tiledeskAuthService.setCurrentUser(null);
|
|
880
|
+
// this.unsubscribe$.next();
|
|
881
|
+
// this.unsubscribe$.complete();
|
|
882
|
+
this.initializeApp('onstoragechanged');
|
|
933
883
|
|
|
934
|
-
|
|
935
|
-
this.logger.log('[APP-COMP] - onStorageChanged currentUser', currentUser)
|
|
936
|
-
// console.log('[APP-COMP] - onStorageChanged wentOnline 2', this.wentOnline)
|
|
884
|
+
console.log('[APP-COMP] - that.BSAuthStateChanged ', this.messagingAuthService.BSAuthStateChanged)
|
|
937
885
|
|
|
938
|
-
|
|
886
|
+
// console.log('[APP-COMP] onAuthStateChanged HERE !!! ')
|
|
887
|
+
// firebase.auth().onAuthStateChanged(user => {
|
|
888
|
+
// console.log('[APP-COMP] onAuthStateChanged', user)
|
|
889
|
+
// })
|
|
939
890
|
|
|
940
891
|
}
|
|
941
892
|
}
|
|
@@ -9,8 +9,8 @@ export abstract class AppStorageService {
|
|
|
9
9
|
abstract initialize(storagePrefix: string, persistence: string, projectID?: string): void;
|
|
10
10
|
abstract getItem(key: string): any;
|
|
11
11
|
abstract setItem(key: string, value: any): void;
|
|
12
|
-
abstract getItemWithoutProjectID(key: string): any;
|
|
13
|
-
abstract setItemWithoutProjectID(key: string, value: any): void;
|
|
12
|
+
// abstract getItemWithoutProjectID(key: string): any; // deprecated !Not tUsed
|
|
13
|
+
// abstract setItemWithoutProjectID(key: string, value: any): void; // deprecated !Not tUsed
|
|
14
14
|
abstract removeItem(key: string): void;
|
|
15
15
|
abstract clear(): void;
|
|
16
16
|
|
|
@@ -64,7 +64,7 @@ export class FirebaseArchivedConversationsHandler extends ArchivedConversationsH
|
|
|
64
64
|
* inizializzo conversations handler
|
|
65
65
|
*/
|
|
66
66
|
initialize(tenant: string, userId: string, translationMap: Map<string, string>) {
|
|
67
|
-
this.logger.info('
|
|
67
|
+
this.logger.info('initialize FROM [APP-COMP] - FIREBASEArchivedConversationsHandlerSERVICE] tenant ', tenant, ' - userId: ', userId, ' - translationMap: ', translationMap)
|
|
68
68
|
this.tenant = tenant;
|
|
69
69
|
this.loggedUserId = userId;
|
|
70
70
|
this.translationMap = translationMap;
|
|
@@ -33,6 +33,7 @@ import { LoggerService } from '../abstract/logger.service';
|
|
|
33
33
|
import { Observable, Observer, fromEvent, merge } from 'rxjs';
|
|
34
34
|
import { map } from 'rxjs/operators'
|
|
35
35
|
import { Network } from '@ionic-native/network/ngx';
|
|
36
|
+
|
|
36
37
|
// @Injectable({ providedIn: 'root' })
|
|
37
38
|
@Injectable()
|
|
38
39
|
export class FirebaseAuthService extends MessagingAuthService {
|
|
@@ -60,40 +61,58 @@ export class FirebaseAuthService extends MessagingAuthService {
|
|
|
60
61
|
|
|
61
62
|
status = 'ONLINE';
|
|
62
63
|
isConnected = true;
|
|
63
|
-
|
|
64
|
+
unsubscribe: any;
|
|
64
65
|
constructor(
|
|
65
66
|
public http: HttpClient,
|
|
66
67
|
private network: Network,
|
|
67
68
|
private connectionService: ConnectionService
|
|
68
69
|
) {
|
|
69
70
|
super();
|
|
71
|
+
// this.initialize()
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
/**
|
|
73
75
|
*
|
|
74
76
|
*/
|
|
75
77
|
initialize() {
|
|
76
|
-
|
|
78
|
+
console.log('initialize FROM [APP-COMP] [FIREBASEAuthSERVICE]')
|
|
77
79
|
this.SERVER_BASE_URL = this.getBaseUrl();
|
|
78
80
|
this.URL_TILEDESK_CREATE_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'chat21/firebase/auth/createCustomToken';
|
|
79
81
|
this.logger.info('[FIREBASEAuthSERVICE] - initialize URL_TILEDESK_CREATE_CUSTOM_TOKEN ', this.URL_TILEDESK_CREATE_CUSTOM_TOKEN)
|
|
80
|
-
// this.URL_TILEDESK_SIGNIN = this.SERVER_BASE_URL + 'auth/signin';
|
|
81
|
-
// this.URL_TILEDESK_SIGNIN_ANONYMOUSLY = this.SERVER_BASE_URL + 'auth/signinAnonymously'
|
|
82
|
-
// this.URL_TILEDESK_SIGNIN_WITH_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'auth/signinWithCustomToken';
|
|
83
|
-
// this.checkIsAuth();
|
|
84
|
-
|
|
85
|
-
// this.createOnline$().subscribe((isOnline) =>{
|
|
86
|
-
// console.log('FIREBASEAuthSERVICE] isOnline ', isOnline);
|
|
87
|
-
// if (isOnline === true ) {
|
|
88
|
-
// this.onAuthStateChanged();
|
|
89
|
-
// }
|
|
90
|
-
// })
|
|
91
|
-
// this.checkInternetConnection()
|
|
92
82
|
|
|
93
|
-
|
|
83
|
+
|
|
84
|
+
let firebasePersistence;
|
|
85
|
+
// console.log('FB-AUTH firebasePersistence', this.getPersistence())
|
|
86
|
+
switch (this.getPersistence()) {
|
|
87
|
+
case 'SESSION': {
|
|
88
|
+
firebasePersistence = firebase.auth.Auth.Persistence.SESSION;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'LOCAL': {
|
|
92
|
+
firebasePersistence = firebase.auth.Auth.Persistence.LOCAL;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'NONE': {
|
|
96
|
+
firebasePersistence = firebase.auth.Auth.Persistence.NONE;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
default: {
|
|
100
|
+
firebasePersistence = firebase.auth.Auth.Persistence.NONE;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
firebase.auth().setPersistence(firebasePersistence).then(async () => {
|
|
105
|
+
console.log('[FIREBASEAuthSERVICE] firebasePersistence ', firebasePersistence)
|
|
106
|
+
this.onAuthStateChanged();
|
|
107
|
+
})
|
|
108
|
+
.catch((error) => {
|
|
109
|
+
this.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
|
|
94
113
|
}
|
|
95
114
|
|
|
96
|
-
checkInternetConnection
|
|
115
|
+
checkInternetConnection() {
|
|
97
116
|
this.logger.log('[FIREBASEAuthSERVICE] - checkInternetConnection');
|
|
98
117
|
// let connectSubscription = this.network.onConnect().subscribe(() => {
|
|
99
118
|
// this.logger.log('[FIREBASEAuthSERVICE] - network connected!');
|
|
@@ -107,28 +126,28 @@ export class FirebaseAuthService extends MessagingAuthService {
|
|
|
107
126
|
// }, 3000);
|
|
108
127
|
// });
|
|
109
128
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
|
|
130
|
+
// this.connectionService.monitor().subscribe(isConnected => {
|
|
131
|
+
// this.isConnected = isConnected;
|
|
132
|
+
// this.logger.log('[FIREBASEAuthSERVICE] - checkInternetConnection isConnected', isConnected);
|
|
133
|
+
// if (this.isConnected) {
|
|
134
|
+
// this.status = "ONLINE";
|
|
135
|
+
|
|
136
|
+
// // this.onAuthStateChanged();
|
|
137
|
+
// firebase.auth().onAuthStateChanged(user => {
|
|
138
|
+
// this.logger.log('[FIREBASEAuthSERVICE] checkInternetConnection onAuthStateChanged', user)
|
|
139
|
+
// })
|
|
140
|
+
// }
|
|
141
|
+
// else {
|
|
142
|
+
// this.status = "OFFLINE";
|
|
143
|
+
// // this.onAuthStateChanged();
|
|
144
|
+
// firebase.auth().onAuthStateChanged(user => {
|
|
145
|
+
// this.logger.log('[FIREBASEAuthSERVICE] checkInternetConnection onAuthStateChanged', user)
|
|
146
|
+
// })
|
|
147
|
+
// }
|
|
148
|
+
// })
|
|
149
|
+
|
|
150
|
+
|
|
132
151
|
}
|
|
133
152
|
|
|
134
153
|
// createOnline$() {
|
|
@@ -178,19 +197,37 @@ export class FirebaseAuthService extends MessagingAuthService {
|
|
|
178
197
|
*/
|
|
179
198
|
onAuthStateChanged() {
|
|
180
199
|
const that = this;
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
|
|
201
|
+
// ---------------------------------------------------------------------------------------------------
|
|
202
|
+
// Protecting from multiple subsciptions due to multiple app initializations (call to initializeApp())
|
|
203
|
+
// Only one subscriber x application allowed
|
|
204
|
+
// ---------------------------------------------------------------------------------------------------
|
|
205
|
+
if (this.unsubscribe) {
|
|
206
|
+
console.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged ALREADY SUBSCRIBED')
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
this.unsubscribe = firebase.auth().onAuthStateChanged(user => {
|
|
211
|
+
console.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged', user)
|
|
183
212
|
if (!user) {
|
|
184
213
|
this.logger.log('[FIREBASEAuthSERVICE] 1 - PASSO OFFLINE AL CHAT MANAGER')
|
|
185
214
|
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged user ', user)
|
|
186
|
-
|
|
215
|
+
|
|
187
216
|
that.BSAuthStateChanged.next('offline');
|
|
217
|
+
// console.log('initialize FROM [APP-COMP] that.BSAuthStateChanged ', that.BSAuthStateChanged)
|
|
188
218
|
} else {
|
|
189
219
|
this.logger.log('[FIREBASEAuthSERVICE] 2 - PASSO ONLINE AL CHAT MANAGER')
|
|
190
220
|
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged user ', user)
|
|
191
221
|
that.BSAuthStateChanged.next('online');
|
|
192
222
|
}
|
|
223
|
+
}, error => {
|
|
224
|
+
this.logger.error('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged * error * ', error)
|
|
225
|
+
}, () => {
|
|
226
|
+
this.logger.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged *** complete *** ');
|
|
227
|
+
|
|
193
228
|
});
|
|
229
|
+
|
|
230
|
+
|
|
194
231
|
}
|
|
195
232
|
|
|
196
233
|
/**
|
|
@@ -198,37 +235,34 @@ export class FirebaseAuthService extends MessagingAuthService {
|
|
|
198
235
|
* @param token
|
|
199
236
|
*/
|
|
200
237
|
signInFirebaseWithCustomToken(token: string): Promise<any> {
|
|
201
|
-
const that = this;
|
|
202
|
-
let firebasePersistence;
|
|
203
|
-
// console.log('FB-AUTH firebasePersistence', this.getPersistence())
|
|
204
|
-
switch (this.getPersistence()) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
return firebase.auth().setPersistence(firebasePersistence).then(async () => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}).catch((error) => {
|
|
227
|
-
that.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
|
|
228
|
-
// that.firebaseSignInWithCustomToken.next(null);
|
|
229
|
-
});
|
|
238
|
+
// const that = this;
|
|
239
|
+
// let firebasePersistence;
|
|
240
|
+
// // console.log('FB-AUTH firebasePersistence', this.getPersistence())
|
|
241
|
+
// switch (this.getPersistence()) {
|
|
242
|
+
// case 'SESSION': {
|
|
243
|
+
// firebasePersistence = firebase.auth.Auth.Persistence.SESSION;
|
|
244
|
+
// break;
|
|
245
|
+
// }
|
|
246
|
+
// case 'LOCAL': {
|
|
247
|
+
// firebasePersistence = firebase.auth.Auth.Persistence.LOCAL;
|
|
248
|
+
// break;
|
|
249
|
+
// }
|
|
250
|
+
// case 'NONE': {
|
|
251
|
+
// firebasePersistence = firebase.auth.Auth.Persistence.NONE;
|
|
252
|
+
// break;
|
|
253
|
+
// }
|
|
254
|
+
// default: {
|
|
255
|
+
// firebasePersistence = firebase.auth.Auth.Persistence.NONE;
|
|
256
|
+
// break;
|
|
257
|
+
// }
|
|
258
|
+
// }
|
|
259
|
+
// return firebase.auth().setPersistence(firebasePersistence).then(async () => {
|
|
260
|
+
return firebase.auth().signInWithCustomToken(token).then(async (user) => {
|
|
261
|
+
|
|
262
|
+
// that.firebaseSignInWithCustomToken.next(response);
|
|
230
263
|
}).catch((error) => {
|
|
231
|
-
|
|
264
|
+
this.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
|
|
265
|
+
// that.firebaseSignInWithCustomToken.next(null);
|
|
232
266
|
});
|
|
233
267
|
}
|
|
234
268
|
|
|
@@ -275,6 +309,8 @@ export class FirebaseAuthService extends MessagingAuthService {
|
|
|
275
309
|
// cancello token
|
|
276
310
|
// this.appStorage.removeItem('tiledeskToken');
|
|
277
311
|
//localStorage.removeItem('firebaseToken');
|
|
312
|
+
|
|
313
|
+
|
|
278
314
|
that.BSSignOut.next(true);
|
|
279
315
|
}).catch((error) => {
|
|
280
316
|
that.logger.error('[FIREBASEAuthSERVICE] signOut error: ', error);
|
|
@@ -322,9 +358,11 @@ export class FirebaseAuthService extends MessagingAuthService {
|
|
|
322
358
|
logout() {
|
|
323
359
|
this.logger.log('[FIREBASEAuthSERVICE] logout');
|
|
324
360
|
this.BSAuthStateChanged.next(null);
|
|
361
|
+
|
|
325
362
|
// cancello token firebase dal local storage e da firebase
|
|
326
363
|
// dovrebbe scattare l'evento authchangeStat
|
|
327
364
|
this.signOut();
|
|
365
|
+
// this.unsubscribe();
|
|
328
366
|
}
|
|
329
367
|
|
|
330
368
|
}
|
|
@@ -157,21 +157,16 @@ export class FirebaseNotifications extends NotificationsService {
|
|
|
157
157
|
|
|
158
158
|
removeNotificationsInstance(callback: (string) => void) {
|
|
159
159
|
var self = this;
|
|
160
|
-
firebase.auth().onAuthStateChanged(function (user) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
} else {
|
|
171
|
-
self.logger.debug('[FIREBASE-NOTIFICATIONS] - No FB user is signed in. ', user)
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
160
|
+
// firebase.auth().onAuthStateChanged(function (user) {
|
|
161
|
+
// if (user) {
|
|
162
|
+
// self.logger.debug('[FIREBASE-NOTIFICATIONS] - FB User is signed in. ', user)
|
|
163
|
+
// self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.userId', self.userId);
|
|
164
|
+
// self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > FCMcurrentToken', self.FCMcurrentToken);
|
|
165
|
+
// // this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.tenant', this.tenant);
|
|
166
|
+
// } else {
|
|
167
|
+
// self.logger.debug('[FIREBASE-NOTIFICATIONS] - No FB user is signed in. ', user)
|
|
168
|
+
// }
|
|
169
|
+
// });
|
|
175
170
|
const urlNodeFirebase = '/apps/' + self.tenant
|
|
176
171
|
const connectionsRefinstancesId = urlNodeFirebase + '/users/' + self.userId + '/instances/'
|
|
177
172
|
self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> connectionsRefinstancesId ', connectionsRefinstancesId);
|
|
@@ -194,7 +189,6 @@ export class FirebaseNotifications extends NotificationsService {
|
|
|
194
189
|
})
|
|
195
190
|
}
|
|
196
191
|
|
|
197
|
-
|
|
198
192
|
}
|
|
199
193
|
|
|
200
194
|
// removeNotificationsInstance() {
|
|
@@ -6,35 +6,35 @@ import { LoggerService } from './abstract/logger.service';
|
|
|
6
6
|
import { LoggerInstance } from './logger/loggerInstance';
|
|
7
7
|
|
|
8
8
|
@Injectable()
|
|
9
|
-
export class LocalSessionStorage extends AppStorageService{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
export class LocalSessionStorage extends AppStorageService {
|
|
10
|
+
|
|
11
|
+
private storagePrefix: string = STORAGE_PREFIX;
|
|
12
|
+
private projectID: string;
|
|
13
|
+
private persistence: string;
|
|
14
|
+
private logger: LoggerService = LoggerInstance.getInstance();
|
|
15
|
+
|
|
16
|
+
initialize(storagePrefix: string, persistence: string, projectID: string): void {
|
|
17
|
+
this.storagePrefix = storagePrefix;
|
|
18
|
+
this.projectID = projectID;
|
|
19
|
+
this.persistence = persistence;
|
|
20
|
+
// this.persistence = 'LOCAL';
|
|
21
|
+
// this.logger.info('[LocalSessionStorage] - initialize ', this.storagePrefix, this.persistence, this.projectID)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** GET item in local/session storage from key value
|
|
25
25
|
* @param key
|
|
26
26
|
*/
|
|
27
27
|
getItem(key: string) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
let prefix;
|
|
29
|
+
try {
|
|
30
|
+
// const sv = 'sv' + environment.shemaVersion + '_';
|
|
31
|
+
// prefix = prefix + sv;
|
|
32
|
+
prefix = this.storagePrefix + '_';
|
|
33
|
+
} catch (e) {
|
|
34
|
+
this.logger.error('[LocalSessionStorage] getItem - Error :' + e);
|
|
35
|
+
}
|
|
36
|
+
const newKey = prefix + this.projectID + '_' + key;
|
|
37
|
+
return this.getValueForKey(newKey);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** SET new item in local/session storage
|
|
@@ -42,173 +42,174 @@ export class LocalSessionStorage extends AppStorageService{
|
|
|
42
42
|
* @param value
|
|
43
43
|
*/
|
|
44
44
|
setItem(key: string, value: any): void {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
// this.removeItem(key);
|
|
46
|
+
let prefix;
|
|
47
|
+
try {
|
|
48
|
+
// const sv = 'sv' + environment.shemaVersion + '_';
|
|
49
|
+
// prefix = prefix + sv;
|
|
50
|
+
prefix = this.storagePrefix + '_';
|
|
51
|
+
} catch (e) {
|
|
52
|
+
this.logger.error('[LocalSessionStorage] setItem > Error :' + e);
|
|
53
|
+
}
|
|
54
|
+
const newKey = prefix + this.projectID + '_' + key;
|
|
55
|
+
this.saveValueForKey(newKey, value);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** GET item in local/session storage from key value without project id SUFFIX
|
|
59
|
-
*
|
|
59
|
+
* @param key
|
|
60
|
+
* @deprecated
|
|
60
61
|
*/
|
|
61
|
-
getItemWithoutProjectID(key: string) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
62
|
+
// getItemWithoutProjectID(key: string) {
|
|
63
|
+
// let prefix;
|
|
64
|
+
// try {
|
|
65
|
+
// // const sv = 'sv' + environment.shemaVersion + '_';
|
|
66
|
+
// // prefix = prefix + sv;
|
|
67
|
+
// prefix = this.storagePrefix + '_';
|
|
68
|
+
// } catch (e) {
|
|
69
|
+
// this.logger.error('[LocalSessionStorage] getItemWithoutProjectID > Error :' + e);
|
|
70
|
+
// }
|
|
71
|
+
// const newKey = prefix + key;
|
|
72
|
+
// return this.getValueForKey(newKey);
|
|
73
|
+
// }
|
|
73
74
|
|
|
74
75
|
/** SET new item in local/session storage without project id SUFFIX
|
|
75
76
|
* @param key
|
|
76
77
|
* @param value
|
|
77
78
|
*/
|
|
78
|
-
setItemWithoutProjectID(key: string, value: any): void {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
79
|
+
// setItemWithoutProjectID(key: string, value: any): void {
|
|
80
|
+
// this.removeItem(key);
|
|
81
|
+
// let prefix = STORAGE_PREFIX;
|
|
82
|
+
// try {
|
|
83
|
+
// // const sv = 'sv' + environment.shemaVersion + '_';
|
|
84
|
+
// // prefix = prefix + sv;
|
|
85
|
+
// prefix = this.storagePrefix + '_';
|
|
86
|
+
// } catch (e) {
|
|
87
|
+
// this.logger.error('[LocalSessionStorage] setItemWithoutProjectID > Error :' + e);
|
|
88
|
+
// }
|
|
89
|
+
// const newKey = prefix + key;
|
|
90
|
+
// this.saveValueForKey(newKey, value);
|
|
91
|
+
// }
|
|
91
92
|
|
|
92
93
|
removeItem(key: string): void {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
let prefix;
|
|
95
|
+
try {
|
|
96
|
+
// const sv = 'sv' + environment.shemaVersion + '_';
|
|
97
|
+
// prefix = prefix + sv;
|
|
98
|
+
prefix = this.storagePrefix + '_';
|
|
99
|
+
} catch (e) {
|
|
100
|
+
this.logger.error('[LocalSessionStorage] removeItem > Error :' + e);
|
|
101
|
+
}
|
|
102
|
+
const newKey = prefix + this.projectID + '_' + key;
|
|
103
|
+
return this.removeItemForKey(newKey);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
clear(): void {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (let i = 0; i < arrayKey.length; i++) {
|
|
124
|
-
// localStorage.removeItem(arrayKey[i]);
|
|
125
|
-
this.removeItemForKey(arrayKey[i]);
|
|
107
|
+
let prefix;
|
|
108
|
+
try {
|
|
109
|
+
// const sv = 'sv' + environment.shemaVersion + '_';
|
|
110
|
+
// prefix = prefix + sv;
|
|
111
|
+
prefix = this.storagePrefix + '_';
|
|
112
|
+
} catch (e) {
|
|
113
|
+
this.logger.error('[LocalSessionStorage] clear > Error :' + e);
|
|
114
|
+
}
|
|
115
|
+
const prefixKey = prefix + this.projectID
|
|
116
|
+
const arrayKey: Array<string> = [];
|
|
117
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
118
|
+
const key = localStorage.key(i);
|
|
119
|
+
if (key.indexOf(prefixKey) !== -1) {
|
|
120
|
+
arrayKey.push(key);
|
|
126
121
|
}
|
|
127
|
-
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (let i = 0; i < arrayKey.length; i++) {
|
|
125
|
+
// localStorage.removeItem(arrayKey[i]);
|
|
126
|
+
this.removeItemForKey(arrayKey[i]);
|
|
127
|
+
}
|
|
128
|
+
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
|
|
131
132
|
// ---------- PRIVATE METHODS start --------------- //
|
|
132
133
|
|
|
133
134
|
private getValueForKey(key) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
} else if (this.persistence === 'none' || this.persistence === 'NONE') {
|
|
135
|
+
if (this.persistence === 'local' || this.persistence === 'LOCAL') {
|
|
136
|
+
if (supports_html5_storage()) {
|
|
137
|
+
return localStorage.getItem(key);
|
|
138
|
+
} else {
|
|
139
|
+
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
} else if (this.persistence === 'session' || this.persistence === 'SESSION') {
|
|
143
|
+
if (supports_html5_session()) {
|
|
144
|
+
return sessionStorage.getItem(key);
|
|
145
|
+
} else {
|
|
146
|
+
this.logger.warn('sessionStorage is not defind. Storage disabled');
|
|
149
147
|
return null;
|
|
148
|
+
}
|
|
149
|
+
} else if (this.persistence === 'none' || this.persistence === 'NONE') {
|
|
150
|
+
return null;
|
|
151
|
+
} else {
|
|
152
|
+
if (supports_html5_storage()) {
|
|
153
|
+
return localStorage.getItem(key);
|
|
150
154
|
} else {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
} else {
|
|
154
|
-
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
155
|
+
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
156
|
+
return null;
|
|
157
157
|
}
|
|
158
|
+
}
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
private saveValueForKey(key, value) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
} else if (this.persistence === 'none' || this.persistence === 'NONE') {
|
|
162
|
+
if (this.persistence === 'local' || this.persistence === 'LOCAL') {
|
|
163
|
+
if (supports_html5_storage()) {
|
|
164
|
+
return localStorage.setItem(key, value);
|
|
165
|
+
} else {
|
|
166
|
+
this.logger.warn('localStorage is not defined. Storage disabled');
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
} else if (this.persistence === 'session' || this.persistence === 'SESSION') {
|
|
170
|
+
if (supports_html5_session()) {
|
|
171
|
+
return sessionStorage.setItem(key, value);
|
|
172
|
+
} else {
|
|
173
|
+
this.logger.warn('sessionStorage is not defined. Storage disabled');
|
|
176
174
|
return null;
|
|
175
|
+
}
|
|
176
|
+
} else if (this.persistence === 'none' || this.persistence === 'NONE') {
|
|
177
|
+
return null;
|
|
178
|
+
} else {
|
|
179
|
+
if (supports_html5_storage()) {
|
|
180
|
+
return localStorage.setItem(key, value);
|
|
177
181
|
} else {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
} else {
|
|
181
|
-
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
182
|
+
this.logger.warn('localStorage is not defined. Storage disabled');
|
|
183
|
+
return null;
|
|
184
184
|
}
|
|
185
|
+
}
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
private removeItemForKey(key: string) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
} else if (this.persistence === 'none' || this.persistence === 'NONE') {
|
|
189
|
+
if (this.persistence === 'local' || this.persistence === 'LOCAL') {
|
|
190
|
+
if (supports_html5_storage()) {
|
|
191
|
+
return localStorage.removeItem(key);
|
|
192
|
+
} else {
|
|
193
|
+
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
} else if (this.persistence === 'session' || this.persistence === 'SESSION') {
|
|
197
|
+
if (supports_html5_session()) {
|
|
198
|
+
return sessionStorage.removeItem(key);
|
|
199
|
+
} else {
|
|
200
|
+
this.logger.warn('sessionStorage is not defind. Storage disabled');
|
|
203
201
|
return null;
|
|
202
|
+
}
|
|
203
|
+
} else if (this.persistence === 'none' || this.persistence === 'NONE') {
|
|
204
|
+
return null;
|
|
205
|
+
} else {
|
|
206
|
+
if (supports_html5_storage()) {
|
|
207
|
+
return localStorage.removeItem(key);
|
|
204
208
|
} else {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
} else {
|
|
208
|
-
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
209
|
+
this.logger.warn('localStorage is not defind. Storage disabled');
|
|
210
|
+
return null;
|
|
211
211
|
}
|
|
212
|
+
}
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
}
|