]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Rich reporter field and video embed in moderation abuse list
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-abuse-list / video-abuse-list.component.ts
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'
17
18 @Component({
19 selector: 'my-video-abuse-list',
20 templateUrl: './video-abuse-list.component.html',
21 styleUrls: [ '../moderation.component.scss']
22 })
23 export class VideoAbuseListComponent extends RestTable implements OnInit {
24 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
25
26 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
27 totalRecords = 0
28 rowsPerPage = 10
29 sort: SortMeta = { field: 'createdAt', order: 1 }
30 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
31
32 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
33
34 constructor (
35 private notifier: Notifier,
36 private videoAbuseService: VideoAbuseService,
37 private confirmService: ConfirmService,
38 private i18n: I18n,
39 private markdownRenderer: MarkdownService,
40 private sanitizer: DomSanitizer
41 ) {
42 super()
43
44 this.videoAbuseActions = [
45 {
46 label: this.i18n('Delete this report'),
47 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
48 },
49 {
50 label: this.i18n('Add note'),
51 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
52 isDisplayed: videoAbuse => !videoAbuse.moderationComment
53 },
54 {
55 label: this.i18n('Update note'),
56 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
57 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
58 },
59 {
60 label: this.i18n('Mark as accepted'),
61 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
62 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
63 },
64 {
65 label: this.i18n('Mark as rejected'),
66 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
67 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
68 }
69 ]
70 }
71
72 ngOnInit () {
73 this.initialize()
74 }
75
76 getIdentifier () {
77 return 'VideoAbuseListComponent'
78 }
79
80 openModerationCommentModal (videoAbuse: VideoAbuse) {
81 this.moderationCommentModal.openModal(videoAbuse)
82 }
83
84 onModerationCommentUpdated () {
85 this.loadData()
86 }
87
88 createByString (account: Account) {
89 return Account.CREATE_BY_STRING(account.name, account.host)
90 }
91
92 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
93 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
94 }
95
96 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
97 return videoAbuse.state.id === VideoAbuseState.REJECTED
98 }
99
100 getVideoUrl (videoAbuse: VideoAbuse) {
101 return Video.buildClientUrl(videoAbuse.video.uuid)
102 }
103
104 getVideoEmbed (videoAbuse: VideoAbuse) {
105 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
106 const embedUrl = buildVideoLink({
107 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
108 warningTitle: false
109 })
110 return buildVideoEmbed(embedUrl)
111 }
112
113 switchToDefaultAvatar ($event: Event) {
114 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
115 }
116
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
120
121 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
122 () => {
123 this.notifier.success(this.i18n('Abuse deleted.'))
124 this.loadData()
125 },
126
127 err => this.notifier.error(err.message)
128 )
129 }
130
131 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
132 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
133 .subscribe(
134 () => this.loadData(),
135
136 err => this.notifier.error(err.message)
137 )
138
139 }
140
141 protected loadData () {
142 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
143 .subscribe(
144 async resultList => {
145 this.totalRecords = resultList.total
146
147 this.videoAbuses = resultList.data
148
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))
154 })
155 }
156
157 },
158
159 err => this.notifier.error(err.message)
160 )
161 }
162
163 private toHtml (text: string) {
164 return this.markdownRenderer.textMarkdownToHTML(text)
165 }
166 }