]>
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 C |
9 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' |
10 | import { AbstractVideoList, OwnerDisplayType } 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 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, |
5bcbcbe3 | 36 | protected cfr: ComponentFactoryResolver, |
afff310e | 37 | private hooks: HooksService, |
5beb89f2 RK |
38 | private videoService: VideoService, |
39 | private scopedTokensService: ScopedTokensService | |
22a16e36 C |
40 | ) { |
41 | super() | |
42 | ||
66357162 | 43 | this.titlePage = $localize`Videos from your subscriptions` |
afff310e | 44 | |
13adf228 | 45 | this.actions.push({ |
17119e4a | 46 | routerLink: '/my-library/subscriptions', |
66357162 | 47 | label: $localize`Subscriptions`, |
13adf228 RK |
48 | iconName: 'cog' |
49 | }) | |
22a16e36 C |
50 | } |
51 | ||
52 | ngOnInit () { | |
53 | super.ngOnInit() | |
afff310e RK |
54 | |
55 | const user = this.authService.getUser() | |
5beb89f2 RK |
56 | let feedUrl = environment.originServerUrl |
57 | ||
d29ae17f C |
58 | this.authService.userInformationLoaded |
59 | .pipe(switchMap(() => this.scopedTokensService.getScopedTokens())) | |
60 | .subscribe( | |
61 | tokens => { | |
62 | const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken) | |
63 | feedUrl = feedUrl + feeds.find(f => f.format === FeedFormat.RSS).url | |
7af5ded4 C |
64 | |
65 | this.actions.unshift({ | |
66 | label: $localize`Copy feed URL`, | |
67 | iconName: 'syndication', | |
68 | justIcon: true, | |
69 | href: feedUrl, | |
70 | click: e => { | |
71 | e.preventDefault() | |
72 | copyToClipboard(feedUrl) | |
73 | this.activateCopiedMessage() | |
74 | } | |
75 | }) | |
d29ae17f | 76 | }, |
5beb89f2 | 77 | |
d29ae17f C |
78 | err => { |
79 | this.notifier.error(err.message) | |
80 | } | |
81 | ) | |
22a16e36 C |
82 | } |
83 | ||
84 | ngOnDestroy () { | |
85 | super.ngOnDestroy() | |
86 | } | |
87 | ||
88 | getVideosObservable (page: number) { | |
89 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
93cae479 C |
90 | const params = { |
91 | videoPagination: newPagination, | |
440d39c5 C |
92 | sort: this.sort, |
93 | skipCount: true | |
93cae479 | 94 | } |
22a16e36 | 95 | |
93cae479 | 96 | return this.hooks.wrapObsFun( |
67ed6552 | 97 | this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription), |
93cae479 C |
98 | params, |
99 | 'common', | |
7663e55a C |
100 | 'filter:api.user-subscriptions-videos.videos.list.params', |
101 | 'filter:api.user-subscriptions-videos.videos.list.result' | |
93cae479 | 102 | ) |
22a16e36 C |
103 | } |
104 | ||
105 | generateSyndicationList () { | |
5bcbcbe3 RK |
106 | /* method disabled: the view provides its own */ |
107 | throw new Error('Method not implemented.') | |
22a16e36 | 108 | } |
afff310e RK |
109 | |
110 | activateCopiedMessage () { | |
111 | this.notifier.success($localize`Feed URL copied`) | |
112 | } | |
22a16e36 | 113 | } |