]>
Commit | Line | Data |
---|---|---|
36004aa7 | 1 | import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core' |
bb152476 | 2 | import { Account } from '@app/shared/account/account.model' |
f8b2c1b4 | 3 | import { Notifier } from '@app/core' |
f77eb73b | 4 | import { SortMeta } from 'primeng/api' |
efc9e845 | 5 | import { VideoAbuse, VideoAbuseState } from '../../../../../../shared' |
5baee5fc | 6 | import { RestPagination, RestTable, VideoAbuseService, VideoBlockService } from '../../../shared' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
614d1ae9 C |
8 | import { DropdownAction } from '../../../shared/buttons/action-dropdown.component' |
9 | import { ConfirmService } from '../../../core/index' | |
efc9e845 | 10 | import { ModerationCommentModalComponent } from './moderation-comment-modal.component' |
614d1ae9 | 11 | import { Video } from '../../../shared/video/video.model' |
1506307f | 12 | import { MarkdownService } from '@app/shared/renderer' |
d6af8146 RK |
13 | import { Actor } from '@app/shared/actor/actor.model' |
14 | import { buildVideoLink, buildVideoEmbed } from 'src/assets/player/utils' | |
15 | import { getAbsoluteAPIUrl } from '@app/shared/misc/utils' | |
16 | import { DomSanitizer } from '@angular/platform-browser' | |
bb152476 | 17 | import { BlocklistService } from '@app/shared/blocklist' |
9b4241e3 | 18 | import { VideoService } from '@app/shared/video/video.service' |
25a42e29 | 19 | import { ActivatedRoute, Params, Router } from '@angular/router' |
36004aa7 | 20 | import { filter } from 'rxjs/operators' |
19a3b914 | 21 | |
25a42e29 RK |
22 | export type ProcessedVideoAbuse = VideoAbuse & { |
23 | moderationCommentHtml?: string, | |
24 | reasonHtml?: string | |
25 | embedHtml?: string | |
26 | updatedAt?: Date | |
27 | // override bare server-side definitions with rich client-side definitions | |
28 | reporterAccount: Account | |
29 | video: VideoAbuse['video'] & { | |
30 | channel: VideoAbuse['video']['channel'] & { | |
31 | ownerAccount: Account | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
11ac88de | 36 | @Component({ |
df98563e | 37 | selector: 'my-video-abuse-list', |
f595d394 | 38 | templateUrl: './video-abuse-list.component.html', |
86521a67 | 39 | styleUrls: [ '../moderation.component.scss', './video-abuse-list.component.scss' ] |
11ac88de | 40 | }) |
36004aa7 | 41 | export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit { |
f36da21e | 42 | @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent |
efc9e845 | 43 | |
25a42e29 | 44 | videoAbuses: ProcessedVideoAbuse[] = [] |
d592e0a9 | 45 | totalRecords = 0 |
ab998f7b | 46 | sort: SortMeta = { field: 'createdAt', order: 1 } |
d592e0a9 | 47 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
11ac88de | 48 | |
bb152476 | 49 | videoAbuseActions: DropdownAction<VideoAbuse>[][] = [] |
efc9e845 | 50 | |
df98563e | 51 | constructor ( |
f8b2c1b4 | 52 | private notifier: Notifier, |
b1d40cff | 53 | private videoAbuseService: VideoAbuseService, |
bb152476 | 54 | private blocklistService: BlocklistService, |
9b4241e3 | 55 | private videoService: VideoService, |
5baee5fc | 56 | private videoBlocklistService: VideoBlockService, |
efc9e845 | 57 | private confirmService: ConfirmService, |
1506307f | 58 | private i18n: I18n, |
d6af8146 | 59 | private markdownRenderer: MarkdownService, |
844db39e | 60 | private sanitizer: DomSanitizer, |
25a42e29 RK |
61 | private route: ActivatedRoute, |
62 | private router: Router | |
28798b5d | 63 | ) { |
d592e0a9 | 64 | super() |
efc9e845 C |
65 | |
66 | this.videoAbuseActions = [ | |
bb152476 RK |
67 | [ |
68 | { | |
69 | label: this.i18n('Internal actions'), | |
70 | isHeader: true | |
71 | }, | |
72 | { | |
73 | label: this.i18n('Delete report'), | |
74 | handler: videoAbuse => this.removeVideoAbuse(videoAbuse) | |
75 | }, | |
76 | { | |
77 | label: this.i18n('Add note'), | |
78 | handler: videoAbuse => this.openModerationCommentModal(videoAbuse), | |
79 | isDisplayed: videoAbuse => !videoAbuse.moderationComment | |
80 | }, | |
81 | { | |
82 | label: this.i18n('Update note'), | |
83 | handler: videoAbuse => this.openModerationCommentModal(videoAbuse), | |
84 | isDisplayed: videoAbuse => !!videoAbuse.moderationComment | |
85 | }, | |
86 | { | |
87 | label: this.i18n('Mark as accepted'), | |
88 | handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED), | |
89 | isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse) | |
90 | }, | |
91 | { | |
92 | label: this.i18n('Mark as rejected'), | |
93 | handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED), | |
94 | isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse) | |
95 | } | |
96 | ], | |
97 | [ | |
98 | { | |
99 | label: this.i18n('Actions for the video'), | |
9b4241e3 RK |
100 | isHeader: true, |
101 | isDisplayed: videoAbuse => !videoAbuse.video.deleted | |
bb152476 RK |
102 | }, |
103 | { | |
5baee5fc | 104 | label: this.i18n('Block video'), |
86521a67 | 105 | isDisplayed: videoAbuse => !videoAbuse.video.deleted && !videoAbuse.video.blacklisted, |
bb152476 | 106 | handler: videoAbuse => { |
5baee5fc | 107 | this.videoBlocklistService.blockVideo(videoAbuse.video.id, undefined, true) |
bb152476 RK |
108 | .subscribe( |
109 | () => { | |
5baee5fc | 110 | this.notifier.success(this.i18n('Video blocklisted.')) |
bb152476 RK |
111 | |
112 | this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) | |
113 | }, | |
114 | ||
9b4241e3 RK |
115 | err => this.notifier.error(err.message) |
116 | ) | |
117 | } | |
118 | }, | |
86521a67 | 119 | { |
5baee5fc | 120 | label: this.i18n('Unblock video'), |
86521a67 RK |
121 | isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted, |
122 | handler: videoAbuse => { | |
5baee5fc | 123 | this.videoBlocklistService.unblockVideo(videoAbuse.video.id) |
86521a67 RK |
124 | .subscribe( |
125 | () => { | |
5baee5fc | 126 | this.notifier.success(this.i18n('Video unblocklisted.')) |
86521a67 RK |
127 | |
128 | this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) | |
129 | }, | |
130 | ||
131 | err => this.notifier.error(err.message) | |
132 | ) | |
133 | } | |
134 | }, | |
9b4241e3 RK |
135 | { |
136 | label: this.i18n('Delete video'), | |
137 | isDisplayed: videoAbuse => !videoAbuse.video.deleted, | |
138 | handler: async videoAbuse => { | |
86521a67 RK |
139 | const res = await this.confirmService.confirm( |
140 | this.i18n('Do you really want to delete this video?'), | |
141 | this.i18n('Delete') | |
142 | ) | |
9b4241e3 RK |
143 | if (res === false) return |
144 | ||
145 | this.videoService.removeVideo(videoAbuse.video.id) | |
146 | .subscribe( | |
147 | () => { | |
148 | this.notifier.success(this.i18n('Video deleted.')) | |
149 | ||
150 | this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) | |
151 | }, | |
152 | ||
153 | err => this.notifier.error(err.message) | |
154 | ) | |
155 | } | |
156 | } | |
157 | ], | |
158 | [ | |
159 | { | |
160 | label: this.i18n('Actions for the reporter'), | |
161 | isHeader: true | |
162 | }, | |
163 | { | |
86521a67 | 164 | label: this.i18n('Mute reporter'), |
9b4241e3 RK |
165 | handler: async videoAbuse => { |
166 | const account = videoAbuse.reporterAccount as Account | |
167 | ||
168 | this.blocklistService.blockAccountByInstance(account) | |
169 | .subscribe( | |
170 | () => { | |
86521a67 RK |
171 | this.notifier.success( |
172 | this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }) | |
173 | ) | |
9b4241e3 RK |
174 | |
175 | account.mutedByInstance = true | |
176 | }, | |
177 | ||
86521a67 RK |
178 | err => this.notifier.error(err.message) |
179 | ) | |
180 | } | |
181 | }, | |
182 | { | |
183 | label: this.i18n('Mute server'), | |
184 | isDisplayed: videoAbuse => !videoAbuse.reporterAccount.userId, | |
185 | handler: async videoAbuse => { | |
186 | this.blocklistService.blockServerByInstance(videoAbuse.reporterAccount.host) | |
187 | .subscribe( | |
188 | () => { | |
189 | this.notifier.success( | |
190 | this.i18n('Server {{host}} muted by the instance.', { host: videoAbuse.reporterAccount.host }) | |
191 | ) | |
192 | }, | |
193 | ||
bb152476 RK |
194 | err => this.notifier.error(err.message) |
195 | ) | |
196 | } | |
197 | } | |
198 | ] | |
efc9e845 | 199 | ] |
d592e0a9 C |
200 | } |
201 | ||
202 | ngOnInit () { | |
24b9417c | 203 | this.initialize() |
844db39e RK |
204 | |
205 | this.route.queryParams | |
36004aa7 RK |
206 | .pipe(filter(params => params.search !== undefined && params.search !== null)) |
207 | .subscribe(params => { | |
208 | this.search = params.search | |
209 | this.setTableFilter(params.search) | |
210 | this.loadData() | |
211 | }) | |
212 | } | |
213 | ||
214 | ngAfterViewInit () { | |
0251197e | 215 | if (this.search) this.setTableFilter(this.search) |
df98563e | 216 | } |
11ac88de | 217 | |
8e11a1b3 C |
218 | getIdentifier () { |
219 | return 'VideoAbuseListComponent' | |
220 | } | |
221 | ||
efc9e845 C |
222 | openModerationCommentModal (videoAbuse: VideoAbuse) { |
223 | this.moderationCommentModal.openModal(videoAbuse) | |
224 | } | |
225 | ||
226 | onModerationCommentUpdated () { | |
227 | this.loadData() | |
228 | } | |
229 | ||
25a42e29 RK |
230 | /* Table filter functions */ |
231 | onAbuseSearch (event: Event) { | |
232 | this.onSearch(event) | |
233 | this.setQueryParams((event.target as HTMLInputElement).value) | |
234 | } | |
235 | ||
236 | setQueryParams (search: string) { | |
237 | const queryParams: Params = {} | |
238 | if (search) Object.assign(queryParams, { search }) | |
239 | this.router.navigate([ '/admin/moderation/video-abuses/list' ], { queryParams }) | |
d592e0a9 C |
240 | } |
241 | ||
25a42e29 RK |
242 | resetTableFilter () { |
243 | this.setTableFilter('') | |
244 | this.setQueryParams('') | |
245 | this.resetSearch() | |
36004aa7 | 246 | } |
25a42e29 | 247 | /* END Table filter functions */ |
36004aa7 | 248 | |
efc9e845 C |
249 | isVideoAbuseAccepted (videoAbuse: VideoAbuse) { |
250 | return videoAbuse.state.id === VideoAbuseState.ACCEPTED | |
251 | } | |
252 | ||
253 | isVideoAbuseRejected (videoAbuse: VideoAbuse) { | |
254 | return videoAbuse.state.id === VideoAbuseState.REJECTED | |
255 | } | |
256 | ||
191764f3 C |
257 | getVideoUrl (videoAbuse: VideoAbuse) { |
258 | return Video.buildClientUrl(videoAbuse.video.uuid) | |
259 | } | |
260 | ||
d6af8146 | 261 | getVideoEmbed (videoAbuse: VideoAbuse) { |
042daa70 | 262 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
d6af8146 RK |
263 | const embedUrl = buildVideoLink({ |
264 | baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid, | |
265 | warningTitle: false | |
266 | }) | |
267 | return buildVideoEmbed(embedUrl) | |
268 | } | |
269 | ||
270 | switchToDefaultAvatar ($event: Event) { | |
271 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | |
272 | } | |
273 | ||
efc9e845 | 274 | async removeVideoAbuse (videoAbuse: VideoAbuse) { |
198d764f | 275 | const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete')) |
efc9e845 C |
276 | if (res === false) return |
277 | ||
278 | this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe( | |
279 | () => { | |
f8b2c1b4 | 280 | this.notifier.success(this.i18n('Abuse deleted.')) |
efc9e845 C |
281 | this.loadData() |
282 | }, | |
283 | ||
f8b2c1b4 | 284 | err => this.notifier.error(err.message) |
efc9e845 C |
285 | ) |
286 | } | |
287 | ||
288 | updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) { | |
289 | this.videoAbuseService.updateVideoAbuse(videoAbuse, { state }) | |
290 | .subscribe( | |
291 | () => this.loadData(), | |
292 | ||
f8b2c1b4 | 293 | err => this.notifier.error(err.message) |
efc9e845 | 294 | ) |
efc9e845 C |
295 | } |
296 | ||
d592e0a9 | 297 | protected loadData () { |
844db39e RK |
298 | return this.videoAbuseService.getVideoAbuses({ |
299 | pagination: this.pagination, | |
042daa70 | 300 | sort: this.sort, |
844db39e RK |
301 | search: this.search |
302 | }).subscribe( | |
303 | async resultList => { | |
304 | this.totalRecords = resultList.total | |
8d419763 | 305 | const videoAbuses = [] |
844db39e | 306 | |
25a42e29 | 307 | for (const abuse of resultList.data) { |
844db39e RK |
308 | Object.assign(abuse, { |
309 | reasonHtml: await this.toHtml(abuse.reason), | |
310 | moderationCommentHtml: await this.toHtml(abuse.moderationComment), | |
311 | embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)), | |
312 | reporterAccount: new Account(abuse.reporterAccount) | |
313 | }) | |
25a42e29 RK |
314 | |
315 | if (abuse.video.channel?.ownerAccount) abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount) | |
0db536f1 | 316 | if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt |
25a42e29 | 317 | |
8d419763 | 318 | videoAbuses.push(abuse as ProcessedVideoAbuse) |
844db39e RK |
319 | } |
320 | ||
8d419763 | 321 | this.videoAbuses = videoAbuses |
844db39e RK |
322 | }, |
323 | ||
324 | err => this.notifier.error(err.message) | |
325 | ) | |
11ac88de | 326 | } |
41d71344 C |
327 | |
328 | private toHtml (text: string) { | |
329 | return this.markdownRenderer.textMarkdownToHTML(text) | |
330 | } | |
11ac88de | 331 | } |