]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/video-list/video-user-subscriptions.component.ts
Use the channel URL behind the account in miniature
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / video-user-subscriptions.component.ts
1
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'
14
15 @Component({
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'
19 })
20 export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy {
21 titlePage: string
22 sort = '-publishedAt' as VideoSortField
23 ownerDisplayType: OwnerDisplayType = 'auto'
24 groupByDate = true
25
26 constructor (
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
40 ) {
41 super()
42
43 this.titlePage = $localize`Videos from your subscriptions`
44
45 this.actions.push({
46 routerLink: '/my-library/subscriptions',
47 label: $localize`Subscriptions`,
48 iconName: 'cog'
49 })
50 }
51
52 ngOnInit () {
53 super.ngOnInit()
54
55 const user = this.authService.getUser()
56 let feedUrl = environment.originServerUrl
57
58 this.authService.userInformationLoaded
59 .pipe(switchMap(() => this.scopedTokensService.getScopedTokens()))
60 .subscribe(
61 tokens => {
62 const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
63 feedUrl = feedUrl + feeds.find(f => f.format === FeedFormat.RSS).url
64
65 this.actions.unshift({
66 label: $localize`Copy feed URL`,
67 iconName: 'syndication',
68 justIcon: true,
69 href: feedUrl,
70 click: e => {
71 e.preventDefault()
72 copyToClipboard(feedUrl)
73 this.activateCopiedMessage()
74 }
75 })
76 },
77
78 err => {
79 this.notifier.error(err.message)
80 }
81 )
82 }
83
84 ngOnDestroy () {
85 super.ngOnDestroy()
86 }
87
88 getVideosObservable (page: number) {
89 const newPagination = immutableAssign(this.pagination, { currentPage: page })
90 const params = {
91 videoPagination: newPagination,
92 sort: this.sort,
93 skipCount: true
94 }
95
96 return this.hooks.wrapObsFun(
97 this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription),
98 params,
99 'common',
100 'filter:api.user-subscriptions-videos.videos.list.params',
101 'filter:api.user-subscriptions-videos.videos.list.result'
102 )
103 }
104
105 generateSyndicationList () {
106 /* method disabled: the view provides its own */
107 throw new Error('Method not implemented.')
108 }
109
110 activateCopiedMessage () {
111 this.notifier.success($localize`Feed URL copied`)
112 }
113 }