aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/video-list/video-user-subscriptions.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+videos/video-list/video-user-subscriptions.component.ts')
-rw-r--r--client/src/app/+videos/video-list/video-user-subscriptions.component.ts133
1 files changed, 56 insertions, 77 deletions
diff --git a/client/src/app/+videos/video-list/video-user-subscriptions.component.ts b/client/src/app/+videos/video-list/video-user-subscriptions.component.ts
index a1498e797..43cbab9f6 100644
--- a/client/src/app/+videos/video-list/video-user-subscriptions.component.ts
+++ b/client/src/app/+videos/video-list/video-user-subscriptions.component.ts
@@ -1,94 +1,53 @@
1 1
2import { switchMap } from 'rxjs/operators' 2import { firstValueFrom } from 'rxjs'
3import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' 3import { switchMap, tap } from 'rxjs/operators'
4import { ActivatedRoute, Router } from '@angular/router' 4import { Component } from '@angular/core'
5import { AuthService, LocalStorageService, Notifier, ScopedTokensService, ScreenService, ServerService, UserService } from '@app/core' 5import { AuthService, ComponentPaginationLight, DisableForReuseHook, ScopedTokensService } from '@app/core'
6import { HooksService } from '@app/core/plugins/hooks.service' 6import { HooksService } from '@app/core/plugins/hooks.service'
7import { immutableAssign } from '@app/helpers'
8import { VideoService } from '@app/shared/shared-main' 7import { VideoService } from '@app/shared/shared-main'
9import { UserSubscriptionService } from '@app/shared/shared-user-subscription' 8import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
10import { AbstractVideoList } from '@app/shared/shared-video-miniature' 9import { VideoFilters } from '@app/shared/shared-video-miniature'
11import { FeedFormat, VideoSortField } from '@shared/models' 10import { VideoSortField } from '@shared/models'
12import { environment } from '../../../environments/environment'
13import { copyToClipboard } from '../../../root-helpers/utils'
14 11
15@Component({ 12@Component({
16 selector: 'my-videos-user-subscriptions', 13 selector: 'my-videos-user-subscriptions',
17 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], 14 templateUrl: './video-user-subscriptions.component.html'
18 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html'
19}) 15})
20export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy { 16export class VideoUserSubscriptionsComponent implements DisableForReuseHook {
21 titlePage: string 17 getVideosObservableFunction = this.getVideosObservable.bind(this)
22 sort = '-publishedAt' as VideoSortField 18 getSyndicationItemsFunction = this.getSyndicationItems.bind(this)
23 groupByDate = true 19
20 defaultSort = '-publishedAt' as VideoSortField
21
22 actions = [
23 {
24 routerLink: '/my-library/subscriptions',
25 label: $localize`Subscriptions`,
26 iconName: 'cog'
27 }
28 ]
29
30 titlePage = $localize`Videos from your subscriptions`
31
32 disabled = false
33
34 private feedToken: string
24 35
25 constructor ( 36 constructor (
26 protected router: Router, 37 private authService: AuthService,
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, 38 private userSubscription: UserSubscriptionService,
35 protected cfr: ComponentFactoryResolver,
36 private hooks: HooksService, 39 private hooks: HooksService,
37 private videoService: VideoService, 40 private videoService: VideoService,
38 private scopedTokensService: ScopedTokensService 41 private scopedTokensService: ScopedTokensService
39 ) { 42 ) {
40 super()
41 43
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 } 44 }
50 45
51 ngOnInit () { 46 getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) {
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 next: 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 error: 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 = { 47 const params = {
90 videoPagination: newPagination, 48 ...filters.toVideosAPIObject(),
91 sort: this.sort, 49
50 videoPagination: pagination,
92 skipCount: true 51 skipCount: true
93 } 52 }
94 53
@@ -101,12 +60,32 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement
101 ) 60 )
102 } 61 }
103 62
104 generateSyndicationList () { 63 getSyndicationItems () {
105 /* method disabled: the view provides its own */ 64 return this.loadFeedToken()
106 throw new Error('Method not implemented.') 65 .then(() => {
66 const user = this.authService.getUser()
67
68 return this.videoService.getVideoSubscriptionFeedUrls(user.account.id, this.feedToken)
69 })
107 } 70 }
108 71
109 activateCopiedMessage () { 72 disableForReuse () {
110 this.notifier.success($localize`Feed URL copied`) 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)
111 } 90 }
112} 91}