]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
Add channel filters for my videos/followers
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-block-list / video-block-list.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { switchMap } from 'rxjs/operators'
3 import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils'
4 import { environment } from 'src/environments/environment'
5 import { Component, OnInit } from '@angular/core'
6 import { DomSanitizer } from '@angular/platform-browser'
7 import { ActivatedRoute, Router } from '@angular/router'
8 import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
9 import { AdvancedInputFilter } from '@app/shared/shared-forms'
10 import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
11 import { VideoBlockService } from '@app/shared/shared-moderation'
12 import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils'
13 import { VideoBlacklist, VideoBlacklistType } from '@shared/models'
14
15 @Component({
16 selector: 'my-video-block-list',
17 templateUrl: './video-block-list.component.html',
18 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ]
19 })
20 export class VideoBlockListComponent extends RestTable implements OnInit {
21 blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = []
22 totalRecords = 0
23 sort: SortMeta = { field: 'createdAt', order: -1 }
24 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
25 blocklistTypeFilter: VideoBlacklistType = undefined
26
27 videoBlocklistActions: DropdownAction<VideoBlacklist>[][] = []
28
29 inputFilters: AdvancedInputFilter[] = [
30 {
31 title: $localize`Advanced filters`,
32 children: [
33 {
34 queryParams: { search: 'type:auto' },
35 label: $localize`Automatic blocks`
36 },
37 {
38 queryParams: { search: 'type:manual' },
39 label: $localize`Manual blocks`
40 }
41 ]
42 }
43 ]
44
45 constructor (
46 protected route: ActivatedRoute,
47 protected router: Router,
48 private notifier: Notifier,
49 private serverService: ServerService,
50 private confirmService: ConfirmService,
51 private videoBlocklistService: VideoBlockService,
52 private markdownRenderer: MarkdownService,
53 private sanitizer: DomSanitizer,
54 private videoService: VideoService
55 ) {
56 super()
57
58 this.videoBlocklistActions = [
59 [
60 {
61 label: $localize`Internal actions`,
62 isHeader: true,
63 isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
64 },
65 {
66 label: $localize`Switch video block to manual`,
67 handler: videoBlock => {
68 this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
69 switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
70 ).subscribe({
71 next: () => {
72 this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`)
73 this.reloadData()
74 },
75
76 error: err => this.notifier.error(err.message)
77 })
78 },
79 isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
80 }
81 ],
82 [
83 {
84 label: $localize`Actions for the video`,
85 isHeader: true
86 },
87 {
88 label: $localize`Unblock`,
89 handler: videoBlock => this.unblockVideo(videoBlock)
90 },
91
92 {
93 label: $localize`Delete`,
94 handler: async videoBlock => {
95 const res = await this.confirmService.confirm(
96 $localize`Do you really want to delete this video?`,
97 $localize`Delete`
98 )
99 if (res === false) return
100
101 this.videoService.removeVideo(videoBlock.video.id)
102 .subscribe({
103 next: () => this.notifier.success($localize`Video deleted.`),
104
105 error: err => this.notifier.error(err.message)
106 })
107 }
108 }
109 ]
110 ]
111 }
112
113 ngOnInit () {
114 const serverConfig = this.serverService.getHTMLConfig()
115
116 // Don't filter if auto-blacklist is not enabled as this will be the only list
117 if (serverConfig.autoBlacklist.videos.ofUsers.enabled) {
118 this.blocklistTypeFilter = VideoBlacklistType.MANUAL
119 }
120
121 this.initialize()
122 }
123
124 getIdentifier () {
125 return 'VideoBlockListComponent'
126 }
127
128 getVideoUrl (videoBlock: VideoBlacklist) {
129 return Video.buildWatchUrl(videoBlock.video)
130 }
131
132 toHtml (text: string) {
133 return this.markdownRenderer.textMarkdownToHTML(text)
134 }
135
136 async unblockVideo (entry: VideoBlacklist) {
137 const confirmMessage = $localize`Do you really want to unblock this video? It will be available again in the videos list.`
138
139 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`)
140 if (res === false) return
141
142 this.videoBlocklistService.unblockVideo(entry.video.id)
143 .subscribe({
144 next: () => {
145 this.notifier.success($localize`Video ${entry.video.name} unblocked.`)
146 this.reloadData()
147 },
148
149 error: err => this.notifier.error(err.message)
150 })
151 }
152
153 getVideoEmbed (entry: VideoBlacklist) {
154 return buildVideoOrPlaylistEmbed(
155 decorateVideoLink({
156 url: buildVideoEmbedLink(entry.video, environment.originServerUrl),
157
158 title: false,
159 warningTitle: false
160 }),
161 entry.video.name
162 )
163 }
164
165 protected reloadData () {
166 this.videoBlocklistService.listBlocks({
167 pagination: this.pagination,
168 sort: this.sort,
169 search: this.search
170 })
171 .subscribe({
172 next: async resultList => {
173 this.totalRecords = resultList.total
174
175 this.blocklist = resultList.data
176
177 for (const element of this.blocklist) {
178 Object.assign(element, {
179 reasonHtml: await this.toHtml(element.reason),
180 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element))
181 })
182 }
183 },
184
185 error: err => this.notifier.error(err.message)
186 })
187 }
188 }