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/components/common/sortmeta'
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') 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)
65 openModerationCommentModal (videoAbuse: VideoAbuse) {
66 this.moderationCommentModal.openModal(videoAbuse)
69 onModerationCommentUpdated () {
73 createByString (account: Account) {
74 return Account.CREATE_BY_STRING(account.name, account.host)
77 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
78 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
81 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
82 return videoAbuse.state.id === VideoAbuseState.REJECTED
85 getVideoUrl (videoAbuse: VideoAbuse) {
86 return Video.buildClientUrl(videoAbuse.video.uuid)
89 async removeVideoAbuse (videoAbuse: VideoAbuse) {
90 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
91 if (res === false) return
93 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
95 this.notifier.success(this.i18n('Abuse deleted.'))
99 err => this.notifier.error(err.message)
103 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
104 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
106 () => this.loadData(),
108 err => this.notifier.error(err.message)
113 protected loadData () {
114 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
116 async resultList => {
117 this.totalRecords = resultList.total
119 this.videoAbuses = resultList.data
121 for (const abuse of this.videoAbuses) {
122 Object.assign(abuse, {
123 reasonHtml: await this.toHtml(abuse.reason),
124 moderationCommentHtml: await this.toHtml(abuse.moderationComment)
130 err => this.notifier.error(err.message)
134 private toHtml (text: string) {
135 return this.markdownRenderer.textMarkdownToHTML(text)