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