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