Sfoglia il codice sorgente

[PushNotification] debug and enhancements

tigger 1 anno fa
parent
commit
20b1a6141c
1 ha cambiato i file con 26 aggiunte e 17 eliminazioni
  1. 26 17
      src/app/app.component.ts

+ 26 - 17
src/app/app.component.ts

@@ -22,6 +22,7 @@ import { PushNotificationDecorator as LeavePushNotif } from 'fis/leave/decorator
 import { FISMessaging } from 'fis/index';
 import { BusinessDataModule } from 'fis/business.data/business.data.module';
 import { NotificationService } from 'angularlib/notification/notification.service';
+import { DecoratorSubject } from 'fis-commons/decorator';
 
 @Component({
   selector: 'app-root',
@@ -107,23 +108,7 @@ export class AppComponent extends BaseComponent implements OnInit {
       this.pbTitle.setTitle(this.title);
     });
 
-    /**subsribe user changes and initiate timeout timer */
-    this.loginService.user$.pipe(untilDestroy(this)).subscribe((user:any) => {
-      if (user?.fisInfo) {
-        this.timeout.pipe(untilDestroy(this),takeUntil(this.loginService.loggedOut)).subscribe();
-        if (this.leavePushNotif$ === undefined) {
-          this.leavePushNotif$ = new LeavePushNotif(
-            this,
-            this.loginService,
-            this.messaging,
-            this.notification
-          ).subscribe();
-        }
-      } else {
-        if (this.leavePushNotif$) this.leavePushNotif$.unsubscribe();
-        this.leavePushNotif$ = undefined;
-      }
-    });
+    
 
     this.store.select(NOTIFICATION_STATE_TOKEN).pipe(untilDestroy(this)).subscribe({
       next: (state:any) => {
@@ -136,6 +121,14 @@ export class AppComponent extends BaseComponent implements OnInit {
     if (this.platform.ANDROID || this.platform.IOS) this.pwaPrompt();
   }
 
+  ngAfterViewInit() {
+    /**subsribe user changes and initiate timeout timer */
+    this.loginService.user$.pipe(untilDestroy(this)).subscribe((user:any) => {
+      if (user) this.timeout.pipe(untilDestroy(this),takeUntil(this.loginService.loggedOut)).subscribe();
+      this.subscribePushNotifications();
+    });
+  }
+
   /**
    * change application language
    * @param {string} language
@@ -179,4 +172,20 @@ export class AppComponent extends BaseComponent implements OnInit {
       disableInAppInstallPrompt();
     });
   }
+
+  private subscribePushNotifications() {
+    if (this.loginService.user?.fisInfo) {
+      if (this.leavePushNotif$ === undefined) {
+        this.leavePushNotif$ = new LeavePushNotif(
+          this,
+          this.loginService,
+          this.messaging,
+          this.notification
+        ).subscribe();
+      }
+    } else {
+      if (this.leavePushNotif$) this.leavePushNotif$.unsubscribe();
+      this.leavePushNotif$ = undefined;
+    }
+  }
 }