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, 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'
19 import { ActivatedRoute } from '@angular/router'
20 import { filter } from 'rxjs/operators'
23 selector: 'my-video-abuse-list',
24 templateUrl: './video-abuse-list.component.html',
25 styleUrls: [ '../moderation.component.scss', './video-abuse-list.component.scss' ]
27 export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit {
28 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
30 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
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,
47 private route: ActivatedRoute
51 this.videoAbuseActions = [
54 label: this.i18n('Internal actions'),
58 label: this.i18n('Delete report'),
59 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
62 label: this.i18n('Add note'),
63 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
64 isDisplayed: videoAbuse => !videoAbuse.moderationComment
67 label: this.i18n('Update note'),
68 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
69 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
72 label: this.i18n('Mark as accepted'),
73 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
74 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
77 label: this.i18n('Mark as rejected'),
78 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
79 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
84 label: this.i18n('Actions for the video'),
86 isDisplayed: videoAbuse => !videoAbuse.video.deleted
89 label: this.i18n('Blacklist video'),
90 isDisplayed: videoAbuse => !videoAbuse.video.deleted && !videoAbuse.video.blacklisted,
91 handler: videoAbuse => {
92 this.videoBlacklistService.blacklistVideo(videoAbuse.video.id, undefined, true)
95 this.notifier.success(this.i18n('Video blacklisted.'))
97 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
100 err => this.notifier.error(err.message)
105 label: this.i18n('Unblacklist video'),
106 isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted,
107 handler: videoAbuse => {
108 this.videoBlacklistService.removeVideoFromBlacklist(videoAbuse.video.id)
111 this.notifier.success(this.i18n('Video unblacklisted.'))
113 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
116 err => this.notifier.error(err.message)
121 label: this.i18n('Delete video'),
122 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
123 handler: async videoAbuse => {
124 const res = await this.confirmService.confirm(
125 this.i18n('Do you really want to delete this video?'),
128 if (res === false) return
130 this.videoService.removeVideo(videoAbuse.video.id)
133 this.notifier.success(this.i18n('Video deleted.'))
135 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
138 err => this.notifier.error(err.message)
145 label: this.i18n('Actions for the reporter'),
149 label: this.i18n('Mute reporter'),
150 handler: async videoAbuse => {
151 const account = videoAbuse.reporterAccount as Account
153 this.blocklistService.blockAccountByInstance(account)
156 this.notifier.success(
157 this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })
160 account.mutedByInstance = true
163 err => this.notifier.error(err.message)
168 label: this.i18n('Mute server'),
169 isDisplayed: videoAbuse => !videoAbuse.reporterAccount.userId,
170 handler: async videoAbuse => {
171 this.blocklistService.blockServerByInstance(videoAbuse.reporterAccount.host)
174 this.notifier.success(
175 this.i18n('Server {{host}} muted by the instance.', { host: videoAbuse.reporterAccount.host })
179 err => this.notifier.error(err.message)
190 this.route.queryParams
191 .pipe(filter(params => params.search !== undefined && params.search !== null))
192 .subscribe(params => {
193 this.search = params.search
194 this.setTableFilter(params.search)
200 if (this.search) this.setTableFilter(this.search)
204 return 'VideoAbuseListComponent'
207 openModerationCommentModal (videoAbuse: VideoAbuse) {
208 this.moderationCommentModal.openModal(videoAbuse)
211 onModerationCommentUpdated () {
215 createByString (account: Account) {
216 return Account.CREATE_BY_STRING(account.name, account.host)
219 setTableFilter (filter: string) {
220 const filterInput = document.getElementById('table-filter') as HTMLInputElement
221 if (filterInput) filterInput.value = filter
224 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
225 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
228 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
229 return videoAbuse.state.id === VideoAbuseState.REJECTED
232 getVideoUrl (videoAbuse: VideoAbuse) {
233 return Video.buildClientUrl(videoAbuse.video.uuid)
236 getVideoEmbed (videoAbuse: VideoAbuse) {
237 const absoluteAPIUrl = getAbsoluteAPIUrl()
238 const embedUrl = buildVideoLink({
239 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
242 return buildVideoEmbed(embedUrl)
245 switchToDefaultAvatar ($event: Event) {
246 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
249 async removeVideoAbuse (videoAbuse: VideoAbuse) {
250 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
251 if (res === false) return
253 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
255 this.notifier.success(this.i18n('Abuse deleted.'))
259 err => this.notifier.error(err.message)
263 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
264 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
266 () => this.loadData(),
268 err => this.notifier.error(err.message)
273 protected loadData () {
274 return this.videoAbuseService.getVideoAbuses({
275 pagination: this.pagination,
279 async resultList => {
280 this.totalRecords = resultList.total
282 this.videoAbuses = resultList.data
284 for (const abuse of this.videoAbuses) {
285 Object.assign(abuse, {
286 reasonHtml: await this.toHtml(abuse.reason),
287 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
288 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)),
289 reporterAccount: new Account(abuse.reporterAccount)
295 err => this.notifier.error(err.message)
299 private toHtml (text: string) {
300 return this.markdownRenderer.textMarkdownToHTML(text)