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', './video-abuse-list.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 && !videoAbuse.video.blacklisted,
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('Unblacklist video'),
105 isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted,
106 handler: videoAbuse => {
107 this.videoBlacklistService.removeVideoFromBlacklist(videoAbuse.video.id)
110 this.notifier.success(this.i18n('Video unblacklisted.'))
112 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
115 err => this.notifier.error(err.message)
120 label: this.i18n('Delete video'),
121 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
122 handler: async videoAbuse => {
123 const res = await this.confirmService.confirm(
124 this.i18n('Do you really want to delete this video?'),
127 if (res === false) return
129 this.videoService.removeVideo(videoAbuse.video.id)
132 this.notifier.success(this.i18n('Video deleted.'))
134 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
137 err => this.notifier.error(err.message)
144 label: this.i18n('Actions for the reporter'),
148 label: this.i18n('Mute reporter'),
149 handler: async videoAbuse => {
150 const account = videoAbuse.reporterAccount as Account
152 this.blocklistService.blockAccountByInstance(account)
155 this.notifier.success(
156 this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })
159 account.mutedByInstance = true
162 err => this.notifier.error(err.message)
167 label: this.i18n('Mute server'),
168 isDisplayed: videoAbuse => !videoAbuse.reporterAccount.userId,
169 handler: async videoAbuse => {
170 this.blocklistService.blockServerByInstance(videoAbuse.reporterAccount.host)
173 this.notifier.success(
174 this.i18n('Server {{host}} muted by the instance.', { host: videoAbuse.reporterAccount.host })
178 err => this.notifier.error(err.message)
191 return 'VideoAbuseListComponent'
194 openModerationCommentModal (videoAbuse: VideoAbuse) {
195 this.moderationCommentModal.openModal(videoAbuse)
198 onModerationCommentUpdated () {
202 createByString (account: Account) {
203 return Account.CREATE_BY_STRING(account.name, account.host)
206 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
207 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
210 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
211 return videoAbuse.state.id === VideoAbuseState.REJECTED
214 getVideoUrl (videoAbuse: VideoAbuse) {
215 return Video.buildClientUrl(videoAbuse.video.uuid)
218 getVideoEmbed (videoAbuse: VideoAbuse) {
219 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
220 const embedUrl = buildVideoLink({
221 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
224 return buildVideoEmbed(embedUrl)
227 switchToDefaultAvatar ($event: Event) {
228 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
231 async removeVideoAbuse (videoAbuse: VideoAbuse) {
232 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
233 if (res === false) return
235 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
237 this.notifier.success(this.i18n('Abuse deleted.'))
241 err => this.notifier.error(err.message)
245 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
246 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
248 () => this.loadData(),
250 err => this.notifier.error(err.message)
255 protected loadData () {
256 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
258 async resultList => {
259 this.totalRecords = resultList.total
261 this.videoAbuses = resultList.data
263 for (const abuse of this.videoAbuses) {
264 Object.assign(abuse, {
265 reasonHtml: await this.toHtml(abuse.reason),
266 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
267 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)),
268 reporterAccount: new Account(abuse.reporterAccount)
274 err => this.notifier.error(err.message)
278 private toHtml (text: string) {
279 return this.markdownRenderer.textMarkdownToHTML(text)