]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts
Fix actor overflows
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-videos / video-channel-videos.component.ts
1 import { forkJoin, Subscription } from 'rxjs'
2 import { first, tap } from 'rxjs/operators'
3 import { Component, ComponentFactoryResolver, 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, MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
9 import { VideoFilter } from '@shared/models'
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 ]
17 })
18 export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
19 titlePage: string
20 loadOnInit = false
21 loadUserVideoPreferences = true
22
23 filter: VideoFilter = null
24
25 displayOptions: MiniatureDisplayOptions = {
26 date: true,
27 views: true,
28 by: false,
29 avatar: false,
30 privacyLabel: true,
31 privacyText: false,
32 state: false,
33 blacklistInfo: false
34 }
35
36 private videoChannel: VideoChannel
37 private videoChannelSub: Subscription
38
39 constructor (
40 protected router: Router,
41 protected serverService: ServerService,
42 protected route: ActivatedRoute,
43 protected authService: AuthService,
44 protected userService: UserService,
45 protected notifier: Notifier,
46 protected confirmService: ConfirmService,
47 protected screenService: ScreenService,
48 protected storageService: LocalStorageService,
49 protected cfr: ComponentFactoryResolver,
50 private videoChannelService: VideoChannelService,
51 private videoService: VideoService
52 ) {
53 super()
54
55 this.titlePage = $localize`Published videos`
56 this.displayOptions = {
57 ...this.displayOptions,
58 avatar: false
59 }
60 }
61
62 ngOnInit () {
63 super.ngOnInit()
64
65 this.enableAllFilterIfPossible()
66
67 // Parent get the video channel for us
68 this.videoChannelSub = forkJoin([
69 this.videoChannelService.videoChannelLoaded.pipe(first()),
70 this.onUserLoadedSubject.pipe(first())
71 ]).subscribe(([ videoChannel ]) => {
72 this.videoChannel = videoChannel
73
74 this.reloadVideos()
75 this.generateSyndicationList()
76 })
77 }
78
79 ngOnDestroy () {
80 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
81
82 super.ngOnDestroy()
83 }
84
85 getVideosObservable (page: number) {
86 const newPagination = immutableAssign(this.pagination, { currentPage: page })
87 const options = {
88 videoChannel: this.videoChannel,
89 videoPagination: newPagination,
90 sort: this.sort,
91 nsfwPolicy: this.nsfwPolicy,
92 videoFilter: this.filter
93 }
94
95 return this.videoService
96 .getVideoChannelVideos(options)
97 .pipe(
98 tap(({ total }) => {
99 this.titlePage = total === 1
100 ? $localize`Published 1 video`
101 : $localize`Published ${total} videos`
102 })
103 )
104 }
105
106 generateSyndicationList () {
107 this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
108 }
109
110 toggleModerationDisplay () {
111 this.filter = this.buildLocalFilter(this.filter, null)
112
113 this.reloadVideos()
114 }
115
116 displayAsRow () {
117 return this.screenService.isInMobileView()
118 }
119 }