]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import { Component, OnDestroy, OnInit } from '@angular/core' | |
3 | import { ActivatedRoute, Router } from '@angular/router' | |
4 | import { AuthService, LocalStorageService, Notifier, ScopedTokensService, ScreenService, ServerService, UserService } from '@app/core' | |
5 | import { HooksService } from '@app/core/plugins/hooks.service' | |
6 | import { immutableAssign } from '@app/helpers' | |
7 | import { VideoService } from '@app/shared/shared-main' | |
8 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' | |
9 | import { AbstractVideoList, OwnerDisplayType } from '@app/shared/shared-video-miniature' | |
10 | import { FeedFormat, VideoSortField } from '@shared/models' | |
11 | import { environment } from '../../../environments/environment' | |
12 | import { copyToClipboard } from '../../../root-helpers/utils' | |
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 => 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 | } |