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'
15 selector: 'my-video-abuse-list',
16 templateUrl: './video-abuse-list.component.html',
17 styleUrls: [ '../moderation.component.scss']
19 export class VideoAbuseListComponent extends RestTable implements OnInit {
20 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
22 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
25 sort: SortMeta = { field: 'createdAt', order: 1 }
26 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
28 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
31 private notifier: Notifier,
32 private videoAbuseService: VideoAbuseService,
33 private confirmService: ConfirmService,
35 private markdownRenderer: MarkdownService
39 this.videoAbuseActions = [
41 label: this.i18n('Delete this report'),
42 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
45 label: this.i18n('Update moderation comment'),
46 handler: videoAbuse => this.openModerationCommentModal(videoAbuse)
49 label: this.i18n('Mark as accepted'),
50 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
51 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
54 label: this.i18n('Mark as rejected'),
55 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
56 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
66 return 'VideoAbuseListComponent'
69 openModerationCommentModal (videoAbuse: VideoAbuse) {
70 this.moderationCommentModal.openModal(videoAbuse)
73 onModerationCommentUpdated () {
77 createByString (account: Account) {
78 return Account.CREATE_BY_STRING(account.name, account.host)
81 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
82 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
85 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
86 return videoAbuse.state.id === VideoAbuseState.REJECTED
89 getVideoUrl (videoAbuse: VideoAbuse) {
90 return Video.buildClientUrl(videoAbuse.video.uuid)
93 async removeVideoAbuse (videoAbuse: VideoAbuse) {
94 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
95 if (res === false) return
97 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
99 this.notifier.success(this.i18n('Abuse deleted.'))
103 err => this.notifier.error(err.message)
107 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
108 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
110 () => this.loadData(),
112 err => this.notifier.error(err.message)
117 protected loadData () {
118 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
120 async resultList => {
121 this.totalRecords = resultList.total
123 this.videoAbuses = resultList.data
125 for (const abuse of this.videoAbuses) {
126 Object.assign(abuse, {
127 reasonHtml: await this.toHtml(abuse.reason),
128 moderationCommentHtml: await this.toHtml(abuse.moderationComment)
134 err => this.notifier.error(err.message)
138 private toHtml (text: string) {
139 return this.markdownRenderer.textMarkdownToHTML(text)