allow limiting video-comments rss feeds to an account or video channel
[oweals/peertube.git] / client / src / app / +video-channels / video-channel-videos / video-channel-videos.component.ts
1 import { Subscription } from 'rxjs'
2 import { first, tap } from 'rxjs/operators'
3 import { Component, OnDestroy, OnInit } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
6 import { immutableAssign } from '@app/helpers'
7 import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
8 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
9 import { I18n } from '@ngx-translate/i18n-polyfill'
10
11 @Component({
12   selector: 'my-video-channel-videos',
13   templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html',
14   styleUrls: [
15     '../../shared/shared-video-miniature/abstract-video-list.scss',
16     './video-channel-videos.component.scss'
17   ]
18 })
19 export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
20   titlePage: string
21   loadOnInit = false
22
23   private videoChannel: VideoChannel
24   private videoChannelSub: Subscription
25
26   constructor (
27     protected i18n: I18n,
28     protected router: Router,
29     protected serverService: ServerService,
30     protected route: ActivatedRoute,
31     protected authService: AuthService,
32     protected userService: UserService,
33     protected notifier: Notifier,
34     protected confirmService: ConfirmService,
35     protected screenService: ScreenService,
36     protected storageService: LocalStorageService,
37     private videoChannelService: VideoChannelService,
38     private videoService: VideoService
39   ) {
40     super()
41
42     this.titlePage = this.i18n('Published videos')
43     this.displayOptions = {
44       ...this.displayOptions,
45       avatar: false
46     }
47   }
48
49   ngOnInit () {
50     super.ngOnInit()
51
52     // Parent get the video channel for us
53     this.videoChannelSub = this.videoChannelService.videoChannelLoaded
54                                .pipe(first())
55                                .subscribe(videoChannel => {
56                                  this.videoChannel = videoChannel
57
58                                  this.reloadVideos()
59                                  this.generateSyndicationList()
60                                })
61   }
62
63   ngOnDestroy () {
64     if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
65
66     super.ngOnDestroy()
67   }
68
69   getVideosObservable (page: number) {
70     const newPagination = immutableAssign(this.pagination, { currentPage: page })
71
72     return this.videoService
73                .getVideoChannelVideos(this.videoChannel, newPagination, this.sort, this.nsfwPolicy)
74                .pipe(
75                  tap(({ total }) => {
76                    this.titlePage = this.i18n(`{total, plural, =1 {Published 1 video} other {Published {{total}} videos}}`, { total })
77                  })
78                )
79   }
80
81   generateSyndicationList () {
82     this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
83   }
84 }