aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts73
1 files changed, 38 insertions, 35 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
index c767f19b2..fa104cc43 100644
--- a/client/src/app/menu/menu.component.ts
+++ b/client/src/app/menu/menu.component.ts
@@ -8,7 +8,8 @@ import {
8 AuthService, 8 AuthService,
9 AuthStatus, 9 AuthStatus,
10 AuthUser, 10 AuthUser,
11 MenuLink, 11 HooksService,
12 MenuSection,
12 MenuService, 13 MenuService,
13 RedirectService, 14 RedirectService,
14 ScreenService, 15 ScreenService,
@@ -45,7 +46,7 @@ export class MenuComponent implements OnInit {
45 46
46 currentInterfaceLanguage: string 47 currentInterfaceLanguage: string
47 48
48 commonMenuLinks: MenuLink[] = [] 49 menuSections: MenuSection[] = []
49 50
50 private languages: VideoConstant<string>[] = [] 51 private languages: VideoConstant<string>[] = []
51 52
@@ -71,7 +72,8 @@ export class MenuComponent implements OnInit {
71 private screenService: ScreenService, 72 private screenService: ScreenService,
72 private menuService: MenuService, 73 private menuService: MenuService,
73 private modalService: PeertubeModalService, 74 private modalService: PeertubeModalService,
74 private router: Router 75 private router: Router,
76 private hooks: HooksService
75 ) { } 77 ) { }
76 78
77 get isInMobileView () { 79 get isInMobileView () {
@@ -88,46 +90,23 @@ export class MenuComponent implements OnInit {
88 return this.languageChooserModal.getCurrentLanguage() 90 return this.languageChooserModal.getCurrentLanguage()
89 } 91 }
90 92
91 get instanceName () {
92 return this.htmlServerConfig.instance.name
93 }
94
95 ngOnInit () { 93 ngOnInit () {
96 this.htmlServerConfig = this.serverService.getHTMLConfig() 94 this.htmlServerConfig = this.serverService.getHTMLConfig()
97 this.buildMenuLinks()
98
99 this.isLoggedIn = this.authService.isLoggedIn()
100 if (this.isLoggedIn === true) {
101 this.user = this.authService.getUser()
102
103 this.computeNSFWPolicy()
104 this.computeVideosLink()
105 }
106
107 this.computeAdminAccess()
108
109 this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage() 95 this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage()
110 96
97 this.updateUserState()
98 this.buildMenuSections()
99
111 this.authService.loginChangedSource.subscribe( 100 this.authService.loginChangedSource.subscribe(
112 status => { 101 status => {
113 if (status === AuthStatus.LoggedIn) { 102 if (status === AuthStatus.LoggedIn) {
114 this.isLoggedIn = true 103 this.isLoggedIn = true
115 this.user = this.authService.getUser()
116
117 this.computeAdminAccess()
118 this.computeVideosLink()
119
120 logger('Logged in.')
121 } else if (status === AuthStatus.LoggedOut) { 104 } else if (status === AuthStatus.LoggedOut) {
122 this.isLoggedIn = false 105 this.isLoggedIn = false
123 this.user = undefined
124
125 this.computeAdminAccess()
126
127 logger('Logged out.')
128 } else {
129 console.error('Unknown auth status: ' + status)
130 } 106 }
107
108 this.updateUserState()
109 this.buildMenuSections()
131 } 110 }
132 ) 111 )
133 112
@@ -257,8 +236,20 @@ export class MenuComponent implements OnInit {
257 } 236 }
258 } 237 }
259 238
260 private buildMenuLinks () { 239 private async buildMenuSections () {
261 this.commonMenuLinks = this.menuService.buildCommonLinks(this.htmlServerConfig) 240 const menuSections = []
241
242 if (this.isLoggedIn) {
243 menuSections.push(
244 this.menuService.buildLibraryLinks(this.user?.canSeeVideosLink)
245 )
246 }
247
248 menuSections.push(
249 this.menuService.buildCommonLinks(this.htmlServerConfig)
250 )
251
252 this.menuSections = await this.hooks.wrapObject(menuSections, 'common', 'filter:left-menu.links.create.result')
262 } 253 }
263 254
264 private buildUserLanguages () { 255 private buildUserLanguages () {
@@ -268,7 +259,7 @@ export class MenuComponent implements OnInit {
268 } 259 }
269 260
270 if (!this.user.videoLanguages) { 261 if (!this.user.videoLanguages) {
271 this.videoLanguages = [$localize`any language`] 262 this.videoLanguages = [ $localize`any language` ]
272 return 263 return
273 } 264 }
274 265
@@ -284,6 +275,8 @@ export class MenuComponent implements OnInit {
284 } 275 }
285 276
286 private computeVideosLink () { 277 private computeVideosLink () {
278 if (!this.isLoggedIn) return
279
287 this.authService.userInformationLoaded 280 this.authService.userInformationLoaded
288 .pipe( 281 .pipe(
289 switchMap(() => this.user.computeCanSeeVideosLink(this.userService.getMyVideoQuotaUsed())) 282 switchMap(() => this.user.computeCanSeeVideosLink(this.userService.getMyVideoQuotaUsed()))
@@ -313,4 +306,14 @@ export class MenuComponent implements OnInit {
313 break 306 break
314 } 307 }
315 } 308 }
309
310 private updateUserState () {
311 this.user = this.isLoggedIn
312 ? this.authService.getUser()
313 : undefined
314
315 this.computeAdminAccess()
316 this.computeNSFWPolicy()
317 this.computeVideosLink()
318 }
316} 319}