]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
Add plugin hooks/placeholder to share modal
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-block-list / video-block-list.component.ts
index 498d8321aff7b1f538584117df97d152b8ce3741..8d67e9beb42b8c08b91f3e8ef506b2fe86dd1dad 100644 (file)
@@ -1,14 +1,14 @@
 import { SortMeta } from 'primeng/api'
 import { switchMap } from 'rxjs/operators'
-import { buildVideoLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils'
 import { environment } from 'src/environments/environment'
 import { Component, OnInit } from '@angular/core'
-import { DomSanitizer } from '@angular/platform-browser'
 import { ActivatedRoute, Router } from '@angular/router'
 import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
 import { AdvancedInputFilter } from '@app/shared/shared-forms'
-import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
+import { DropdownAction, VideoService } from '@app/shared/shared-main'
 import { VideoBlockService } from '@app/shared/shared-moderation'
+import { buildVideoOrPlaylistEmbed } from '@root-helpers/video'
+import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils'
 import { VideoBlacklist, VideoBlacklistType } from '@shared/models'
 
 @Component({
@@ -17,7 +17,7 @@ import { VideoBlacklist, VideoBlacklistType } from '@shared/models'
   styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ]
 })
 export class VideoBlockListComponent extends RestTable implements OnInit {
-  blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = []
+  blocklist: (VideoBlacklist & { reasonHtml?: string })[] = []
   totalRecords = 0
   sort: SortMeta = { field: 'createdAt', order: -1 }
   pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
@@ -27,12 +27,17 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
 
   inputFilters: AdvancedInputFilter[] = [
     {
-      queryParams: { 'search': 'type:auto' },
-      label: $localize`Automatic blocks`
-    },
-    {
-      queryParams: { 'search': 'type:manual' },
-      label: $localize`Manual blocks`
+      title: $localize`Advanced filters`,
+      children: [
+        {
+          value: 'type:auto',
+          label: $localize`Automatic blocks`
+        },
+        {
+          value: 'type:manual',
+          label: $localize`Manual blocks`
+        }
+      ]
     }
   ]
 
@@ -44,7 +49,6 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
     private confirmService: ConfirmService,
     private videoBlocklistService: VideoBlockService,
     private markdownRenderer: MarkdownService,
-    private sanitizer: DomSanitizer,
     private videoService: VideoService
   ) {
     super()
@@ -60,15 +64,15 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
           label: $localize`Switch video block to manual`,
           handler: videoBlock => {
             this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
-              switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
-            ).subscribe(
-              () => {
+              switchMap(_ => this.videoBlocklistService.blockVideo([ { videoId: videoBlock.video.id, unfederate: true } ]))
+            ).subscribe({
+              next: () => {
                 this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`)
                 this.reloadData()
               },
 
-              err => this.notifier.error(err.message)
-            )
+              error: err => this.notifier.error(err.message)
+            })
           },
           isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
         }
@@ -93,13 +97,11 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
             if (res === false) return
 
             this.videoService.removeVideo(videoBlock.video.id)
-              .subscribe(
-                () => {
-                  this.notifier.success($localize`Video deleted.`)
-                },
+              .subscribe({
+                next: () => this.notifier.success($localize`Video deleted.`),
 
-                err => this.notifier.error(err.message)
-              )
+                error: err => this.notifier.error(err.message)
+              })
           }
         }
       ]
@@ -107,13 +109,12 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
   }
 
   ngOnInit () {
-    this.serverService.getConfig()
-        .subscribe(config => {
-          // don't filter if auto-blacklist is not enabled as this will be the only list
-          if (config.autoBlacklist.videos.ofUsers.enabled) {
-            this.blocklistTypeFilter = VideoBlacklistType.MANUAL
-          }
-        })
+    const serverConfig = this.serverService.getHTMLConfig()
+
+    // Don't filter if auto-blacklist is not enabled as this will be the only list
+    if (serverConfig.autoBlacklist.videos.ofUsers.enabled) {
+      this.blocklistTypeFilter = VideoBlacklistType.MANUAL
+    }
 
     this.initialize()
   }
@@ -122,10 +123,6 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
     return 'VideoBlockListComponent'
   }
 
-  getVideoUrl (videoBlock: VideoBlacklist) {
-    return Video.buildClientUrl(videoBlock.video.uuid)
-  }
-
   toHtml (text: string) {
     return this.markdownRenderer.textMarkdownToHTML(text)
   }
@@ -136,25 +133,27 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
     const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`)
     if (res === false) return
 
-    this.videoBlocklistService.unblockVideo(entry.video.id).subscribe(
-      () => {
-        this.notifier.success($localize`Video ${entry.video.name} unblocked.`)
-        this.reloadData()
-      },
+    this.videoBlocklistService.unblockVideo(entry.video.id)
+      .subscribe({
+        next: () => {
+          this.notifier.success($localize`Video ${entry.video.name} unblocked.`)
+          this.reloadData()
+        },
 
-      err => this.notifier.error(err.message)
-    )
+        error: err => this.notifier.error(err.message)
+      })
   }
 
   getVideoEmbed (entry: VideoBlacklist) {
-    return buildVideoOrPlaylistEmbed(
-      buildVideoLink({
-        baseUrl: `${environment.originServerUrl}/videos/embed/${entry.video.uuid}`,
+    return buildVideoOrPlaylistEmbed({
+      embedUrl: decorateVideoLink({
+        url: buildVideoEmbedLink(entry.video, environment.originServerUrl),
+
         title: false,
         warningTitle: false
       }),
-      entry.video.name
-    )
+      embedTitle: entry.video.name
+    })
   }
 
   protected reloadData () {
@@ -163,21 +162,20 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
       sort: this.sort,
       search: this.search
     })
-      .subscribe(
-        async resultList => {
+      .subscribe({
+        next: async resultList => {
           this.totalRecords = resultList.total
 
           this.blocklist = resultList.data
 
           for (const element of this.blocklist) {
             Object.assign(element, {
-              reasonHtml: await this.toHtml(element.reason),
-              embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element))
+              reasonHtml: await this.toHtml(element.reason)
             })
           }
         },
 
-        err => this.notifier.error(err.message)
-      )
+        error: err => this.notifier.error(err.message)
+      })
   }
 }