aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/user-subscription/subscribe-button.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/user-subscription/subscribe-button.component.ts')
-rw-r--r--client/src/app/shared/user-subscription/subscribe-button.component.ts46
1 files changed, 41 insertions, 5 deletions
diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.ts b/client/src/app/shared/user-subscription/subscribe-button.component.ts
index b5873a2ee..e3c758942 100644
--- a/client/src/app/shared/user-subscription/subscribe-button.component.ts
+++ b/client/src/app/shared/user-subscription/subscribe-button.component.ts
@@ -1,4 +1,6 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
3import { AuthService } from '@app/core'
2import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service' 4import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
3import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 5import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
4import { NotificationsService } from 'angular2-notifications' 6import { NotificationsService } from 'angular2-notifications'
@@ -17,6 +19,8 @@ export class SubscribeButtonComponent implements OnInit {
17 subscribed: boolean 19 subscribed: boolean
18 20
19 constructor ( 21 constructor (
22 private authService: AuthService,
23 private router: Router,
20 private notificationsService: NotificationsService, 24 private notificationsService: NotificationsService,
21 private userSubscriptionService: UserSubscriptionService, 25 private userSubscriptionService: UserSubscriptionService,
22 private i18n: I18n 26 private i18n: I18n
@@ -26,16 +30,30 @@ export class SubscribeButtonComponent implements OnInit {
26 return this.videoChannel.name + '@' + this.videoChannel.host 30 return this.videoChannel.name + '@' + this.videoChannel.host
27 } 31 }
28 32
33 get uriAccount () {
34 return this.videoChannel.ownerAccount.name + '@' + this.videoChannel.host
35 }
36
29 ngOnInit () { 37 ngOnInit () {
30 this.userSubscriptionService.isSubscriptionExists(this.uri) 38 if (this.isUserLoggedIn()) {
31 .subscribe( 39 this.userSubscriptionService.isSubscriptionExists(this.uri)
32 res => this.subscribed = res[this.uri], 40 .subscribe(
41 res => this.subscribed = res[this.uri],
33 42
34 err => this.notificationsService.error(this.i18n('Error'), err.message) 43 err => this.notificationsService.error(this.i18n('Error'), err.message)
35 ) 44 )
45 }
36 } 46 }
37 47
38 subscribe () { 48 subscribe () {
49 if (this.isUserLoggedIn()) {
50 this.localSubscribe()
51 } else {
52 this.gotoLogin()
53 }
54 }
55
56 localSubscribe () {
39 this.userSubscriptionService.addSubscription(this.uri) 57 this.userSubscriptionService.addSubscription(this.uri)
40 .subscribe( 58 .subscribe(
41 () => { 59 () => {
@@ -52,6 +70,12 @@ export class SubscribeButtonComponent implements OnInit {
52 } 70 }
53 71
54 unsubscribe () { 72 unsubscribe () {
73 if (this.isUserLoggedIn()) {
74 this.localUnsubscribe()
75 }
76 }
77
78 localUnsubscribe () {
55 this.userSubscriptionService.deleteSubscription(this.uri) 79 this.userSubscriptionService.deleteSubscription(this.uri)
56 .subscribe( 80 .subscribe(
57 () => { 81 () => {
@@ -66,4 +90,16 @@ export class SubscribeButtonComponent implements OnInit {
66 err => this.notificationsService.error(this.i18n('Error'), err.message) 90 err => this.notificationsService.error(this.i18n('Error'), err.message)
67 ) 91 )
68 } 92 }
93
94 isUserLoggedIn () {
95 return this.authService.isLoggedIn()
96 }
97
98 gotoLogin () {
99 this.router.navigate([ '/login' ])
100 }
101
102 rssOpen () {
103 window.open('')
104 }
69} 105}