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