]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+accounts/account-videos/account-videos.component.ts
da3903d2c704fa645278839a292b50749c3c453a
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-videos / account-videos.component.ts
1 import { 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
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,
37 private accountService: AccountService,
38 private videoService: VideoService,
39 protected cfr: ComponentFactoryResolver
40 ) {
41 super()
42 }
43
44 ngOnInit () {
45 super.ngOnInit()
46
47 this.enableAllFilterIfPossible()
48
49 // Parent get the account for us
50 this.accountSub = this.accountService.accountLoaded
51 .pipe(first())
52 .subscribe(account => {
53 this.account = account
54
55 this.reloadVideos()
56 this.generateSyndicationList()
57 })
58 }
59
60 ngOnDestroy () {
61 if (this.accountSub) this.accountSub.unsubscribe()
62
63 super.ngOnDestroy()
64 }
65
66 getVideosObservable (page: number) {
67 const newPagination = immutableAssign(this.pagination, { currentPage: page })
68 const options = {
69 account: this.account,
70 videoPagination: newPagination,
71 sort: this.sort,
72 nsfwPolicy: this.nsfwPolicy,
73 videoFilter: this.filter
74 }
75
76 return this.videoService
77 .getAccountVideos(options)
78 .pipe(
79 tap(({ total }) => {
80 this.titlePage = $localize`Published ${total} videos`
81 })
82 )
83 }
84
85 toggleModerationDisplay () {
86 this.filter = this.buildLocalFilter(this.filter, null)
87
88 this.reloadVideos()
89 }
90
91 generateSyndicationList () {
92 this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id)
93 }
94 }