1 import { Component, OnInit, ViewChild } 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, VideoBlacklistService } 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'
21 selector: 'my-video-abuse-list',
22 templateUrl: './video-abuse-list.component.html',
23 styleUrls: [ '../moderation.component.scss']
25 export class VideoAbuseListComponent extends RestTable implements OnInit {
26 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
28 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
30 rowsPerPageOptions = [ 20, 50, 100 ]
31 rowsPerPage = this.rowsPerPageOptions[0]
32 sort: SortMeta = { field: 'createdAt', order: 1 }
33 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
35 videoAbuseActions: DropdownAction<VideoAbuse>[][] = []
38 private notifier: Notifier,
39 private videoAbuseService: VideoAbuseService,
40 private blocklistService: BlocklistService,
41 private videoService: VideoService,
42 private videoBlacklistService: VideoBlacklistService,
43 private confirmService: ConfirmService,
45 private markdownRenderer: MarkdownService,
46 private sanitizer: DomSanitizer
50 this.videoAbuseActions = [
53 label: this.i18n('Internal actions'),
57 label: this.i18n('Delete report'),
58 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
61 label: this.i18n('Add note'),
62 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
63 isDisplayed: videoAbuse => !videoAbuse.moderationComment
66 label: this.i18n('Update note'),
67 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
68 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
71 label: this.i18n('Mark as accepted'),
72 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
73 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
76 label: this.i18n('Mark as rejected'),
77 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
78 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
83 label: this.i18n('Actions for the video'),
85 isDisplayed: videoAbuse => !videoAbuse.video.deleted
88 label: this.i18n('Blacklist video'),
89 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
90 handler: videoAbuse => {
91 this.videoBlacklistService.blacklistVideo(videoAbuse.video.id, undefined, true)
94 this.notifier.success(this.i18n('Video blacklisted.'))
96 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
99 err => this.notifier.error(err.message)
104 label: this.i18n('Delete video'),
105 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
106 handler: async videoAbuse => {
107 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this video?'), this.i18n('Delete'))
108 if (res === false) return
110 this.videoService.removeVideo(videoAbuse.video.id)
113 this.notifier.success(this.i18n('Video deleted.'))
115 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
118 err => this.notifier.error(err.message)
125 label: this.i18n('Actions for the reporter'),
129 label: this.i18n('Mute reporter'),
130 handler: async videoAbuse => {
131 const account = videoAbuse.reporterAccount as Account
133 this.blocklistService.blockAccountByInstance(account)
136 this.notifier.success(this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }))
138 account.mutedByInstance = true
141 err => this.notifier.error(err.message)
154 return 'VideoAbuseListComponent'
157 openModerationCommentModal (videoAbuse: VideoAbuse) {
158 this.moderationCommentModal.openModal(videoAbuse)
161 onModerationCommentUpdated () {
165 createByString (account: Account) {
166 return Account.CREATE_BY_STRING(account.name, account.host)
169 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
170 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
173 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
174 return videoAbuse.state.id === VideoAbuseState.REJECTED
177 getVideoUrl (videoAbuse: VideoAbuse) {
178 return Video.buildClientUrl(videoAbuse.video.uuid)
181 getVideoEmbed (videoAbuse: VideoAbuse) {
182 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
183 const embedUrl = buildVideoLink({
184 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
187 return buildVideoEmbed(embedUrl)
190 switchToDefaultAvatar ($event: Event) {
191 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
194 async removeVideoAbuse (videoAbuse: VideoAbuse) {
195 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
196 if (res === false) return
198 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
200 this.notifier.success(this.i18n('Abuse deleted.'))
204 err => this.notifier.error(err.message)
208 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
209 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
211 () => this.loadData(),
213 err => this.notifier.error(err.message)
218 protected loadData () {
219 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
221 async resultList => {
222 this.totalRecords = resultList.total
224 this.videoAbuses = resultList.data
226 for (const abuse of this.videoAbuses) {
227 Object.assign(abuse, {
228 reasonHtml: await this.toHtml(abuse.reason),
229 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
230 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)),
231 reporterAccount: new Account(abuse.reporterAccount)
237 err => this.notifier.error(err.message)
241 private toHtml (text: string) {
242 return this.markdownRenderer.textMarkdownToHTML(text)