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