]>
Commit | Line | Data |
---|---|---|
18490b07 | 1 | |
d29ae17f | 2 | import { switchMap } from 'rxjs/operators' |
5bcbcbe3 | 3 | import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' |
22a16e36 | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5beb89f2 | 5 | import { AuthService, LocalStorageService, Notifier, ScopedTokensService, ScreenService, ServerService, UserService } from '@app/core' |
93cae479 | 6 | import { HooksService } from '@app/core/plugins/hooks.service' |
67ed6552 | 7 | import { immutableAssign } from '@app/helpers' |
afff310e | 8 | import { VideoService } from '@app/shared/shared-main' |
67ed6552 | 9 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' |
733dbc53 | 10 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' |
18490b07 | 11 | import { FeedFormat, VideoSortField } from '@shared/models' |
afff310e | 12 | import { environment } from '../../../environments/environment' |
18490b07 | 13 | import { 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 | }) |
20 | export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
21 | titlePage: string | |
22a16e36 | 22 | sort = '-publishedAt' as VideoSortField |
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, |
5bcbcbe3 | 35 | protected cfr: ComponentFactoryResolver, |
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 | |
7af5ded4 C |
63 | |
64 | this.actions.unshift({ | |
65 | label: $localize`Copy feed URL`, | |
66 | iconName: 'syndication', | |
67 | justIcon: true, | |
68 | href: feedUrl, | |
69 | click: e => { | |
70 | e.preventDefault() | |
71 | copyToClipboard(feedUrl) | |
72 | this.activateCopiedMessage() | |
73 | } | |
74 | }) | |
d29ae17f | 75 | }, |
5beb89f2 | 76 | |
d29ae17f C |
77 | err => { |
78 | this.notifier.error(err.message) | |
79 | } | |
80 | ) | |
22a16e36 C |
81 | } |
82 | ||
83 | ngOnDestroy () { | |
84 | super.ngOnDestroy() | |
85 | } | |
86 | ||
87 | getVideosObservable (page: number) { | |
88 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
93cae479 C |
89 | const params = { |
90 | videoPagination: newPagination, | |
440d39c5 C |
91 | sort: this.sort, |
92 | skipCount: true | |
93cae479 | 93 | } |
22a16e36 | 94 | |
93cae479 | 95 | return this.hooks.wrapObsFun( |
67ed6552 | 96 | this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription), |
93cae479 C |
97 | params, |
98 | 'common', | |
7663e55a C |
99 | 'filter:api.user-subscriptions-videos.videos.list.params', |
100 | 'filter:api.user-subscriptions-videos.videos.list.result' | |
93cae479 | 101 | ) |
22a16e36 C |
102 | } |
103 | ||
104 | generateSyndicationList () { | |
5bcbcbe3 RK |
105 | /* method disabled: the view provides its own */ |
106 | throw new Error('Method not implemented.') | |
22a16e36 | 107 | } |
afff310e RK |
108 | |
109 | activateCopiedMessage () { | |
110 | this.notifier.success($localize`Feed URL copied`) | |
111 | } | |
22a16e36 | 112 | } |