Add naive aggregation from channels to account display of subscribers
authorRigel Kent <sendmemail@rigelk.eu>
Fri, 10 Jan 2020 15:22:55 +0000 (16:22 +0100)
committerRigel Kent <sendmemail@rigelk.eu>
Fri, 10 Jan 2020 15:23:55 +0000 (16:23 +0100)
client/src/app/+accounts/accounts.component.html
client/src/app/+accounts/accounts.component.ts

index be40b63cae971d8cd22579af3aeb910a9c540754..57498e98c85c68298438207fb85935a5962012f8 100644 (file)
@@ -28,7 +28,9 @@
           >
           </my-user-moderation-dropdown>
         </div>
-        <div class="actor-followers" i18n>{account.followersCount, plural, =1 {1 subscriber} other {{{ account.followersCount }} subscribers}}</div>
+        <div class="actor-followers" i18n-title [title]="subscribersDisplayFor(account.followersCount) + ' to the account actor'">
+          {{ subscribersDisplayFor(naiveAggregatedSubscribers) }}
+        </div>
       </div>
 
       <my-subscribe-button *ngIf="videoChannels" [account]="account" [videoChannels]="videoChannels"></my-subscribe-button>
index 8bde7ad070689123a34b1acd9c98b12e1a859918..da4a0b28e72d156c7b19365c8bf268bf0d4cfa94 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
 
@@ -58,6 +58,13 @@ 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
+    )
+  }
+
   onUserChanged () {
     this.getUserIfNeeded(this.account)
   }
@@ -70,6 +77,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