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