Use search client scope
authorChocobozzz <me@florianbigard.com>
Mon, 22 Jul 2019 14:04:44 +0000 (16:04 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Wed, 24 Jul 2019 08:58:16 +0000 (10:58 +0200)
client/src/app/core/plugins/plugin.service.ts
client/src/app/search/search.component.ts
client/src/app/videos/+video-watch/comment/video-comment.service.ts
client/src/app/videos/+video-watch/comment/video-comments.component.ts
client/src/app/videos/+video-watch/video-watch.component.ts
shared/models/plugins/plugin-client-scope.type.ts
shared/models/plugins/plugin-package-json.model.ts
shared/models/server/server-config.model.ts

index 14310f093670b053039a68d33ee3c68ae990d5f7..7c1d69bec49a0c822a66029a6b8a580092a5b492 100644 (file)
@@ -28,6 +28,7 @@ export class PluginService implements ClientHook {
 
   pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = {
     common: new ReplaySubject<boolean>(1),
+    search: new ReplaySubject<boolean>(1),
     'video-watch': new ReplaySubject<boolean>(1)
   }
 
@@ -109,7 +110,11 @@ export class PluginService implements ClientHook {
       if (!isReload) this.loadedScopes.push(scope)
 
       const toLoad = this.scopes[ scope ]
-      if (!Array.isArray(toLoad)) return
+      if (!Array.isArray(toLoad)) {
+        this.pluginsLoaded[scope].next(true)
+
+        return
+      }
 
       const promises: Promise<any>[] = []
       for (const pluginInfo of toLoad) {
index b1d732d68d3b361e1da5d587188cc71ca610ce2e..55637771e45f76fb042103e2f93feefbfe8fd0f1 100644 (file)
@@ -11,6 +11,7 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
 import { immutableAssign } from '@app/shared/misc/utils'
 import { Video } from '@app/shared/video/video.model'
 import { HooksService } from '@app/core/plugins/hooks.service'
+import { PluginService } from '@app/core/plugins/plugin.service'
 
 @Component({
   selector: 'my-search',
@@ -43,7 +44,8 @@ export class SearchComponent implements OnInit, OnDestroy {
     private notifier: Notifier,
     private searchService: SearchService,
     private authService: AuthService,
-    private hooks: HooksService
+    private hooks: HooksService,
+    private pluginService: PluginService
   ) { }
 
   get user () {
@@ -51,6 +53,8 @@ export class SearchComponent implements OnInit, OnDestroy {
   }
 
   ngOnInit () {
+    this.pluginService.loadPluginsByScope('search')
+
     this.subActivatedRoute = this.route.queryParams.subscribe(
       queryParams => {
         const querySearch = queryParams['search']
@@ -175,7 +179,7 @@ export class SearchComponent implements OnInit, OnDestroy {
     return this.hooks.wrapObsFun(
       this.searchService.searchVideos.bind(this.searchService),
       params,
-      'common',
+      'search',
       'filter:api.search.videos.list.params',
       'filter:api.search.videos.list.result'
     )
@@ -190,7 +194,7 @@ export class SearchComponent implements OnInit, OnDestroy {
     return this.hooks.wrapObsFun(
       this.searchService.searchVideoChannels.bind(this.searchService),
       params,
-      'common',
+      'search',
       'filter:api.search.video-channels.list.params',
       'filter:api.search.video-channels.list.result'
     )
index eb608a1a36a9cec2ddfe57d03dee0642af3c23e7..550d42fa86552c65a2b100ff8691a6b4a26c2f14 100644 (file)
@@ -52,7 +52,7 @@ export class VideoCommentService {
     videoId: number | string,
     componentPagination: ComponentPagination,
     sort: VideoSortField
-  }): Observable<{ comments: VideoComment[], totalComments: number}> {
+  }): Observable<ResultList<VideoComment>> {
     const { videoId, componentPagination, sort } = parameters
 
     const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
@@ -61,10 +61,9 @@ export class VideoCommentService {
     params = this.restService.addRestGetParams(params, pagination, sort)
 
     const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
-    return this.authHttp
-               .get(url, { params })
+    return this.authHttp.get<ResultList<VideoComment>>(url, { params })
                .pipe(
-                 map(this.extractVideoComments),
+                 map(result => this.extractVideoComments(result)),
                  catchError(err => this.restExtractor.handleError(err))
                )
   }
@@ -136,7 +135,7 @@ export class VideoCommentService {
       comments.push(new VideoComment(videoCommentJson))
     }
 
-    return { comments, totalComments }
+    return { data: comments, total: totalComments }
   }
 
   private extractVideoCommentTree (tree: VideoCommentThreadTree) {
index 3c1a0986c7833f8fa64ea98a7f25d311fe3b7c9b..5bafc55e5fa474c560f336424cbd0f70f696b039 100644 (file)
@@ -122,8 +122,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
 
     obs.subscribe(
       res => {
-        this.comments = this.comments.concat(res.comments)
-        this.componentPagination.totalItems = res.totalComments
+        this.comments = this.comments.concat(res.data)
+        this.componentPagination.totalItems = res.total
       },
 
       err => this.notifier.error(err.message)
index eed2ec0486546d3a9a2ad56f591e9cc5cc20df21..0d9b6d680acf950fcf3cdeb2ff8f971924a4537a 100644 (file)
@@ -103,7 +103,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   }
 
   async ngOnInit () {
-    await this.pluginService.loadPluginsByScope('video-watch')
+    this.pluginService.loadPluginsByScope('video-watch')
 
     this.configSub = this.serverService.configLoaded
         .subscribe(() => {
index a2112eed751e2dcb816b5a6d130955e46a586ec0..0c616c5edb08cc637bd31ee92ce6640da9a6d052 100644 (file)
@@ -1 +1 @@
-export type PluginClientScope = 'common' | 'video-watch'
+export type PluginClientScope = 'common' | 'video-watch' | 'search'
index f8029ec3435d5b2cfa0654498e9a05d6a47c761e..87a48e97f78c57aef7c7972b04dc9e38bead0c8d 100644 (file)
@@ -1,6 +1,8 @@
+import { PluginClientScope } from './plugin-client-scope.type'
+
 export type ClientScript = {
   script: string,
-  scopes: string[]
+  scopes: PluginClientScope[]
 }
 
 export type PluginPackageJson = {
index 49bb01708cbae88876d9a7d7d5e549741044869c..3498f86d77be9db4439a05d042baf51c8db8d67c 100644 (file)
@@ -1,12 +1,11 @@
 import { NSFWPolicyType } from '../videos/nsfw-policy.type'
 import { ClientScript } from '../plugins/plugin-package-json.model'
-import { PluginClientScope } from '../plugins/plugin-scope.type'
 
 export interface ServerConfigPlugin {
   name: string
   version: string
   description: string
-  clientScripts: { [name in PluginClientScope]: ClientScript }
+  clientScripts: { [name: string]: ClientScript }
 }
 
 export interface ServerConfigTheme extends ServerConfigPlugin {