]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+accounts/accounts.component.ts
Add action dropdown descriptions
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / accounts.component.ts
index e3a503f4cb8ac97d91d9e033dbfd55293d2a9c06..3d486f084e5ccf02a073d313c7dc98c264a30945 100644 (file)
@@ -18,7 +18,7 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
 export class AccountsComponent implements OnInit, OnDestroy {
   account: Account
   user: User
-  videoChannels: VideoChannel[]
+  videoChannels: VideoChannel[] = []
 
   private routeSub: Subscription
 
@@ -40,15 +40,15 @@ export class AccountsComponent implements OnInit, OnDestroy {
         map(params => params[ 'accountId' ]),
         distinctUntilChanged(),
         switchMap(accountId => this.accountService.getAccount(accountId)),
-        tap(account => this.getUserIfNeeded(account)),
+        tap(account => {
+          this.account = account
+          this.getUserIfNeeded(account)
+        }),
+        switchMap(account => this.videoChannelService.listAccountVideoChannels(account)),
         catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
       )
       .subscribe(
-        account => {
-          this.account = account
-          this.videoChannelService.listAccountVideoChannels(account)
-            .subscribe(videoChannels => this.videoChannels = videoChannels.data)
-        },
+        videoChannels => this.videoChannels = videoChannels.data,
 
         err => this.notifier.error(err.message)
       )
@@ -58,6 +58,18 @@ export class AccountsComponent implements OnInit, OnDestroy {
     if (this.routeSub) this.routeSub.unsubscribe()
   }
 
+  get naiveAggregatedSubscribers () {
+    return this.videoChannels.reduce(
+      (acc, val) => acc + val.followersCount,
+      this.account.followersCount // accumulator starts with the base number of subscribers the account has
+    )
+  }
+
+  get isManageable () {
+    if (!this.authService.isLoggedIn()) return false
+    return this.user.id === this.authService.getUser().id
+  }
+
   onUserChanged () {
     this.getUserIfNeeded(this.account)
   }
@@ -70,6 +82,10 @@ export class AccountsComponent implements OnInit, OnDestroy {
     this.notifier.success(this.i18n('Username copied'))
   }
 
+  subscribersDisplayFor (count: number) {
+    return this.i18n(`{count, plural, =1 {1 subscriber} other {${count} subscribers}}`, { count })
+  }
+
   private getUserIfNeeded (account: Account) {
     if (!account.userId) return
     if (!this.authService.isLoggedIn()) return