]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+accounts/account-search/account-search.component.ts
Fix NSFW policy on account/channel videos
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-search / account-search.component.ts
CommitLineData
07f81d9d 1import { forkJoin, Subscription } from 'rxjs'
37024082 2import { first, tap } from 'rxjs/operators'
5bcbcbe3 3import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core'
37024082
RK
4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
6import { immutableAssign } from '@app/helpers'
7import { Account, AccountService, VideoService } from '@app/shared/shared-main'
8import { AbstractVideoList } from '@app/shared/shared-video-miniature'
9import { VideoFilter } from '@shared/models'
10
11@Component({
12 selector: 'my-account-search',
13 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html',
5bcbcbe3 14 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ]
37024082
RK
15})
16export class AccountSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
17 titlePage: string
18 loadOnInit = false
07f81d9d 19 loadUserVideoPreferences = true
37024082
RK
20
21 search = ''
22 filter: VideoFilter = null
23
24 private account: Account
25 private accountSub: Subscription
26
27 constructor (
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,
5bcbcbe3 37 protected cfr: ComponentFactoryResolver,
37024082
RK
38 private accountService: AccountService,
39 private videoService: VideoService
40 ) {
41 super()
42 }
43
44 ngOnInit () {
45 super.ngOnInit()
46
47 this.enableAllFilterIfPossible()
48
49 // Parent get the account for us
07f81d9d
C
50 this.accountSub = forkJoin([
51 this.accountService.accountLoaded.pipe(first()),
52 this.onUserLoadedSubject.pipe(first())
53 ]).subscribe(([ account ]) => {
54 this.account = account
37024082 55
07f81d9d
C
56 this.reloadVideos()
57 })
37024082
RK
58 }
59
60 ngOnDestroy () {
61 if (this.accountSub) this.accountSub.unsubscribe()
62
63 super.ngOnDestroy()
64 }
65
66 updateSearch (value: string) {
67 if (value === '') this.router.navigate(['../videos'], { relativeTo: this.route })
68 this.search = value
69
70 this.reloadVideos()
71 }
72
73 getVideosObservable (page: number) {
74 const newPagination = immutableAssign(this.pagination, { currentPage: page })
75 const options = {
76 account: this.account,
77 videoPagination: newPagination,
78 sort: this.sort,
79 nsfwPolicy: this.nsfwPolicy,
80 videoFilter: this.filter,
81 search: this.search
82 }
83
84 return this.videoService
85 .getAccountVideos(options)
86 .pipe(
87 tap(({ total }) => {
88 this.titlePage = this.search
89 ? $localize`Published ${total} videos matching "${this.search}"`
90 : $localize`Published ${total} videos`
91 })
92 )
93 }
94
95 toggleModerationDisplay () {
96 this.filter = this.buildLocalFilter(this.filter, null)
97
98 this.reloadVideos()
99 }
100
101 generateSyndicationList () {
5bcbcbe3
RK
102 /* method disabled */
103 throw new Error('Method not implemented.')
37024082
RK
104 }
105}