1 import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core'
2 import { Account } from '@app/shared/account/account.model'
3 import { Notifier } from '@app/core'
4 import { SortMeta } from 'primeng/api'
5 import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
6 import { RestPagination, RestTable, VideoAbuseService, VideoBlockService } from '../../../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9 import { ConfirmService } from '../../../core/index'
10 import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
11 import { Video } from '../../../shared/video/video.model'
12 import { MarkdownService } from '@app/shared/renderer'
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'
17 import { BlocklistService } from '@app/shared/blocklist'
18 import { VideoService } from '@app/shared/video/video.service'
19 import { ActivatedRoute, Params, Router } from '@angular/router'
20 import { filter } from 'rxjs/operators'
22 export type ProcessedVideoAbuse = VideoAbuse & {
23 moderationCommentHtml?: string,
27 // override bare server-side definitions with rich client-side definitions
28 reporterAccount: Account
29 video: VideoAbuse['video'] & {
30 channel: VideoAbuse['video']['channel'] & {
37 selector: 'my-video-abuse-list',
38 templateUrl: './video-abuse-list.component.html',
39 styleUrls: [ '../moderation.component.scss', './video-abuse-list.component.scss' ]
41 export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit {
42 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
44 videoAbuses: ProcessedVideoAbuse[] = []
46 sort: SortMeta = { field: 'createdAt', order: 1 }
47 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
49 videoAbuseActions: DropdownAction<VideoAbuse>[][] = []
52 private notifier: Notifier,
53 private videoAbuseService: VideoAbuseService,
54 private blocklistService: BlocklistService,
55 private videoService: VideoService,
56 private videoBlocklistService: VideoBlockService,
57 private confirmService: ConfirmService,
59 private markdownRenderer: MarkdownService,
60 private sanitizer: DomSanitizer,
61 private route: ActivatedRoute,
62 private router: Router
66 this.videoAbuseActions = [
69 label: this.i18n('Internal actions'),
73 label: this.i18n('Delete report'),
74 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
77 label: this.i18n('Add note'),
78 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
79 isDisplayed: videoAbuse => !videoAbuse.moderationComment
82 label: this.i18n('Update note'),
83 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
84 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
87 label: this.i18n('Mark as accepted'),
88 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
89 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
92 label: this.i18n('Mark as rejected'),
93 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
94 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
99 label: this.i18n('Actions for the video'),
101 isDisplayed: videoAbuse => !videoAbuse.video.deleted
104 label: this.i18n('Block video'),
105 isDisplayed: videoAbuse => !videoAbuse.video.deleted && !videoAbuse.video.blacklisted,
106 handler: videoAbuse => {
107 this.videoBlocklistService.blockVideo(videoAbuse.video.id, undefined, true)
110 this.notifier.success(this.i18n('Video blocklisted.'))
112 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
115 err => this.notifier.error(err.message)
120 label: this.i18n('Unblock video'),
121 isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted,
122 handler: videoAbuse => {
123 this.videoBlocklistService.unblockVideo(videoAbuse.video.id)
126 this.notifier.success(this.i18n('Video unblocklisted.'))
128 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
131 err => this.notifier.error(err.message)
136 label: this.i18n('Delete video'),
137 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
138 handler: async videoAbuse => {
139 const res = await this.confirmService.confirm(
140 this.i18n('Do you really want to delete this video?'),
143 if (res === false) return
145 this.videoService.removeVideo(videoAbuse.video.id)
148 this.notifier.success(this.i18n('Video deleted.'))
150 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
153 err => this.notifier.error(err.message)
160 label: this.i18n('Actions for the reporter'),
164 label: this.i18n('Mute reporter'),
165 handler: async videoAbuse => {
166 const account = videoAbuse.reporterAccount as Account
168 this.blocklistService.blockAccountByInstance(account)
171 this.notifier.success(
172 this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })
175 account.mutedByInstance = true
178 err => this.notifier.error(err.message)
183 label: this.i18n('Mute server'),
184 isDisplayed: videoAbuse => !videoAbuse.reporterAccount.userId,
185 handler: async videoAbuse => {
186 this.blocklistService.blockServerByInstance(videoAbuse.reporterAccount.host)
189 this.notifier.success(
190 this.i18n('Server {{host}} muted by the instance.', { host: videoAbuse.reporterAccount.host })
194 err => this.notifier.error(err.message)
205 this.route.queryParams
206 .pipe(filter(params => params.search !== undefined && params.search !== null))
207 .subscribe(params => {
208 this.search = params.search
209 this.setTableFilter(params.search)
215 if (this.search) this.setTableFilter(this.search)
219 return 'VideoAbuseListComponent'
222 openModerationCommentModal (videoAbuse: VideoAbuse) {
223 this.moderationCommentModal.openModal(videoAbuse)
226 onModerationCommentUpdated () {
230 /* Table filter functions */
231 onAbuseSearch (event: Event) {
233 this.setQueryParams((event.target as HTMLInputElement).value)
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 })
242 resetTableFilter () {
243 this.setTableFilter('')
244 this.setQueryParams('')
247 /* END Table filter functions */
249 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
250 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
253 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
254 return videoAbuse.state.id === VideoAbuseState.REJECTED
257 getVideoUrl (videoAbuse: VideoAbuse) {
258 return Video.buildClientUrl(videoAbuse.video.uuid)
261 getVideoEmbed (videoAbuse: VideoAbuse) {
262 const absoluteAPIUrl = getAbsoluteAPIUrl()
263 const embedUrl = buildVideoLink({
264 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
267 return buildVideoEmbed(embedUrl)
270 switchToDefaultAvatar ($event: Event) {
271 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
274 async removeVideoAbuse (videoAbuse: VideoAbuse) {
275 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
276 if (res === false) return
278 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
280 this.notifier.success(this.i18n('Abuse deleted.'))
284 err => this.notifier.error(err.message)
288 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
289 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
291 () => this.loadData(),
293 err => this.notifier.error(err.message)
297 protected loadData () {
298 return this.videoAbuseService.getVideoAbuses({
299 pagination: this.pagination,
303 async resultList => {
304 this.totalRecords = resultList.total
305 const videoAbuses = []
307 for (const abuse of resultList.data) {
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)
315 if (abuse.video.channel?.ownerAccount) abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount)
316 if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt
318 videoAbuses.push(abuse as ProcessedVideoAbuse)
321 this.videoAbuses = videoAbuses
324 err => this.notifier.error(err.message)
328 private toHtml (text: string) {
329 return this.markdownRenderer.textMarkdownToHTML(text)