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'
13 selector: 'my-videos-user-subscriptions',
14 templateUrl: './video-user-subscriptions.component.html'
16 export class VideoUserSubscriptionsComponent implements DisableForReuseHook {
17 getVideosObservableFunction = this.getVideosObservable.bind(this)
18 getSyndicationItemsFunction = this.getSyndicationItems.bind(this)
20 defaultSort = '-publishedAt' as VideoSortField
24 routerLink: '/my-library/subscriptions',
25 label: $localize`Subscriptions`,
26 iconName: 'cog' as 'cog'
30 titlePage = $localize`Videos from your subscriptions`
34 private feedToken: string
37 private authService: AuthService,
38 private userSubscription: UserSubscriptionService,
39 private hooks: HooksService,
40 private videoService: VideoService,
41 private scopedTokensService: ScopedTokensService
46 getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) {
48 ...filters.toVideosAPIObject(),
50 videoPagination: pagination,
54 return this.hooks.wrapObsFun(
55 this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription),
58 'filter:api.user-subscriptions-videos.videos.list.params',
59 'filter:api.user-subscriptions-videos.videos.list.result'
63 getSyndicationItems () {
64 return this.loadFeedToken()
66 const user = this.authService.getUser()
68 return this.videoService.getVideoSubscriptionFeedUrls(user.account.id, this.feedToken)
80 private loadFeedToken () {
81 if (this.feedToken) return Promise.resolve(this.feedToken)
83 const obs = this.authService.userInformationLoaded
85 switchMap(() => this.scopedTokensService.getScopedTokens()),
86 tap(tokens => this.feedToken = tokens.feedToken)
89 return firstValueFrom(obs)