]>
Commit | Line | Data |
---|---|---|
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 | 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 | }) | |
75 | }, | |
76 | ||
77 | err => { | |
78 | this.notifier.error(err.message) | |
79 | } | |
80 | ) | |
81 | } | |
82 | ||
83 | ngOnDestroy () { | |
84 | super.ngOnDestroy() | |
85 | } | |
86 | ||
87 | getVideosObservable (page: number) { | |
88 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
89 | const params = { | |
90 | videoPagination: newPagination, | |
91 | sort: this.sort, | |
92 | skipCount: true | |
93 | } | |
94 | ||
95 | return this.hooks.wrapObsFun( | |
96 | this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription), | |
97 | params, | |
98 | 'common', | |
99 | 'filter:api.user-subscriptions-videos.videos.list.params', | |
100 | 'filter:api.user-subscriptions-videos.videos.list.result' | |
101 | ) | |
102 | } | |
103 | ||
104 | generateSyndicationList () { | |
105 | // not implemented yet | |
106 | } | |
107 | ||
108 | activateCopiedMessage () { | |
109 | this.notifier.success($localize`Feed URL copied`) | |
110 | } | |
111 | } |