]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-update.resolver.ts
Move to sass @use
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-update.resolver.ts
index a391913d82df1d18ebf2904ebe1ff671ec834fdd..9172b78a88154a890b5711bb7de6cc0a4baf4b2f 100644 (file)
@@ -1,14 +1,18 @@
-import { forkJoin } from 'rxjs'
+import { forkJoin, of } from 'rxjs'
 import { map, switchMap } from 'rxjs/operators'
 import { Injectable } from '@angular/core'
 import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
-import { VideoCaptionService, VideoChannelService, VideoService } from '@app/shared/shared-main'
+import { AuthService } from '@app/core'
+import { listUserChannels } from '@app/helpers'
+import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
+import { LiveVideoService } from '@app/shared/shared-video-live'
 
 @Injectable()
 export class VideoUpdateResolver implements Resolve<any> {
   constructor (
     private videoService: VideoService,
-    private videoChannelService: VideoChannelService,
+    private liveVideoService: LiveVideoService,
+    private authService: AuthService,
     private videoCaptionService: VideoCaptionService
   ) {
   }
@@ -18,32 +22,28 @@ export class VideoUpdateResolver implements Resolve<any> {
 
     return this.videoService.getVideo({ videoId: uuid })
                .pipe(
-                 switchMap(video => {
-                   return forkJoin([
-                     this.videoService
-                         .loadCompleteDescription(video.descriptionPath)
-                         .pipe(map(description => Object.assign(video, { description }))),
+                 switchMap(video => forkJoin(this.buildVideoObservables(video))),
+                 map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo }))
+               )
+  }
 
-                     this.videoChannelService
-                         .listAccountVideoChannels(video.account)
-                         .pipe(
-                           map(result => result.data),
-                           map(videoChannels => videoChannels.map(c => ({
-                             id: c.id,
-                             label: c.displayName,
-                             support: c.support,
-                             avatarPath: c.avatar?.path
-                           })))
-                         ),
+  private buildVideoObservables (video: VideoDetails) {
+    return [
+      this.videoService
+        .loadCompleteDescription(video.descriptionPath)
+        .pipe(map(description => Object.assign(video, { description }))),
 
-                     this.videoCaptionService
-                         .listCaptions(video.id)
-                         .pipe(
-                           map(result => result.data)
-                         )
-                   ])
-                 }),
-                 map(([ video, videoChannels, videoCaptions ]) => ({ video, videoChannels, videoCaptions }))
-               )
+      listUserChannels(this.authService),
+
+      this.videoCaptionService
+        .listCaptions(video.id)
+        .pipe(
+          map(result => result.data)
+        ),
+
+      video.isLive
+          ? this.liveVideoService.getVideoLive(video.id)
+          : of(undefined)
+    ]
   }
 }