]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-user-subscription/subscribe-button.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-user-subscription / subscribe-button.component.ts
index 72fa3f4fd4240cef2435992d0110be8f42a8b3c2..a002bf4e7d749919297e20df7e1c02f1ab6b365c 100644 (file)
@@ -1,9 +1,7 @@
 import { concat, forkJoin, merge } from 'rxjs'
 import { Component, Input, OnChanges, OnInit } from '@angular/core'
-import { Router } from '@angular/router'
-import { AuthService, Notifier } from '@app/core'
+import { AuthService, Notifier, RedirectService } from '@app/core'
 import { Account, VideoChannel, VideoService } from '@app/shared/shared-main'
-import { I18n } from '@ngx-translate/i18n-polyfill'
 import { FeedFormat } from '@shared/models'
 import { UserSubscriptionService } from './user-subscription.service'
 
@@ -28,10 +26,9 @@ export class SubscribeButtonComponent implements OnInit, OnChanges {
 
   constructor (
     private authService: AuthService,
-    private router: Router,
+    private redirectService: RedirectService,
     private notifier: Notifier,
     private userSubscriptionService: UserSubscriptionService,
-    private i18n: I18n,
     private videoService: VideoService
   ) { }
 
@@ -104,25 +101,19 @@ export class SubscribeButtonComponent implements OnInit, OnChanges {
       .map(handle => this.userSubscriptionService.addSubscription(handle))
 
     forkJoin(observableBatch)
-      .subscribe(
-        () => {
+      .subscribe({
+        next: () => {
           this.notifier.success(
             this.account
-              ? this.i18n(
-                  'Subscribed to all current channels of {{nameWithHost}}. You will be notified of all their new videos.',
-                  { nameWithHost: this.account.displayName }
-                )
-              : this.i18n(
-                  'Subscribed to {{nameWithHost}}. You will be notified of all their new videos.',
-                  { nameWithHost: this.videoChannels[0].displayName }
-                )
-            ,
-            this.i18n('Subscribed')
+              ? $localize`Subscribed to all current channels of ${this.account.displayName}. You will be notified of all their new videos.`
+              : $localize`Subscribed to ${this.videoChannels[0].displayName}. You will be notified of all their new videos.`,
+
+            $localize`Subscribed`
           )
         },
 
-          err => this.notifier.error(err.message)
-      )
+        error: err => this.notifier.error(err.message)
+      })
   }
 
   unsubscribe () {
@@ -144,10 +135,10 @@ export class SubscribeButtonComponent implements OnInit, OnChanges {
         complete: () => {
           this.notifier.success(
             this.account
-              ? this.i18n('Unsubscribed from all channels of {{nameWithHost}}', { nameWithHost: this.account.nameWithHost })
-              : this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannels[ 0 ].nameWithHost })
-            ,
-            this.i18n('Unsubscribed')
+              ? $localize`Unsubscribed from all channels of ${this.account.nameWithHost}`
+              : $localize`Unsubscribed from ${this.videoChannels[0].nameWithHost}`,
+
+            $localize`Unsubscribed`
           )
         },
 
@@ -160,18 +151,26 @@ export class SubscribeButtonComponent implements OnInit, OnChanges {
   }
 
   gotoLogin () {
-    this.router.navigate([ '/login' ])
+    this.redirectService.redirectToLogin()
   }
 
   subscribeStatus (subscribed: boolean) {
     const accumulator: string[] = []
-    for (const [key, value] of this.subscribed.entries()) {
+    for (const [ key, value ] of this.subscribed.entries()) {
       if (value === subscribed) accumulator.push(key)
     }
 
     return accumulator
   }
 
+  isSubscribedToAll () {
+    return Array.from(this.subscribed.values()).every(v => v === true)
+  }
+
+  isRemoteSubscribeAvailable () {
+    return !this.isUserLoggedIn()
+  }
+
   private getChannelHandler (videoChannel: VideoChannel) {
     return videoChannel.name + '@' + videoChannel.host
   }
@@ -186,11 +185,11 @@ export class SubscribeButtonComponent implements OnInit, OnChanges {
       merge(
         this.userSubscriptionService.listenToSubscriptionCacheChange(handle),
         this.userSubscriptionService.doesSubscriptionExist(handle)
-      ).subscribe(
-        res => this.subscribed.set(handle, res),
+      ).subscribe({
+        next: res => this.subscribed.set(handle, res),
 
-        err => this.notifier.error(err.message)
-      )
+        error: err => this.notifier.error(err.message)
+      })
     }
   }
 }