]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import { firstValueFrom } from 'rxjs' | |
3 | import { switchMap, tap } from 'rxjs/operators' | |
4 | import { Component } from '@angular/core' | |
5 | import { AuthService, ComponentPaginationLight, DisableForReuseHook, ScopedTokensService } from '@app/core' | |
6 | import { HooksService } from '@app/core/plugins/hooks.service' | |
7 | import { VideoService } from '@app/shared/shared-main' | |
8 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' | |
9 | import { VideoFilters } from '@app/shared/shared-video-miniature' | |
10 | import { VideoSortField } from '@shared/models' | |
11 | ||
12 | @Component({ | |
13 | selector: 'my-videos-user-subscriptions', | |
14 | templateUrl: './video-user-subscriptions.component.html' | |
15 | }) | |
16 | export class VideoUserSubscriptionsComponent implements DisableForReuseHook { | |
17 | getVideosObservableFunction = this.getVideosObservable.bind(this) | |
18 | getSyndicationItemsFunction = this.getSyndicationItems.bind(this) | |
19 | ||
20 | defaultSort = '-publishedAt' as VideoSortField | |
21 | ||
22 | actions = [ | |
23 | { | |
24 | routerLink: '/my-library/subscriptions', | |
25 | label: $localize`Subscriptions`, | |
26 | iconName: 'cog' as 'cog' | |
27 | } | |
28 | ] | |
29 | ||
30 | titlePage = $localize`Videos from your subscriptions` | |
31 | ||
32 | disabled = false | |
33 | ||
34 | private feedToken: string | |
35 | ||
36 | constructor ( | |
37 | private authService: AuthService, | |
38 | private userSubscription: UserSubscriptionService, | |
39 | private hooks: HooksService, | |
40 | private videoService: VideoService, | |
41 | private scopedTokensService: ScopedTokensService | |
42 | ) { | |
43 | ||
44 | } | |
45 | ||
46 | getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) { | |
47 | const params = { | |
48 | ...filters.toVideosAPIObject(), | |
49 | ||
50 | videoPagination: pagination, | |
51 | skipCount: true | |
52 | } | |
53 | ||
54 | return this.hooks.wrapObsFun( | |
55 | this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription), | |
56 | params, | |
57 | 'common', | |
58 | 'filter:api.user-subscriptions-videos.videos.list.params', | |
59 | 'filter:api.user-subscriptions-videos.videos.list.result' | |
60 | ) | |
61 | } | |
62 | ||
63 | getSyndicationItems () { | |
64 | return this.loadFeedToken() | |
65 | .then(() => { | |
66 | const user = this.authService.getUser() | |
67 | ||
68 | return this.videoService.getVideoSubscriptionFeedUrls(user.account.id, this.feedToken) | |
69 | }) | |
70 | } | |
71 | ||
72 | disableForReuse () { | |
73 | this.disabled = true | |
74 | } | |
75 | ||
76 | enabledForReuse () { | |
77 | this.disabled = false | |
78 | } | |
79 | ||
80 | private loadFeedToken () { | |
81 | if (this.feedToken) return Promise.resolve(this.feedToken) | |
82 | ||
83 | const obs = this.authService.userInformationLoaded | |
84 | .pipe( | |
85 | switchMap(() => this.scopedTokensService.getScopedTokens()), | |
86 | tap(tokens => this.feedToken = tokens.feedToken) | |
87 | ) | |
88 | ||
89 | return firstValueFrom(obs) | |
90 | } | |
91 | } |