1 import { Component, Input, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier } from '@app/core'
4 import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { VideoService } from '@app/shared/video/video.service'
8 import { FeedFormat } from '../../../../../shared/models/feeds'
11 selector: 'my-subscribe-button',
12 templateUrl: './subscribe-button.component.html',
13 styleUrls: [ './subscribe-button.component.scss' ]
15 export class SubscribeButtonComponent implements OnInit {
16 @Input() videoChannel: VideoChannel
17 @Input() displayFollowers = false
18 @Input() size: 'small' | 'normal' = 'normal'
23 private authService: AuthService,
24 private router: Router,
25 private notifier: Notifier,
26 private userSubscriptionService: UserSubscriptionService,
28 private videoService: VideoService
32 return this.videoChannel.name + '@' + this.videoChannel.host
36 return this.videoChannel.ownerAccount.name + '@' + this.videoChannel.host
40 if (this.isUserLoggedIn()) {
41 this.userSubscriptionService.doesSubscriptionExist(this.uri)
43 res => this.subscribed = res[this.uri],
45 err => this.notifier.error(err.message)
51 if (this.isUserLoggedIn()) {
52 return this.localSubscribe()
55 return this.gotoLogin()
59 this.userSubscriptionService.addSubscription(this.uri)
62 this.subscribed = true
64 this.notifier.success(
65 this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }),
66 this.i18n('Subscribed')
70 err => this.notifier.error(err.message)
75 if (this.isUserLoggedIn()) {
76 this.localUnsubscribe()
81 this.userSubscriptionService.deleteSubscription(this.uri)
84 this.subscribed = false
86 this.notifier.success(
87 this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }),
88 this.i18n('Unsubscribed')
92 err => this.notifier.error(err.message)
97 return this.authService.isLoggedIn()
101 this.router.navigate([ '/login' ])
105 const rssFeed = this.videoService
106 .getVideoChannelFeedUrls(this.videoChannel.id)
107 .find(i => i.format === FeedFormat.RSS)
109 window.open(rssFeed.url)