X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fapp%2F%2Baccounts%2Faccounts.component.ts;h=b06ecfe0e49db6fe0c7a03fc28911c0ad4ad6b72;hb=496b02e38f272622a84ba22db412858d478ae7b0;hp=3d486f084e5ccf02a073d313c7dc98c264a30945;hpb=36619ac8f50daf51a46658f0b530495ba3a0b6bf;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index 3d486f084..b06ecfe0e 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -3,8 +3,8 @@ 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 { catchError, distinctUntilChanged, first, map, switchMap, tap } from 'rxjs/operators' +import { forkJoin, Subscription } from 'rxjs' import { AuthService, Notifier, RedirectService } from '@app/core' import { User, UserRight } from '../../../../shared' import { I18n } from '@ngx-translate/i18n-polyfill' @@ -17,9 +17,12 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model' }) export class AccountsComponent implements OnInit, OnDestroy { account: Account - user: User + accountUser: User videoChannels: VideoChannel[] = [] + isAccountManageable = false + accountFollowerTitle = '' + private routeSub: Subscription constructor ( @@ -42,6 +45,14 @@ export class AccountsComponent implements OnInit, OnDestroy { switchMap(accountId => this.accountService.getAccount(accountId)), tap(account => { this.account = account + + 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)), @@ -65,11 +76,6 @@ export class AccountsComponent implements OnInit, OnDestroy { ) } - get isManageable () { - if (!this.authService.isLoggedIn()) return false - return this.user.id === this.authService.getUser().id - } - onUserChanged () { this.getUserIfNeeded(this.account) } @@ -87,17 +93,18 @@ export class AccountsComponent implements OnInit, OnDestroy { } 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, + forkJoin([ + this.userService.getUser(account.userId), + this.authService.userInformationLoaded.pipe(first()) + ]).subscribe( + ([ accountUser ]) => this.accountUser = accountUser, - err => this.notifier.error(err.message) - ) + err => this.notifier.error(err.message) + ) } } }