1 import { Component, Input, OnInit } from '@angular/core'
2 import { AuthService } from '@app/core'
3 import { RestExtractor } from '@app/shared/rest'
4 import { RedirectService } from '@app/core/routing/redirect.service'
5 import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
6 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
7 import { NotificationsService } from 'angular2-notifications'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
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
22 private authService: AuthService,
23 private restExtractor: RestExtractor,
24 private redirectService: RedirectService,
25 private notificationsService: NotificationsService,
26 private userSubscriptionService: UserSubscriptionService,
31 return this.videoChannel.name + '@' + this.videoChannel.host
35 this.userSubscriptionService.isSubscriptionExists(this.uri)
37 exists => this.subscribed = exists,
39 err => this.notificationsService.error(this.i18n('Error'), err.message)
44 this.userSubscriptionService.addSubscription(this.uri)
47 this.subscribed = true
49 this.notificationsService.success(
50 this.i18n('Subscribed'),
51 this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
55 err => this.notificationsService.error(this.i18n('Error'), err.message)
60 this.userSubscriptionService.deleteSubscription(this.uri)
63 this.subscribed = false
65 this.notificationsService.success(
66 this.i18n('Unsubscribed'),
67 this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
71 err => this.notificationsService.error(this.i18n('Error'), err.message)