]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Increase rows per page, add reporter muting for 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 '@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
20 @Component({
21 selector: 'my-video-abuse-list',
22 templateUrl: './video-abuse-list.component.html',
23 styleUrls: [ '../moderation.component.scss']
24 })
25 export class VideoAbuseListComponent extends RestTable implements OnInit {
26 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
27
28 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
29 totalRecords = 0
30 rowsPerPageOptions = [ 20, 50, 100 ]
31 rowsPerPage = this.rowsPerPageOptions[0]
32 sort: SortMeta = { field: 'createdAt', order: 1 }
33 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
34
35 videoAbuseActions: DropdownAction<VideoAbuse>[][] = []
36
37 constructor (
38 private notifier: Notifier,
39 private videoAbuseService: VideoAbuseService,
40 private blocklistService: BlocklistService,
41 private videoService: VideoService,
42 private videoBlacklistService: VideoBlacklistService,
43 private confirmService: ConfirmService,
44 private i18n: I18n,
45 private markdownRenderer: MarkdownService,
46 private sanitizer: DomSanitizer
47 ) {
48 super()
49
50 this.videoAbuseActions = [
51 [
52 {
53 label: this.i18n('Internal actions'),
54 isHeader: true
55 },
56 {
57 label: this.i18n('Delete report'),
58 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
59 },
60 {
61 label: this.i18n('Add note'),
62 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
63 isDisplayed: videoAbuse => !videoAbuse.moderationComment
64 },
65 {
66 label: this.i18n('Update note'),
67 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
68 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
69 },
70 {
71 label: this.i18n('Mark as accepted'),
72 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
73 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
74 },
75 {
76 label: this.i18n('Mark as rejected'),
77 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
78 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
79 }
80 ],
81 [
82 {
83 label: this.i18n('Actions for the video'),
84 isHeader: true,
85 isDisplayed: videoAbuse => !videoAbuse.video.deleted
86 },
87 {
88 label: this.i18n('Blacklist video'),
89 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
90 handler: videoAbuse => {
91 this.videoBlacklistService.blacklistVideo(videoAbuse.video.id, undefined, true)
92 .subscribe(
93 () => {
94 this.notifier.success(this.i18n('Video blacklisted.'))
95
96 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
97 },
98
99 err => this.notifier.error(err.message)
100 )
101 }
102 },
103 {
104 label: this.i18n('Delete video'),
105 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
106 handler: async videoAbuse => {
107 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this video?'), this.i18n('Delete'))
108 if (res === false) return
109
110 this.videoService.removeVideo(videoAbuse.video.id)
111 .subscribe(
112 () => {
113 this.notifier.success(this.i18n('Video deleted.'))
114
115 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
116 },
117
118 err => this.notifier.error(err.message)
119 )
120 }
121 }
122 ],
123 [
124 {
125 label: this.i18n('Actions for the reporter'),
126 isHeader: true
127 },
128 {
129 label: this.i18n('Mute reporter'),
130 handler: async videoAbuse => {
131 const account = videoAbuse.reporterAccount as Account
132
133 this.blocklistService.blockAccountByInstance(account)
134 .subscribe(
135 () => {
136 this.notifier.success(this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }))
137
138 account.mutedByInstance = true
139 },
140
141 err => this.notifier.error(err.message)
142 )
143 }
144 }
145 ]
146 ]
147 }
148
149 ngOnInit () {
150 this.initialize()
151 }
152
153 getIdentifier () {
154 return 'VideoAbuseListComponent'
155 }
156
157 openModerationCommentModal (videoAbuse: VideoAbuse) {
158 this.moderationCommentModal.openModal(videoAbuse)
159 }
160
161 onModerationCommentUpdated () {
162 this.loadData()
163 }
164
165 createByString (account: Account) {
166 return Account.CREATE_BY_STRING(account.name, account.host)
167 }
168
169 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
170 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
171 }
172
173 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
174 return videoAbuse.state.id === VideoAbuseState.REJECTED
175 }
176
177 getVideoUrl (videoAbuse: VideoAbuse) {
178 return Video.buildClientUrl(videoAbuse.video.uuid)
179 }
180
181 getVideoEmbed (videoAbuse: VideoAbuse) {
182 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
183 const embedUrl = buildVideoLink({
184 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
185 warningTitle: false
186 })
187 return buildVideoEmbed(embedUrl)
188 }
189
190 switchToDefaultAvatar ($event: Event) {
191 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
192 }
193
194 async removeVideoAbuse (videoAbuse: VideoAbuse) {
195 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
196 if (res === false) return
197
198 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
199 () => {
200 this.notifier.success(this.i18n('Abuse deleted.'))
201 this.loadData()
202 },
203
204 err => this.notifier.error(err.message)
205 )
206 }
207
208 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
209 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
210 .subscribe(
211 () => this.loadData(),
212
213 err => this.notifier.error(err.message)
214 )
215
216 }
217
218 protected loadData () {
219 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
220 .subscribe(
221 async resultList => {
222 this.totalRecords = resultList.total
223
224 this.videoAbuses = resultList.data
225
226 for (const abuse of this.videoAbuses) {
227 Object.assign(abuse, {
228 reasonHtml: await this.toHtml(abuse.reason),
229 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
230 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)),
231 reporterAccount: new Account(abuse.reporterAccount)
232 })
233 }
234
235 },
236
237 err => this.notifier.error(err.message)
238 )
239 }
240
241 private toHtml (text: string) {
242 return this.markdownRenderer.textMarkdownToHTML(text)
243 }
244 }