]>
Commit | Line | Data |
---|---|---|
94148c90 C |
1 | import * as debug from 'debug' |
2 | import truncate from 'lodash-es/truncate' | |
3 | import { SortMeta } from 'primeng/api' | |
2e46eb97 | 4 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
94148c90 | 5 | import { DomSanitizer } from '@angular/platform-browser' |
5ed46c1b | 6 | import { ActivatedRoute, Router } from '@angular/router' |
94148c90 C |
7 | import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core' |
8 | import { Account, Actor, DropdownAction, Video, VideoService } from '@app/shared/shared-main' | |
9 | import { AbuseService, BlocklistService, VideoBlockService } from '@app/shared/shared-moderation' | |
10 | import { VideoCommentService } from '@app/shared/shared-video-comment' | |
94148c90 | 11 | import { AbuseState, AdminAbuse } from '@shared/models' |
2e46eb97 | 12 | import { AdvancedInputFilter } from '../shared-forms' |
94148c90 C |
13 | import { AbuseMessageModalComponent } from './abuse-message-modal.component' |
14 | import { ModerationCommentModalComponent } from './moderation-comment-modal.component' | |
15 | import { ProcessedAbuse } from './processed-abuse.model' | |
16 | ||
17 | const logger = debug('peertube:moderation:AbuseListTableComponent') | |
18 | ||
19 | @Component({ | |
20 | selector: 'my-abuse-list-table', | |
21 | templateUrl: './abuse-list-table.component.html', | |
22 | styleUrls: [ '../shared-moderation/moderation.scss', './abuse-list-table.component.scss' ] | |
23 | }) | |
2e46eb97 | 24 | export class AbuseListTableComponent extends RestTable implements OnInit { |
94148c90 | 25 | @Input() viewType: 'admin' | 'user' |
94148c90 C |
26 | |
27 | @ViewChild('abuseMessagesModal', { static: true }) abuseMessagesModal: AbuseMessageModalComponent | |
28 | @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent | |
29 | ||
30 | abuses: ProcessedAbuse[] = [] | |
31 | totalRecords = 0 | |
32 | sort: SortMeta = { field: 'createdAt', order: 1 } | |
33 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
34 | ||
35 | abuseActions: DropdownAction<ProcessedAbuse>[][] = [] | |
36 | ||
1fd61899 C |
37 | inputFilters: AdvancedInputFilter[] = [ |
38 | { | |
978c87e7 C |
39 | title: $localize`Advanced filters`, |
40 | children: [ | |
41 | { | |
dd6d2a7c | 42 | value: 'state:pending', |
978c87e7 C |
43 | label: $localize`Unsolved reports` |
44 | }, | |
45 | { | |
dd6d2a7c | 46 | value: 'state:accepted', |
978c87e7 C |
47 | label: $localize`Accepted reports` |
48 | }, | |
49 | { | |
dd6d2a7c | 50 | value: 'state:rejected', |
978c87e7 C |
51 | label: $localize`Refused reports` |
52 | }, | |
53 | { | |
dd6d2a7c | 54 | value: 'videoIs:blacklisted', |
978c87e7 C |
55 | label: $localize`Reports with blocked videos` |
56 | }, | |
57 | { | |
dd6d2a7c | 58 | value: 'videoIs:deleted', |
978c87e7 C |
59 | label: $localize`Reports with deleted videos` |
60 | } | |
61 | ] | |
1fd61899 C |
62 | } |
63 | ] | |
64 | ||
94148c90 | 65 | constructor ( |
5ed46c1b C |
66 | protected route: ActivatedRoute, |
67 | protected router: Router, | |
94148c90 C |
68 | private notifier: Notifier, |
69 | private abuseService: AbuseService, | |
70 | private blocklistService: BlocklistService, | |
71 | private commentService: VideoCommentService, | |
72 | private videoService: VideoService, | |
73 | private videoBlocklistService: VideoBlockService, | |
74 | private confirmService: ConfirmService, | |
94148c90 | 75 | private markdownRenderer: MarkdownService, |
5ed46c1b | 76 | private sanitizer: DomSanitizer |
94148c90 C |
77 | ) { |
78 | super() | |
79 | } | |
80 | ||
81 | ngOnInit () { | |
82 | this.abuseActions = [ | |
83 | this.buildInternalActions(), | |
84 | ||
85 | this.buildFlaggedAccountActions(), | |
86 | ||
87 | this.buildCommentActions(), | |
88 | ||
89 | this.buildVideoActions(), | |
90 | ||
91 | this.buildAccountActions() | |
92 | ] | |
93 | ||
94 | this.initialize() | |
94148c90 C |
95 | } |
96 | ||
97 | isAdminView () { | |
98 | return this.viewType === 'admin' | |
99 | } | |
100 | ||
101 | getIdentifier () { | |
102 | return 'AbuseListTableComponent' | |
103 | } | |
104 | ||
105 | openModerationCommentModal (abuse: AdminAbuse) { | |
106 | this.moderationCommentModal.openModal(abuse) | |
107 | } | |
108 | ||
109 | onModerationCommentUpdated () { | |
2e46eb97 | 110 | this.reloadData() |
94148c90 C |
111 | } |
112 | ||
94148c90 C |
113 | isAbuseAccepted (abuse: AdminAbuse) { |
114 | return abuse.state.id === AbuseState.ACCEPTED | |
115 | } | |
116 | ||
117 | isAbuseRejected (abuse: AdminAbuse) { | |
118 | return abuse.state.id === AbuseState.REJECTED | |
119 | } | |
120 | ||
121 | getVideoUrl (abuse: AdminAbuse) { | |
d4a8e7a6 | 122 | return Video.buildWatchUrl(abuse.video) |
94148c90 C |
123 | } |
124 | ||
125 | getCommentUrl (abuse: AdminAbuse) { | |
d4a8e7a6 | 126 | return Video.buildWatchUrl(abuse.comment.video) + ';threadId=' + abuse.comment.threadId |
94148c90 C |
127 | } |
128 | ||
129 | getAccountUrl (abuse: ProcessedAbuse) { | |
71887396 | 130 | return '/a/' + abuse.flaggedAccount.nameWithHost |
94148c90 C |
131 | } |
132 | ||
94148c90 | 133 | async removeAbuse (abuse: AdminAbuse) { |
66357162 | 134 | const res = await this.confirmService.confirm($localize`Do you really want to delete this abuse report?`, $localize`Delete`) |
94148c90 C |
135 | if (res === false) return |
136 | ||
1378c0d3 C |
137 | this.abuseService.removeAbuse(abuse) |
138 | .subscribe({ | |
139 | next: () => { | |
140 | this.notifier.success($localize`Abuse deleted.`) | |
141 | this.reloadData() | |
142 | }, | |
94148c90 | 143 | |
1378c0d3 C |
144 | error: err => this.notifier.error(err.message) |
145 | }) | |
94148c90 C |
146 | } |
147 | ||
148 | updateAbuseState (abuse: AdminAbuse, state: AbuseState) { | |
149 | this.abuseService.updateAbuse(abuse, { state }) | |
1378c0d3 C |
150 | .subscribe({ |
151 | next: () => this.reloadData(), | |
94148c90 | 152 | |
1378c0d3 C |
153 | error: err => this.notifier.error(err.message) |
154 | }) | |
94148c90 C |
155 | } |
156 | ||
157 | onCountMessagesUpdated (event: { abuseId: number, countMessages: number }) { | |
158 | const abuse = this.abuses.find(a => a.id === event.abuseId) | |
159 | ||
160 | if (!abuse) { | |
161 | console.error('Cannot find abuse %d.', event.abuseId) | |
162 | return | |
163 | } | |
164 | ||
165 | abuse.countMessages = event.countMessages | |
166 | } | |
167 | ||
168 | openAbuseMessagesModal (abuse: AdminAbuse) { | |
169 | this.abuseMessagesModal.openModal(abuse) | |
170 | } | |
171 | ||
172 | isLocalAbuse (abuse: AdminAbuse) { | |
173 | if (this.viewType === 'user') return true | |
174 | ||
175 | return Actor.IS_LOCAL(abuse.reporterAccount.host) | |
176 | } | |
177 | ||
2e46eb97 | 178 | protected reloadData () { |
94148c90 C |
179 | logger('Loading data.') |
180 | ||
181 | const options = { | |
182 | pagination: this.pagination, | |
183 | sort: this.sort, | |
184 | search: this.search | |
185 | } | |
186 | ||
187 | const observable = this.viewType === 'admin' | |
188 | ? this.abuseService.getAdminAbuses(options) | |
189 | : this.abuseService.getUserAbuses(options) | |
190 | ||
1378c0d3 C |
191 | return observable.subscribe({ |
192 | next: async resultList => { | |
193 | this.totalRecords = resultList.total | |
94148c90 | 194 | |
1378c0d3 | 195 | this.abuses = [] |
94148c90 | 196 | |
1378c0d3 C |
197 | for (const a of resultList.data) { |
198 | const abuse = a as ProcessedAbuse | |
94148c90 | 199 | |
1378c0d3 | 200 | abuse.reasonHtml = await this.toHtml(abuse.reason) |
94148c90 | 201 | |
1378c0d3 C |
202 | if (abuse.moderationComment) { |
203 | abuse.moderationCommentHtml = await this.toHtml(abuse.moderationComment) | |
204 | } | |
94148c90 | 205 | |
1378c0d3 | 206 | if (abuse.video) { |
1378c0d3 C |
207 | if (abuse.video.channel?.ownerAccount) { |
208 | abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount) | |
94148c90 | 209 | } |
1378c0d3 | 210 | } |
94148c90 | 211 | |
1378c0d3 C |
212 | if (abuse.comment) { |
213 | if (abuse.comment.deleted) { | |
214 | abuse.truncatedCommentHtml = abuse.commentHtml = $localize`Deleted comment` | |
215 | } else { | |
216 | const truncated = truncate(abuse.comment.text, { length: 100 }) | |
217 | abuse.truncatedCommentHtml = await this.markdownRenderer.textMarkdownToHTML(truncated, true) | |
218 | abuse.commentHtml = await this.markdownRenderer.textMarkdownToHTML(abuse.comment.text, true) | |
94148c90 | 219 | } |
1378c0d3 | 220 | } |
94148c90 | 221 | |
1378c0d3 C |
222 | if (abuse.reporterAccount) { |
223 | abuse.reporterAccount = new Account(abuse.reporterAccount) | |
224 | } | |
94148c90 | 225 | |
1378c0d3 C |
226 | if (abuse.flaggedAccount) { |
227 | abuse.flaggedAccount = new Account(abuse.flaggedAccount) | |
228 | } | |
94148c90 | 229 | |
1378c0d3 | 230 | if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt |
94148c90 | 231 | |
1378c0d3 C |
232 | this.abuses.push(abuse) |
233 | } | |
234 | }, | |
94148c90 | 235 | |
1378c0d3 C |
236 | error: err => this.notifier.error(err.message) |
237 | }) | |
94148c90 C |
238 | } |
239 | ||
240 | private buildInternalActions (): DropdownAction<ProcessedAbuse>[] { | |
241 | return [ | |
242 | { | |
66357162 | 243 | label: $localize`Internal actions`, |
94148c90 C |
244 | isHeader: true |
245 | }, | |
246 | { | |
247 | label: this.isAdminView() | |
66357162 C |
248 | ? $localize`Messages with reporter` |
249 | : $localize`Messages with moderators`, | |
94148c90 C |
250 | handler: abuse => this.openAbuseMessagesModal(abuse), |
251 | isDisplayed: abuse => this.isLocalAbuse(abuse) | |
252 | }, | |
253 | { | |
66357162 | 254 | label: $localize`Update internal note`, |
94148c90 C |
255 | handler: abuse => this.openModerationCommentModal(abuse), |
256 | isDisplayed: abuse => this.isAdminView() && !!abuse.moderationComment | |
257 | }, | |
258 | { | |
66357162 | 259 | label: $localize`Mark as accepted`, |
94148c90 C |
260 | handler: abuse => this.updateAbuseState(abuse, AbuseState.ACCEPTED), |
261 | isDisplayed: abuse => this.isAdminView() && !this.isAbuseAccepted(abuse) | |
262 | }, | |
263 | { | |
66357162 | 264 | label: $localize`Mark as rejected`, |
94148c90 C |
265 | handler: abuse => this.updateAbuseState(abuse, AbuseState.REJECTED), |
266 | isDisplayed: abuse => this.isAdminView() && !this.isAbuseRejected(abuse) | |
267 | }, | |
268 | { | |
66357162 | 269 | label: $localize`Add internal note`, |
94148c90 C |
270 | handler: abuse => this.openModerationCommentModal(abuse), |
271 | isDisplayed: abuse => this.isAdminView() && !abuse.moderationComment | |
272 | }, | |
273 | { | |
66357162 | 274 | label: $localize`Delete report`, |
94148c90 C |
275 | handler: abuse => this.isAdminView() && this.removeAbuse(abuse) |
276 | } | |
277 | ] | |
278 | } | |
279 | ||
280 | private buildFlaggedAccountActions (): DropdownAction<ProcessedAbuse>[] { | |
281 | if (!this.isAdminView()) return [] | |
282 | ||
283 | return [ | |
284 | { | |
66357162 | 285 | label: $localize`Actions for the flagged account`, |
94148c90 C |
286 | isHeader: true, |
287 | isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video | |
288 | }, | |
289 | ||
290 | { | |
66357162 | 291 | label: $localize`Mute account`, |
94148c90 C |
292 | isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video, |
293 | handler: abuse => this.muteAccountHelper(abuse.flaggedAccount) | |
294 | }, | |
295 | ||
296 | { | |
66357162 | 297 | label: $localize`Mute server account`, |
94148c90 C |
298 | isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video, |
299 | handler: abuse => this.muteServerHelper(abuse.flaggedAccount.host) | |
300 | } | |
301 | ] | |
302 | } | |
303 | ||
304 | private buildAccountActions (): DropdownAction<ProcessedAbuse>[] { | |
305 | if (!this.isAdminView()) return [] | |
306 | ||
307 | return [ | |
308 | { | |
66357162 | 309 | label: $localize`Actions for the reporter`, |
94148c90 C |
310 | isHeader: true, |
311 | isDisplayed: abuse => !!abuse.reporterAccount | |
312 | }, | |
313 | ||
314 | { | |
66357162 | 315 | label: $localize`Mute reporter`, |
94148c90 C |
316 | isDisplayed: abuse => !!abuse.reporterAccount, |
317 | handler: abuse => this.muteAccountHelper(abuse.reporterAccount) | |
318 | }, | |
319 | ||
320 | { | |
66357162 | 321 | label: $localize`Mute server`, |
94148c90 C |
322 | isDisplayed: abuse => abuse.reporterAccount && !abuse.reporterAccount.userId, |
323 | handler: abuse => this.muteServerHelper(abuse.reporterAccount.host) | |
324 | } | |
325 | ] | |
326 | } | |
327 | ||
328 | private buildVideoActions (): DropdownAction<ProcessedAbuse>[] { | |
329 | if (!this.isAdminView()) return [] | |
330 | ||
331 | return [ | |
332 | { | |
66357162 | 333 | label: $localize`Actions for the video`, |
94148c90 C |
334 | isHeader: true, |
335 | isDisplayed: abuse => abuse.video && !abuse.video.deleted | |
336 | }, | |
337 | { | |
66357162 | 338 | label: $localize`Block video`, |
94148c90 C |
339 | isDisplayed: abuse => abuse.video && !abuse.video.deleted && !abuse.video.blacklisted, |
340 | handler: abuse => { | |
3cfa8176 | 341 | this.videoBlocklistService.blockVideo([ { videoId: abuse.video.id, unfederate: abuse.video.channel.isLocal } ]) |
1378c0d3 C |
342 | .subscribe({ |
343 | next: () => { | |
66357162 | 344 | this.notifier.success($localize`Video blocked.`) |
94148c90 C |
345 | |
346 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) | |
347 | }, | |
348 | ||
1378c0d3 C |
349 | error: err => this.notifier.error(err.message) |
350 | }) | |
94148c90 C |
351 | } |
352 | }, | |
353 | { | |
66357162 | 354 | label: $localize`Unblock video`, |
94148c90 C |
355 | isDisplayed: abuse => abuse.video && !abuse.video.deleted && abuse.video.blacklisted, |
356 | handler: abuse => { | |
357 | this.videoBlocklistService.unblockVideo(abuse.video.id) | |
1378c0d3 C |
358 | .subscribe({ |
359 | next: () => { | |
66357162 | 360 | this.notifier.success($localize`Video unblocked.`) |
94148c90 C |
361 | |
362 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) | |
363 | }, | |
364 | ||
1378c0d3 C |
365 | error: err => this.notifier.error(err.message) |
366 | }) | |
94148c90 C |
367 | } |
368 | }, | |
369 | { | |
66357162 | 370 | label: $localize`Delete video`, |
94148c90 C |
371 | isDisplayed: abuse => abuse.video && !abuse.video.deleted, |
372 | handler: async abuse => { | |
373 | const res = await this.confirmService.confirm( | |
66357162 C |
374 | $localize`Do you really want to delete this video?`, |
375 | $localize`Delete` | |
94148c90 C |
376 | ) |
377 | if (res === false) return | |
378 | ||
379 | this.videoService.removeVideo(abuse.video.id) | |
1378c0d3 C |
380 | .subscribe({ |
381 | next: () => { | |
66357162 | 382 | this.notifier.success($localize`Video deleted.`) |
94148c90 C |
383 | |
384 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) | |
385 | }, | |
386 | ||
1378c0d3 C |
387 | error: err => this.notifier.error(err.message) |
388 | }) | |
94148c90 C |
389 | } |
390 | } | |
391 | ] | |
392 | } | |
393 | ||
394 | private buildCommentActions (): DropdownAction<ProcessedAbuse>[] { | |
395 | if (!this.isAdminView()) return [] | |
396 | ||
397 | return [ | |
398 | { | |
66357162 | 399 | label: $localize`Actions for the comment`, |
94148c90 C |
400 | isHeader: true, |
401 | isDisplayed: abuse => abuse.comment && !abuse.comment.deleted | |
402 | }, | |
403 | ||
404 | { | |
66357162 | 405 | label: $localize`Delete comment`, |
94148c90 C |
406 | isDisplayed: abuse => abuse.comment && !abuse.comment.deleted, |
407 | handler: async abuse => { | |
408 | const res = await this.confirmService.confirm( | |
66357162 C |
409 | $localize`Do you really want to delete this comment?`, |
410 | $localize`Delete` | |
94148c90 C |
411 | ) |
412 | if (res === false) return | |
413 | ||
414 | this.commentService.deleteVideoComment(abuse.comment.video.id, abuse.comment.id) | |
1378c0d3 C |
415 | .subscribe({ |
416 | next: () => { | |
66357162 | 417 | this.notifier.success($localize`Comment deleted.`) |
94148c90 C |
418 | |
419 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) | |
420 | }, | |
421 | ||
1378c0d3 C |
422 | error: err => this.notifier.error(err.message) |
423 | }) | |
94148c90 C |
424 | } |
425 | } | |
426 | ] | |
427 | } | |
428 | ||
429 | private muteAccountHelper (account: Account) { | |
430 | this.blocklistService.blockAccountByInstance(account) | |
1378c0d3 C |
431 | .subscribe({ |
432 | next: () => { | |
66357162 | 433 | this.notifier.success($localize`Account ${account.nameWithHost} muted by the instance.`) |
94148c90 C |
434 | account.mutedByInstance = true |
435 | }, | |
436 | ||
1378c0d3 C |
437 | error: err => this.notifier.error(err.message) |
438 | }) | |
94148c90 C |
439 | } |
440 | ||
441 | private muteServerHelper (host: string) { | |
442 | this.blocklistService.blockServerByInstance(host) | |
1378c0d3 C |
443 | .subscribe({ |
444 | next: () => { | |
66357162 | 445 | this.notifier.success($localize`Server ${host} muted by the instance.`) |
94148c90 C |
446 | }, |
447 | ||
1378c0d3 C |
448 | error: err => this.notifier.error(err.message) |
449 | }) | |
94148c90 C |
450 | } |
451 | ||
452 | private toHtml (text: string) { | |
453 | return this.markdownRenderer.textMarkdownToHTML(text) | |
454 | } | |
455 | } |