X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Baccounts%2Faccounts.component.ts;h=01911cac286892648079c6dc1a38d6f5820a5bd7;hb=8ca56654a176ee8f350d31282c6cac4a59f58499;hp=e3a503f4cb8ac97d91d9e033dbfd55293d2a9c06;hpb=41eb700fceee1085dd0e1a9ce78ecbd0e111eb6e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index e3a503f4c..01911cac2 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -1,15 +1,11 @@ +import { Subscription } from 'rxjs' +import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators' import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute } from '@angular/router' -import { AccountService } from '@app/shared/account/account.service' -import { Account } from '@app/shared/account/account.model' -import { RestExtractor, UserService } from '@app/shared' -import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators' -import { Subscription } from 'rxjs' -import { AuthService, Notifier, RedirectService } from '@app/core' -import { User, UserRight } from '../../../../shared' +import { AuthService, Notifier, RedirectService, RestExtractor, ScreenService, UserService } from '@app/core' +import { Account, AccountService, ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main' import { I18n } from '@ngx-translate/i18n-polyfill' -import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' -import { VideoChannel } from '@app/shared/video-channel/video-channel.model' +import { User, UserRight } from '@shared/models' @Component({ templateUrl: './accounts.component.html', @@ -17,8 +13,12 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model' }) export class AccountsComponent implements OnInit, OnDestroy { account: Account - user: User - videoChannels: VideoChannel[] + accountUser: User + videoChannels: VideoChannel[] = [] + links: ListOverflowItem[] = [] + + isAccountManageable = false + accountFollowerTitle = '' private routeSub: Subscription @@ -31,33 +31,66 @@ export class AccountsComponent implements OnInit, OnDestroy { private restExtractor: RestExtractor, private redirectService: RedirectService, private authService: AuthService, + private screenService: ScreenService, private i18n: I18n - ) {} + ) { + } ngOnInit () { this.routeSub = this.route.params - .pipe( - map(params => params[ 'accountId' ]), - distinctUntilChanged(), - switchMap(accountId => this.accountService.getAccount(accountId)), - tap(account => this.getUserIfNeeded(account)), - catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) - ) - .subscribe( - account => { - this.account = account - this.videoChannelService.listAccountVideoChannels(account) - .subscribe(videoChannels => this.videoChannels = videoChannels.data) - }, + .pipe( + map(params => params[ 'accountId' ]), + distinctUntilChanged(), + switchMap(accountId => this.accountService.getAccount(accountId)), + tap(account => { + this.account = account - err => this.notifier.error(err.message) - ) + if (this.authService.isLoggedIn()) { + this.authService.userInformationLoaded.subscribe( + () => { + this.isAccountManageable = this.account.userId && this.account.userId === this.authService.getUser().id + + this.accountFollowerTitle = this.i18n( + '{{followers}} direct account followers', + { followers: this.subscribersDisplayFor(account.followersCount) } + ) + } + ) + } + + this.getUserIfNeeded(account) + }), + switchMap(account => this.videoChannelService.listAccountVideoChannels(account)), + catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) + ) + .subscribe( + videoChannels => this.videoChannels = videoChannels.data, + + err => this.notifier.error(err.message) + ) + + this.links = [ + { label: this.i18n('VIDEO CHANNELS'), routerLink: 'video-channels' }, + { label: this.i18n('VIDEOS'), routerLink: 'videos' }, + { label: this.i18n('ABOUT'), routerLink: 'about' } + ] } ngOnDestroy () { 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 isInSmallView () { + return this.screenService.isInSmallView() + } + onUserChanged () { this.getUserIfNeeded(this.account) } @@ -70,18 +103,20 @@ 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 + if (!account.userId || !this.authService.isLoggedIn()) return const user = this.authService.getUser() if (user.hasRight(UserRight.MANAGE_USERS)) { - this.userService.getUser(account.userId) - .subscribe( - user => this.user = user, + this.userService.getUser(account.userId).subscribe( + accountUser => this.accountUser = accountUser, - err => this.notifier.error(err.message) - ) + err => this.notifier.error(err.message) + ) } } }