aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+accounts/accounts.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+accounts/accounts.component.ts')
-rw-r--r--client/src/app/+accounts/accounts.component.ts37
1 files changed, 22 insertions, 15 deletions
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'
3import { AccountService } from '@app/shared/account/account.service' 3import { AccountService } from '@app/shared/account/account.service'
4import { Account } from '@app/shared/account/account.model' 4import { Account } from '@app/shared/account/account.model'
5import { RestExtractor, UserService } from '@app/shared' 5import { RestExtractor, UserService } from '@app/shared'
6import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators' 6import { catchError, distinctUntilChanged, first, map, switchMap, tap } from 'rxjs/operators'
7import { Subscription } from 'rxjs' 7import { forkJoin, Subscription } from 'rxjs'
8import { AuthService, Notifier, RedirectService } from '@app/core' 8import { AuthService, Notifier, RedirectService } from '@app/core'
9import { User, UserRight } from '../../../../shared' 9import { User, UserRight } from '../../../../shared'
10import { I18n } from '@ngx-translate/i18n-polyfill' 10import { I18n } from '@ngx-translate/i18n-polyfill'
@@ -17,9 +17,12 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
17}) 17})
18export class AccountsComponent implements OnInit, OnDestroy { 18export class AccountsComponent implements OnInit, OnDestroy {
19 account: Account 19 account: Account
20 user: User 20 accountUser: User
21 videoChannels: VideoChannel[] = [] 21 videoChannels: VideoChannel[] = []
22 22
23 isAccountManageable = false
24 accountFollowerTitle = ''
25
23 private routeSub: Subscription 26 private routeSub: Subscription
24 27
25 constructor ( 28 constructor (
@@ -42,6 +45,14 @@ export class AccountsComponent implements OnInit, OnDestroy {
42 switchMap(accountId => this.accountService.getAccount(accountId)), 45 switchMap(accountId => this.accountService.getAccount(accountId)),
43 tap(account => { 46 tap(account => {
44 this.account = account 47 this.account = account
48
49 this.isAccountManageable = this.account.userId && this.account.userId === this.authService.getUser().id
50
51 this.accountFollowerTitle = this.i18n(
52 '{{followers}} direct account followers',
53 { followers: this.subscribersDisplayFor(account.followersCount) }
54 )
55
45 this.getUserIfNeeded(account) 56 this.getUserIfNeeded(account)
46 }), 57 }),
47 switchMap(account => this.videoChannelService.listAccountVideoChannels(account)), 58 switchMap(account => this.videoChannelService.listAccountVideoChannels(account)),
@@ -65,11 +76,6 @@ export class AccountsComponent implements OnInit, OnDestroy {
65 ) 76 )
66 } 77 }
67 78
68 get isManageable () {
69 if (!this.authService.isLoggedIn()) return false
70 return this.user.id === this.authService.getUser().id
71 }
72
73 onUserChanged () { 79 onUserChanged () {
74 this.getUserIfNeeded(this.account) 80 this.getUserIfNeeded(this.account)
75 } 81 }
@@ -87,17 +93,18 @@ export class AccountsComponent implements OnInit, OnDestroy {
87 } 93 }
88 94
89 private getUserIfNeeded (account: Account) { 95 private getUserIfNeeded (account: Account) {
90 if (!account.userId) return 96 if (!account.userId || !this.authService.isLoggedIn()) return
91 if (!this.authService.isLoggedIn()) return
92 97
93 const user = this.authService.getUser() 98 const user = this.authService.getUser()
94 if (user.hasRight(UserRight.MANAGE_USERS)) { 99 if (user.hasRight(UserRight.MANAGE_USERS)) {
95 this.userService.getUser(account.userId) 100 forkJoin([
96 .subscribe( 101 this.userService.getUser(account.userId),
97 user => this.user = user, 102 this.authService.userInformationLoaded.pipe(first())
103 ]).subscribe(
104 ([ accountUser ]) => this.accountUser = accountUser,
98 105
99 err => this.notifier.error(err.message) 106 err => this.notifier.error(err.message)
100 ) 107 )
101 } 108 }
102 } 109 }
103} 110}