1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Account } from '../../../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 } 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'
19 selector: 'my-video-abuse-list',
20 templateUrl: './video-abuse-list.component.html',
21 styleUrls: [ '../moderation.component.scss']
23 export class VideoAbuseListComponent extends RestTable implements OnInit {
24 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
26 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
29 sort: SortMeta = { field: 'createdAt', order: 1 }
30 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
32 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
35 private notifier: Notifier,
36 private videoAbuseService: VideoAbuseService,
37 private confirmService: ConfirmService,
39 private markdownRenderer: MarkdownService,
40 private sanitizer: DomSanitizer
44 this.videoAbuseActions = [
46 label: this.i18n('Delete this report'),
47 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
50 label: this.i18n('Add note'),
51 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
52 isDisplayed: videoAbuse => !videoAbuse.moderationComment
55 label: this.i18n('Update note'),
56 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
57 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
60 label: this.i18n('Mark as accepted'),
61 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
62 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
65 label: this.i18n('Mark as rejected'),
66 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
67 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
77 return 'VideoAbuseListComponent'
80 openModerationCommentModal (videoAbuse: VideoAbuse) {
81 this.moderationCommentModal.openModal(videoAbuse)
84 onModerationCommentUpdated () {
88 createByString (account: Account) {
89 return Account.CREATE_BY_STRING(account.name, account.host)
92 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
93 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
96 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
97 return videoAbuse.state.id === VideoAbuseState.REJECTED
100 getVideoUrl (videoAbuse: VideoAbuse) {
101 return Video.buildClientUrl(videoAbuse.video.uuid)
104 getVideoEmbed (videoAbuse: VideoAbuse) {
105 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
106 const embedUrl = buildVideoLink({
107 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
110 return buildVideoEmbed(embedUrl)
113 switchToDefaultAvatar ($event: Event) {
114 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
117 async removeVideoAbuse (videoAbuse: VideoAbuse) {
118 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
119 if (res === false) return
121 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
123 this.notifier.success(this.i18n('Abuse deleted.'))
127 err => this.notifier.error(err.message)
131 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
132 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
134 () => this.loadData(),
136 err => this.notifier.error(err.message)
141 protected loadData () {
142 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
144 async resultList => {
145 this.totalRecords = resultList.total
147 this.videoAbuses = resultList.data
149 for (const abuse of this.videoAbuses) {
150 Object.assign(abuse, {
151 reasonHtml: await this.toHtml(abuse.reason),
152 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
153 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse))
159 err => this.notifier.error(err.message)
163 private toHtml (text: string) {
164 return this.markdownRenderer.textMarkdownToHTML(text)