2 import { switchMap } from 'rxjs/operators'
3 import { Component, ComponentFactoryResolver, 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'
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'
20 export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy {
22 sort = '-publishedAt' as VideoSortField
23 ownerDisplayType: OwnerDisplayType = 'auto'
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 protected cfr: ComponentFactoryResolver,
37 private hooks: HooksService,
38 private videoService: VideoService,
39 private scopedTokensService: ScopedTokensService
43 this.titlePage = $localize`Videos from your subscriptions`
46 routerLink: '/my-library/subscriptions',
47 label: $localize`Subscriptions`,
55 const user = this.authService.getUser()
56 let feedUrl = environment.originServerUrl
58 this.authService.userInformationLoaded
59 .pipe(switchMap(() => this.scopedTokensService.getScopedTokens()))
62 const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
63 feedUrl = feedUrl + feeds.find(f => f.format === FeedFormat.RSS).url
65 this.actions.unshift({
66 label: $localize`Copy feed URL`,
67 iconName: 'syndication',
72 copyToClipboard(feedUrl)
73 this.activateCopiedMessage()
79 this.notifier.error(err.message)
88 getVideosObservable (page: number) {
89 const newPagination = immutableAssign(this.pagination, { currentPage: page })
91 videoPagination: newPagination,
96 return this.hooks.wrapObsFun(
97 this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription),
100 'filter:api.user-subscriptions-videos.videos.list.params',
101 'filter:api.user-subscriptions-videos.videos.list.result'
105 generateSyndicationList () {
106 /* method disabled: the view provides its own */
107 throw new Error('Method not implemented.')
110 activateCopiedMessage () {
111 this.notifier.success($localize`Feed URL copied`)