]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+search/search.component.ts
wt-plugin: clearify err msg
[github/Chocobozzz/PeerTube.git] / client / src / app / +search / search.component.ts
index 1ed54937b510ecf7a1d3a6e03f0b1b77bb4acc4f..2be952e161b9306b9afafaa1ba651dc3e4123d85 100644 (file)
@@ -5,9 +5,8 @@ import { AuthService, ComponentPagination, HooksService, Notifier, ServerService
 import { immutableAssign } from '@app/helpers'
 import { Video, VideoChannel } from '@app/shared/shared-main'
 import { AdvancedSearch, SearchService } from '@app/shared/shared-search'
-import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
+import { MiniatureDisplayOptions, VideoLinkType } from '@app/shared/shared-video-miniature'
 import { MetaService } from '@ngx-meta/core'
-import { I18n } from '@ngx-translate/i18n-polyfill'
 import { SearchTargetType, ServerConfig } from '@shared/models'
 
 @Component({
@@ -52,7 +51,6 @@ export class SearchComponent implements OnInit, OnDestroy {
   private lastSearchTarget: SearchTargetType
 
   constructor (
-    private i18n: I18n,
     private route: ActivatedRoute,
     private router: Router,
     private metaService: MetaService,
@@ -119,6 +117,25 @@ export class SearchComponent implements OnInit, OnDestroy {
     return this.authService.isLoggedIn()
   }
 
+  getVideoLinkType (): VideoLinkType {
+    if (this.advancedSearch.searchTarget === 'search-index') {
+      const remoteUriConfig = this.serverConfig.search.remoteUri
+
+      // Redirect on the external instance if not allowed to fetch remote data
+      if ((!this.isUserLoggedIn() && !remoteUriConfig.anonymous) || !remoteUriConfig.users) {
+        return 'external'
+      }
+
+      return 'lazy-load'
+    }
+
+    return 'internal'
+  }
+
+  isExternalChannelUrl () {
+    return this.getVideoLinkType() === 'external'
+  }
+
   search () {
     forkJoin([
       this.getVideosObs(),
@@ -151,8 +168,8 @@ export class SearchComponent implements OnInit, OnDestroy {
         }
 
         this.notifier.error(
-          this.i18n('Search index is unavailable. Retrying with instance results instead.'),
-          this.i18n('Search error')
+          $localize`Search index is unavailable. Retrying with instance results instead.`,
+          $localize`Search error`
         )
         this.advancedSearch.searchTarget = 'local'
         this.search()
@@ -184,17 +201,16 @@ export class SearchComponent implements OnInit, OnDestroy {
   }
 
   getChannelUrl (channel: VideoChannel) {
-    if (this.advancedSearch.searchTarget === 'search-index' && channel.url) {
-      const remoteUriConfig = this.serverConfig.search.remoteUri
-
-      // Redirect on the external instance if not allowed to fetch remote data
-      const externalRedirect = (!this.authService.isLoggedIn() && !remoteUriConfig.anonymous) || !remoteUriConfig.users
-      const fromPath = window.location.pathname + window.location.search
+    // Same algorithm than videos
+    if (this.getVideoLinkType() === 'external') {
+      return channel.url
+    }
 
-      return [ '/search/lazy-load-channel', { url: channel.url, externalRedirect, fromPath } ]
+    if (this.getVideoLinkType() === 'internal') {
+      return [ '/video-channels', channel.nameWithHost ]
     }
 
-    return [ '/video-channels', channel.nameWithHost ]
+    return [ '/search/lazy-load-channel', { url: channel.url } ]
   }
 
   hideActions () {
@@ -211,7 +227,7 @@ export class SearchComponent implements OnInit, OnDestroy {
 
   private updateTitle () {
     const suffix = this.currentSearch ? ' ' + this.currentSearch : ''
-    this.metaService.setTitle(this.i18n('Search') + suffix)
+    this.metaService.setTitle($localize`Search` + suffix)
   }
 
   private updateUrlFromAdvancedSearch () {