]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+accounts/account-videos/account-videos.component.ts
Fix NSFW policy on account/channel videos
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-videos / account-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 { Account, AccountService, VideoService } from '@app/shared/shared-main'
8 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
9 import { VideoFilter } from '@shared/models'
10
11 @Component({
12 selector: 'my-account-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 AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
19 titlePage: string
20 loadOnInit = false
21 loadUserVideoPreferences = true
22
23 filter: VideoFilter = null
24
25 private account: Account
26 private accountSub: Subscription
27
28 constructor (
29 protected router: Router,
30 protected serverService: ServerService,
31 protected route: ActivatedRoute,
32 protected authService: AuthService,
33 protected userService: UserService,
34 protected notifier: Notifier,
35 protected confirmService: ConfirmService,
36 protected screenService: ScreenService,
37 protected storageService: LocalStorageService,
38 private accountService: AccountService,
39 private videoService: VideoService,
40 protected cfr: ComponentFactoryResolver
41 ) {
42 super()
43 }
44
45 ngOnInit () {
46 super.ngOnInit()
47
48 this.enableAllFilterIfPossible()
49
50 // Parent get the account for us
51 this.accountSub = forkJoin([
52 this.accountService.accountLoaded.pipe(first()),
53 this.onUserLoadedSubject.pipe(first())
54 ]).subscribe(([ account ]) => {
55 this.account = account
56
57 this.reloadVideos()
58 this.generateSyndicationList()
59 })
60 }
61
62 ngOnDestroy () {
63 if (this.accountSub) this.accountSub.unsubscribe()
64
65 super.ngOnDestroy()
66 }
67
68 getVideosObservable (page: number) {
69 const newPagination = immutableAssign(this.pagination, { currentPage: page })
70 const options = {
71 account: this.account,
72 videoPagination: newPagination,
73 sort: this.sort,
74 nsfwPolicy: this.nsfwPolicy,
75 videoFilter: this.filter
76 }
77
78 return this.videoService
79 .getAccountVideos(options)
80 .pipe(
81 tap(({ total }) => {
82 this.titlePage = $localize`Published ${total} videos`
83 })
84 )
85 }
86
87 toggleModerationDisplay () {
88 this.filter = this.buildLocalFilter(this.filter, null)
89
90 this.reloadVideos()
91 }
92
93 generateSyndicationList () {
94 this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id)
95 }
96 }