]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts
Force channel in my videos
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-videos / video-channel-videos.component.ts
1 import { Subscription } from 'rxjs'
2 import { first } from 'rxjs/operators'
3 import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'
4 import { ComponentPaginationLight, DisableForReuseHook, HooksService, ScreenService } from '@app/core'
5 import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
6 import { MiniatureDisplayOptions, VideoFilters } from '@app/shared/shared-video-miniature'
7 import { Video, VideoSortField } from '@shared/models'
8
9 @Component({
10 selector: 'my-video-channel-videos',
11 templateUrl: './video-channel-videos.component.html'
12 })
13 export class VideoChannelVideosComponent implements OnInit, AfterViewInit, OnDestroy, DisableForReuseHook {
14 getVideosObservableFunction = this.getVideosObservable.bind(this)
15 getSyndicationItemsFunction = this.getSyndicationItems.bind(this)
16
17 title = $localize`Videos`
18 defaultSort = '-publishedAt' as VideoSortField
19
20 displayOptions: MiniatureDisplayOptions = {
21 date: true,
22 views: true,
23 by: false,
24 avatar: false,
25 privacyLabel: true,
26 privacyText: false,
27 state: false,
28 blacklistInfo: false
29 }
30
31 videoChannel: VideoChannel
32 disabled = false
33
34 private videoChannelSub: Subscription
35
36 constructor (
37 private screenService: ScreenService,
38 private videoChannelService: VideoChannelService,
39 private videoService: VideoService,
40 private hooks: HooksService
41 ) {
42 }
43
44 ngOnInit () {
45 // Parent get the video channel for us
46 this.videoChannelService.videoChannelLoaded.pipe(first())
47 .subscribe(videoChannel => {
48 this.videoChannel = videoChannel
49
50 this.hooks.runAction('action:video-channel-videos.video-channel.loaded', 'video-channel', { videoChannel })
51 })
52 }
53
54 ngAfterViewInit () {
55 this.hooks.runAction('action:video-channel-videos.init', 'video-channel')
56 }
57
58 ngOnDestroy () {
59 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
60 }
61
62 getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) {
63 const params = {
64 ...filters.toVideosAPIObject(),
65
66 videoPagination: pagination,
67 videoChannel: this.videoChannel,
68 skipCount: true
69 }
70
71 return this.videoService.getVideoChannelVideos(params)
72 }
73
74 getSyndicationItems () {
75 return this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
76 }
77
78 displayAsRow () {
79 return this.screenService.isInMobileView()
80 }
81
82 disableForReuse () {
83 this.disabled = true
84 }
85
86 enabledForReuse () {
87 this.disabled = false
88 }
89
90 onVideosLoaded (videos: Video[]) {
91 this.hooks.runAction('action:video-channel-videos.videos.loaded', 'video-channel', { videos })
92 }
93 }