]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/user-subscription/subscribe-button.component.ts
Generate translations
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / user-subscription / subscribe-button.component.ts
index 95c2bb8f8a8289415fd1d8dd4add1a45c3a4e434..0407856cbd1d89827e404e99974a6fddcc23062d 100644 (file)
@@ -1,9 +1,8 @@
 import { Component, Input, OnInit } from '@angular/core'
 import { Router } from '@angular/router'
-import { AuthService } from '@app/core'
+import { AuthService, Notifier } from '@app/core'
 import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
-import { NotificationsService } from 'angular2-notifications'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { VideoService } from '@app/shared/video/video.service'
 import { FeedFormat } from '../../../../../shared/models/feeds'
@@ -23,52 +22,62 @@ export class SubscribeButtonComponent implements OnInit {
   constructor (
     private authService: AuthService,
     private router: Router,
-    private notificationsService: NotificationsService,
+    private notifier: Notifier,
     private userSubscriptionService: UserSubscriptionService,
     private i18n: I18n,
     private videoService: VideoService
   ) { }
 
-  get uri () {
+  get channelHandle () {
     return this.videoChannel.name + '@' + this.videoChannel.host
   }
 
-  get uriAccount () {
-    return this.videoChannel.ownerAccount.name + '@' + this.videoChannel.host
+  get channelUri () {
+    return this.videoChannel.url
+  }
+
+  get rssUri () {
+    const rssFeed = this.videoService
+                      .getVideoChannelFeedUrls(this.videoChannel.id)
+                      .find(i => i.format === FeedFormat.RSS)
+
+    return rssFeed.url
   }
 
   ngOnInit () {
     if (this.isUserLoggedIn()) {
-      this.userSubscriptionService.isSubscriptionExists(this.uri)
+      this.userSubscriptionService.doesSubscriptionExist(this.channelHandle)
         .subscribe(
-          res => this.subscribed = res[this.uri],
+          res => this.subscribed = res[this.channelHandle],
 
-          err => this.notificationsService.error(this.i18n('Error'), err.message)
+          err => this.notifier.error(err.message)
         )
     }
   }
 
   subscribe () {
     if (this.isUserLoggedIn()) {
-      this.localSubscribe()
-    } else {
-      this.gotoLogin()
+      return this.localSubscribe()
     }
+
+    return this.gotoLogin()
   }
 
   localSubscribe () {
-    this.userSubscriptionService.addSubscription(this.uri)
+    this.userSubscriptionService.addSubscription(this.channelHandle)
       .subscribe(
         () => {
           this.subscribed = true
 
-          this.notificationsService.success(
-            this.i18n('Subscribed'),
-            this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
+          this.notifier.success(
+            this.i18n('Subscribed to {{nameWithHost}}. You will be notified of all their new videos.',
+              { nameWithHost: this.videoChannel.displayName }
+            ),
+            this.i18n('Subscribed')
           )
         },
 
-          err => this.notificationsService.error(this.i18n('Error'), err.message)
+          err => this.notifier.error(err.message)
       )
   }
 
@@ -79,18 +88,18 @@ export class SubscribeButtonComponent implements OnInit {
   }
 
   localUnsubscribe () {
-    this.userSubscriptionService.deleteSubscription(this.uri)
+    this.userSubscriptionService.deleteSubscription(this.channelHandle)
         .subscribe(
           () => {
             this.subscribed = false
 
-            this.notificationsService.success(
-              this.i18n('Unsubscribed'),
-              this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
+            this.notifier.success(
+              this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }),
+              this.i18n('Unsubscribed')
             )
           },
 
-          err => this.notificationsService.error(this.i18n('Error'), err.message)
+          err => this.notifier.error(err.message)
         )
   }
 
@@ -101,12 +110,4 @@ export class SubscribeButtonComponent implements OnInit {
   gotoLogin () {
     this.router.navigate([ '/login' ])
   }
-
-  rssOpen () {
-    const rssFeed = this.videoService
-                      .getVideoChannelFeedUrls(this.videoChannel.id)
-                      .find(i => i.format === FeedFormat.RSS)
-
-    window.open(rssFeed.url)
-  }
 }