]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/app.component.ts
Add additional checks when importing a video
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
index 86b687173158fa97eae218557a5b2f89d802983c..a60138af9fc22f8d0edb4458376abe54de53f983 100644 (file)
@@ -1,5 +1,5 @@
 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
-import { forkJoin } from 'rxjs'
+import { forkJoin, delay } from 'rxjs'
 import { filter, first, map } from 'rxjs/operators'
 import { DOCUMENT, getLocaleDirection, PlatformLocation } from '@angular/common'
 import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core'
@@ -14,7 +14,8 @@ import {
   ScrollService,
   ServerService,
   ThemeService,
-  User
+  User,
+  UserLocalStorageService
 } from '@app/core'
 import { HooksService } from '@app/core/plugins/hooks.service'
 import { PluginService } from '@app/core/plugins/plugin.service'
@@ -70,6 +71,7 @@ export class AppComponent implements OnInit, AfterViewInit {
     private ngbConfig: NgbConfig,
     private loadingBar: LoadingBarService,
     private scrollService: ScrollService,
+    private userLocalStorage: UserLocalStorageService,
     public menu: MenuService
   ) {
     this.ngbConfig.animation = false
@@ -86,6 +88,8 @@ export class AppComponent implements OnInit, AfterViewInit {
   ngOnInit () {
     document.getElementById('incompatible-browser').className += ' browser-ok'
 
+    this.loadUser()
+
     this.serverConfig = this.serverService.getHTMLConfig()
 
     this.hooks.runAction('action:application.init', 'common')
@@ -223,7 +227,10 @@ export class AppComponent implements OnInit, AfterViewInit {
 
   private openModalsIfNeeded () {
     const userSub = this.authService.userInformationLoaded
-        .pipe(map(() => this.authService.getUser()))
+        .pipe(
+          delay(0), // Wait for modals creations
+          map(() => this.authService.getUser())
+        )
 
     // Admin modal
     userSub.pipe(
@@ -297,4 +304,15 @@ export class AppComponent implements OnInit, AfterViewInit {
       }, undefined, $localize`Go to the videos upload page`)
     ])
   }
+
+  private loadUser () {
+    const tokens = this.userLocalStorage.getTokens()
+    if (!tokens) return
+
+    const user = this.userLocalStorage.getLoggedInUser()
+    if (!user) return
+
+    // Initialize user
+    this.authService.buildAuthUser(user, tokens)
+  }
 }