]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Filter videos by live in custom markup
authorChocobozzz <me@florianbigard.com>
Mon, 2 Aug 2021 14:50:56 +0000 (16:50 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 2 Aug 2021 15:10:07 +0000 (17:10 +0200)
client/src/app/shared/shared-custom-markup/custom-markup.service.ts
client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
client/src/app/shared/shared-custom-markup/peertube-custom-tags/playlist-miniature-markup.component.ts
client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.ts
client/src/app/shared/shared-custom-markup/peertube-custom-tags/videos-list-markup.component.ts
client/src/app/shared/shared-main/video/video.service.ts
client/src/app/shared/shared-search/find-in-bulk.service.ts
shared/models/custom-markup/custom-markup-data.model.ts

index 089728a51ab8e551db794f597985a4b9a7e12b85..c9d33980ef466f0ac1af9ea09be3412c57270566 100644 (file)
@@ -191,6 +191,8 @@ export class CustomMarkupService {
       accountHandle: data.accountHandle || undefined,
       channelHandle: data.channelHandle || undefined,
 
+      isLive: this.buildBoolean(data.isLive),
+
       filter: this.buildBoolean(data.onlyLocal) ? 'local' as VideoFilter : undefined
     }
 
index bb099deae476233b702dbdd5b2c7133f818eb9df..5bb045a8230ff6dfe60358ed29caafbd39167dd5 100644 (file)
@@ -50,7 +50,7 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
           this.video = data[0]
         },
 
-        err => this.notifier.error('Error in channel miniature component: ' + err.message)
+        err => this.notifier.error($localize`Error in channel miniature component: ${err.message}`)
       )
   }
 
index 97d31c4a78fbcb9558663175f17cc161092f6617..5a5c348670275a8c07ab9470f9459da9bce29670 100644 (file)
@@ -44,7 +44,7 @@ export class PlaylistMiniatureMarkupComponent implements CustomMarkupComponent,
       .subscribe(
         playlist => this.playlist = playlist,
 
-        err => this.notifier.error('Error in playlist miniature component: ' + err.message)
+        err => this.notifier.error($localize`Error in playlist miniature component: ${err.message}`)
       )
   }
 }
index ba61aaf51bfe82d6c71bb9bf6b872c0b6d337b6e..84c936ee74a543e65b06f1adb49d7d03886ae488 100644 (file)
@@ -56,7 +56,7 @@ export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnI
       .subscribe(
         video => this.video = video,
 
-        err => this.notifier.error('Error in video miniature component: ' + err.message)
+        err => this.notifier.error($localize`Error in video miniature component: ${err.message}`)
       )
   }
 }
index d9f77802b91e956ed55e9e38ad8d567336aef055..6473e9ba064f500ba00f1af254a6c59fb379ea5f 100644 (file)
@@ -22,6 +22,7 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
   @Input() count: number
   @Input() onlyDisplayTitle: boolean
   @Input() filter: VideoFilter
+  @Input() isLive: boolean
   @Input() maxRows: number
   @Input() channelHandle: string
   @Input() accountHandle: string
@@ -73,7 +74,7 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
       .subscribe(
         ({ data }) => this.videos = data,
 
-        err => this.notifier.error('Error in videos list component: ' + err.message)
+        err => this.notifier.error($localize`Error in videos list component: ${err.message}`)
       )
   }
 
@@ -86,6 +87,7 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
       categoryOneOf: this.categoryOneOf,
       languageOneOf: this.languageOneOf,
       filter: this.filter,
+      isLive: this.isLive,
       sort: this.sort as VideoSortField,
       account: { nameWithHost: this.accountHandle },
       videoChannel: { nameWithHost: this.channelHandle }
index 04a39be0e7976ad904172c7477e11ba79eb08b4b..4a97719fa96858749800dabf244eddc4642766e0 100644 (file)
@@ -210,15 +210,16 @@ export class VideoService implements VideosProvider {
   }
 
   getVideos (parameters: {
-    videoPagination: ComponentPaginationLight,
-    sort: VideoSortField,
-    filter?: VideoFilter,
-    categoryOneOf?: number[],
-    languageOneOf?: string[],
-    skipCount?: boolean,
+    videoPagination: ComponentPaginationLight
+    sort: VideoSortField
+    filter?: VideoFilter
+    categoryOneOf?: number[]
+    languageOneOf?: string[]
+    isLive?: boolean
+    skipCount?: boolean
     nsfwPolicy?: NSFWPolicyType
   }): Observable<ResultList<Video>> {
-    const { videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount, nsfwPolicy } = parameters
+    const { videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount, nsfwPolicy, isLive } = parameters
 
     const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
 
@@ -228,21 +229,10 @@ export class VideoService implements VideosProvider {
     if (filter) params = params.set('filter', filter)
     if (skipCount) params = params.set('skipCount', skipCount + '')
 
-    if (nsfwPolicy) {
-      params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy))
-    }
-
-    if (languageOneOf) {
-      for (const l of languageOneOf) {
-        params = params.append('languageOneOf[]', l)
-      }
-    }
-
-    if (categoryOneOf) {
-      for (const c of categoryOneOf) {
-        params = params.append('categoryOneOf[]', c + '')
-      }
-    }
+    if (isLive) params = params.set('isLive', isLive)
+    if (nsfwPolicy) params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy))
+    if (languageOneOf) this.restService.addArrayParams(params, 'languageOneOf', languageOneOf)
+    if (categoryOneOf) this.restService.addArrayParams(params, 'categoryOneOf', categoryOneOf)
 
     return this.authHttp
                .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
index 0383d864805474461fda182c772e5b23dcee76e6..61dd2cbc56a3d6adafc0192735b4d635c877d36b 100644 (file)
@@ -1,6 +1,6 @@
 import * as debug from 'debug'
-import { Observable, Subject } from 'rxjs'
-import { map } from 'rxjs/operators'
+import { Observable, Subject, throwError } from 'rxjs'
+import { first, map } from 'rxjs/operators'
 import { Injectable, NgZone } from '@angular/core'
 import { buildBulkObservable } from '@app/helpers'
 import { ResultList } from '@shared/models/common'
@@ -71,12 +71,17 @@ export class FindInBulkService {
     return new Observable<R>(obs => {
       observableObject.result
         .pipe(
+          first(),
           map(({ data }) => data),
           map(data => data.find(finder))
         )
         .subscribe(result => {
-          obs.next(result)
-          obs.complete()
+          if (!result) {
+            obs.error(new Error($localize`Element ${param} not found`))
+          } else {
+            obs.next(result)
+            obs.complete()
+          }
         })
 
       observableObject.notifier.next(param)
index 8cbe3cfa4731ea680f2500008350af4805f4f705..667eaad9c0c3cb30178a6087db0968905f556100 100644 (file)
@@ -36,6 +36,8 @@ export type VideosListMarkupData = {
   channelHandle?: string
   accountHandle?: string
 
+  isLive?: string // number
+
   onlyLocal?: string // boolean
 }