]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/video-list/trending/video-trending-header.component.ts
Merge branch 'develop' into shorter-URLs-channels-accounts
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / trending / video-trending-header.component.ts
index 46e65f305dcacaea9e6607b2a1b5afed88429ec1..bbb02a236a80253e87d1bb7f658ddc78fc4303a4 100644 (file)
@@ -4,7 +4,7 @@ import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature'
 import { GlobalIconName } from '@app/shared/shared-icons'
 import { ServerService } from '@app/core/server/server.service'
 import { Subscription } from 'rxjs'
-import { RedirectService } from '@app/core'
+import { AuthService, RedirectService } from '@app/core'
 
 interface VideoTrendingHeaderItem {
   label: string
@@ -30,7 +30,9 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
     @Inject('data') public data: any,
     private route: ActivatedRoute,
     private router: Router,
-    private serverService: ServerService
+    private auth: AuthService,
+    private serverService: ServerService,
+    private redirectService: RedirectService
   ) {
     super(data)
 
@@ -67,20 +69,23 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
   ngOnInit () {
     this.serverService.getConfig()
         .subscribe(config => {
+          const algEnabled = config.trending.videos.algorithms.enabled
+
           this.buttons = this.buttons.map(b => {
-            b.hidden = !config.trending.videos.algorithms.enabled.includes(b.value)
+            b.hidden = !algEnabled.includes(b.value)
+
+            // Best is adapted by the user history so
+            if (b.value === 'best' && !this.auth.isLoggedIn()) {
+              b.hidden = true
+            }
+
             return b
           })
         })
 
     this.algorithmChangeSub = this.route.queryParams.subscribe(
       queryParams => {
-        const algorithm = queryParams['alg']
-        if (algorithm) {
-          this.data.model = algorithm
-        } else {
-          this.data.model = RedirectService.DEFAULT_TRENDING_ALGORITHM
-        }
+        this.data.model = queryParams['alg'] || this.redirectService.getDefaultTrendingAlgorithm()
       }
     )
   }
@@ -90,7 +95,7 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
   }
 
   setSort () {
-    const alg = this.data.model !== RedirectService.DEFAULT_TRENDING_ALGORITHM
+    const alg = this.data.model !== this.redirectService.getDefaultTrendingAlgorithm()
       ? this.data.model
       : undefined