]>
Commit | Line | Data |
---|---|---|
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 | // No value because we don't want a page title | |
20 | titlePage: string | |
21 | loadOnInit = false | |
22 | loadUserVideoPreferences = true | |
23 | ||
24 | filter: VideoFilter = null | |
25 | ||
26 | displayOptions: MiniatureDisplayOptions = { | |
27 | date: true, | |
28 | views: true, | |
29 | by: false, | |
30 | avatar: false, | |
31 | privacyLabel: true, | |
32 | privacyText: false, | |
33 | state: false, | |
34 | blacklistInfo: false | |
35 | } | |
36 | ||
37 | private videoChannel: VideoChannel | |
38 | private videoChannelSub: Subscription | |
39 | ||
40 | constructor ( | |
41 | protected router: Router, | |
42 | protected serverService: ServerService, | |
43 | protected route: ActivatedRoute, | |
44 | protected authService: AuthService, | |
45 | protected userService: UserService, | |
46 | protected notifier: Notifier, | |
47 | protected confirmService: ConfirmService, | |
48 | protected screenService: ScreenService, | |
49 | protected storageService: LocalStorageService, | |
50 | protected cfr: ComponentFactoryResolver, | |
51 | private videoChannelService: VideoChannelService, | |
52 | private videoService: VideoService | |
53 | ) { | |
54 | super() | |
55 | ||
56 | this.titlePage = $localize`Published videos` | |
57 | this.displayOptions = { | |
58 | ...this.displayOptions, | |
59 | avatar: false | |
60 | } | |
61 | } | |
62 | ||
63 | ngOnInit () { | |
64 | super.ngOnInit() | |
65 | ||
66 | this.enableAllFilterIfPossible() | |
67 | ||
68 | // Parent get the video channel for us | |
69 | this.videoChannelSub = forkJoin([ | |
70 | this.videoChannelService.videoChannelLoaded.pipe(first()), | |
71 | this.onUserLoadedSubject.pipe(first()) | |
72 | ]).subscribe(([ videoChannel ]) => { | |
73 | this.videoChannel = videoChannel | |
74 | ||
75 | this.reloadVideos() | |
76 | this.generateSyndicationList() | |
77 | }) | |
78 | } | |
79 | ||
80 | ngOnDestroy () { | |
81 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() | |
82 | ||
83 | super.ngOnDestroy() | |
84 | } | |
85 | ||
86 | getVideosObservable (page: number) { | |
87 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
88 | const options = { | |
89 | videoChannel: this.videoChannel, | |
90 | videoPagination: newPagination, | |
91 | sort: this.sort, | |
92 | nsfwPolicy: this.nsfwPolicy, | |
93 | videoFilter: this.filter | |
94 | } | |
95 | ||
96 | return this.videoService | |
97 | .getVideoChannelVideos(options) | |
98 | } | |
99 | ||
100 | generateSyndicationList () { | |
101 | this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) | |
102 | } | |
103 | ||
104 | toggleModerationDisplay () { | |
105 | this.filter = this.buildLocalFilter(this.filter, null) | |
106 | ||
107 | this.reloadVideos() | |
108 | } | |
109 | ||
110 | displayAsRow () { | |
111 | return this.screenService.isInMobileView() | |
112 | } | |
113 | } |