]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/video-list/video-user-subscriptions.component.ts
Load user when auth service is ready
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / video-user-subscriptions.component.ts
CommitLineData
18490b07 1
d29ae17f 2import { switchMap } from 'rxjs/operators'
22a16e36
C
3import { Component, OnDestroy, OnInit } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router'
5beb89f2 5import { AuthService, LocalStorageService, Notifier, ScopedTokensService, ScreenService, ServerService, UserService } from '@app/core'
93cae479 6import { HooksService } from '@app/core/plugins/hooks.service'
67ed6552 7import { immutableAssign } from '@app/helpers'
afff310e 8import { VideoService } from '@app/shared/shared-main'
67ed6552
C
9import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
10import { AbstractVideoList, OwnerDisplayType } from '@app/shared/shared-video-miniature'
18490b07 11import { FeedFormat, VideoSortField } from '@shared/models'
afff310e 12import { environment } from '../../../environments/environment'
18490b07 13import { copyToClipboard } from '../../../root-helpers/utils'
22a16e36
C
14
15@Component({
16 selector: 'my-videos-user-subscriptions',
67ed6552
C
17 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ],
18 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html'
22a16e36
C
19})
20export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy {
21 titlePage: string
22a16e36
C
22 sort = '-publishedAt' as VideoSortField
23 ownerDisplayType: OwnerDisplayType = 'auto'
34c7f429 24 groupByDate = true
22a16e36
C
25
26 constructor (
27 protected router: Router,
489290b8 28 protected serverService: ServerService,
22a16e36 29 protected route: ActivatedRoute,
f8b2c1b4 30 protected notifier: Notifier,
22a16e36 31 protected authService: AuthService,
d3217560 32 protected userService: UserService,
22a16e36 33 protected screenService: ScreenService,
d3217560 34 protected storageService: LocalStorageService,
67ed6552 35 private userSubscription: UserSubscriptionService,
afff310e 36 private hooks: HooksService,
5beb89f2
RK
37 private videoService: VideoService,
38 private scopedTokensService: ScopedTokensService
22a16e36
C
39 ) {
40 super()
41
66357162 42 this.titlePage = $localize`Videos from your subscriptions`
afff310e 43
13adf228 44 this.actions.push({
17119e4a 45 routerLink: '/my-library/subscriptions',
66357162 46 label: $localize`Subscriptions`,
13adf228
RK
47 iconName: 'cog'
48 })
22a16e36
C
49 }
50
51 ngOnInit () {
52 super.ngOnInit()
afff310e
RK
53
54 const user = this.authService.getUser()
5beb89f2
RK
55 let feedUrl = environment.originServerUrl
56
d29ae17f
C
57 this.authService.userInformationLoaded
58 .pipe(switchMap(() => this.scopedTokensService.getScopedTokens()))
59 .subscribe(
60 tokens => {
61 const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
62 feedUrl = feedUrl + feeds.find(f => f.format === FeedFormat.RSS).url
63 },
5beb89f2 64
d29ae17f
C
65 err => {
66 this.notifier.error(err.message)
67 }
68 )
5beb89f2 69
afff310e
RK
70 this.actions.unshift({
71 label: $localize`Feed`,
72 iconName: 'syndication',
73 justIcon: true,
74 click: () => {
75 copyToClipboard(feedUrl)
76 this.activateCopiedMessage()
77 }
78 })
22a16e36
C
79 }
80
81 ngOnDestroy () {
82 super.ngOnDestroy()
83 }
84
85 getVideosObservable (page: number) {
86 const newPagination = immutableAssign(this.pagination, { currentPage: page })
93cae479
C
87 const params = {
88 videoPagination: newPagination,
440d39c5
C
89 sort: this.sort,
90 skipCount: true
93cae479 91 }
22a16e36 92
93cae479 93 return this.hooks.wrapObsFun(
67ed6552 94 this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription),
93cae479
C
95 params,
96 'common',
7663e55a
C
97 'filter:api.user-subscriptions-videos.videos.list.params',
98 'filter:api.user-subscriptions-videos.videos.list.result'
93cae479 99 )
22a16e36
C
100 }
101
102 generateSyndicationList () {
103 // not implemented yet
104 }
afff310e
RK
105
106 activateCopiedMessage () {
107 this.notifier.success($localize`Feed URL copied`)
108 }
22a16e36 109}