]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-edit/video-update.component.ts
Fix video channel update with an admin account
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-update.component.ts
index 73e2764c6692a01bfc6c7c6b622edcb52c88e13e..00c2ed3f11bc69c5cc2b6d07933fdf76084de4cf 100644 (file)
@@ -1,9 +1,9 @@
+import { map, switchMap } from 'rxjs/operators'
 import { Component, OnInit } from '@angular/core'
 import { FormBuilder, FormGroup } from '@angular/forms'
 import { ActivatedRoute, Router } from '@angular/router'
 import { LoadingBarService } from '@ngx-loading-bar/core'
 import { NotificationsService } from 'angular2-notifications'
-import 'rxjs/add/observable/forkJoin'
 import { VideoPrivacy } from '../../../../../shared/models/videos'
 import { ServerService } from '../../core'
 import { AuthService } from '../../core/auth'
@@ -11,14 +11,13 @@ import { FormReactive } from '../../shared'
 import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message'
 import { VideoEdit } from '../../shared/video/video-edit.model'
 import { VideoService } from '../../shared/video/video.service'
-import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
+import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
 
 @Component({
   selector: 'my-videos-update',
   styleUrls: [ './shared/video-edit.component.scss' ],
   templateUrl: './video-update.component.html'
 })
-
 export class VideoUpdateComponent extends FormReactive implements OnInit {
   video: VideoEdit
 
@@ -37,7 +36,8 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
     private serverService: ServerService,
     private videoService: VideoService,
     private authService: AuthService,
-    private loadingBar: LoadingBarService
+    private loadingBar: LoadingBarService,
+    private videoChannelService: VideoChannelService
   ) {
     super()
   }
@@ -53,38 +53,47 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
     this.serverService.videoPrivaciesLoaded
       .subscribe(() => this.videoPrivacies = this.serverService.getVideoPrivacies())
 
-    const uuid: string = this.route.snapshot.params['uuid']
+    const uuid: string = this.route.snapshot.params[ 'uuid' ]
     this.videoService.getVideo(uuid)
-      .switchMap(video => {
-        return this.videoService
-          .loadCompleteDescription(video.descriptionPath)
-          .map(description => Object.assign(video, { description }))
-      })
-      .subscribe(
-        video => {
-          this.video = new VideoEdit(video)
-
-          populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
-            .catch(err => console.error(err))
-
-          // We cannot set private a video that was not private
-          if (video.privacy.id !== VideoPrivacy.PRIVATE) {
-            const newVideoPrivacies = []
-            for (const p of this.videoPrivacies) {
-              if (p.id !== VideoPrivacy.PRIVATE) newVideoPrivacies.push(p)
+        .pipe(
+          switchMap(video => {
+            return this.videoService
+                       .loadCompleteDescription(video.descriptionPath)
+                       .pipe(map(description => Object.assign(video, { description })))
+          }),
+          switchMap(video => {
+            return this.videoChannelService
+                       .listAccountVideoChannels(video.account.id)
+                       .pipe(
+                         map(result => result.data),
+                         map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName }))),
+                         map(videoChannels => ({ video, videoChannels }))
+                       )
+          })
+        )
+        .subscribe(
+          ({ video, videoChannels }) => {
+            this.video = new VideoEdit(video)
+            this.userVideoChannels = videoChannels
+
+            // We cannot set private a video that was not private
+            if (video.privacy.id !== VideoPrivacy.PRIVATE) {
+              const newVideoPrivacies = []
+              for (const p of this.videoPrivacies) {
+                if (p.id !== VideoPrivacy.PRIVATE) newVideoPrivacies.push(p)
+              }
+
+              this.videoPrivacies = newVideoPrivacies
             }
 
-            this.videoPrivacies = newVideoPrivacies
-          }
+            this.hydrateFormFromVideo()
+          },
 
-          this.hydrateFormFromVideo()
-        },
-
-        err => {
-          console.error(err)
-          this.notificationsService.error('Error', err.message)
-        }
-      )
+          err => {
+            console.error(err)
+            this.notificationsService.error('Error', err.message)
+          }
+        )
   }
 
   checkForm () {