]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Add video channel and video thumbnail, rework video appearance in row
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-abuse-list / video-abuse-list.component.ts
CommitLineData
efc9e845 1import { Component, OnInit, ViewChild } from '@angular/core'
bb152476 2import { Account } from '@app/shared/account/account.model'
f8b2c1b4 3import { Notifier } from '@app/core'
f77eb73b 4import { SortMeta } from 'primeng/api'
efc9e845 5import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
bb152476 6import { RestPagination, RestTable, VideoAbuseService, VideoBlacklistService } from '../../../shared'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
614d1ae9
C
8import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9import { ConfirmService } from '../../../core/index'
efc9e845 10import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
614d1ae9 11import { Video } from '../../../shared/video/video.model'
1506307f 12import { MarkdownService } from '@app/shared/renderer'
d6af8146
RK
13import { Actor } from '@app/shared/actor/actor.model'
14import { buildVideoLink, buildVideoEmbed } from 'src/assets/player/utils'
15import { getAbsoluteAPIUrl } from '@app/shared/misc/utils'
16import { DomSanitizer } from '@angular/platform-browser'
bb152476 17import { BlocklistService } from '@app/shared/blocklist'
9b4241e3 18import { VideoService } from '@app/shared/video/video.service'
19a3b914 19
11ac88de 20@Component({
df98563e 21 selector: 'my-video-abuse-list',
f595d394 22 templateUrl: './video-abuse-list.component.html',
86521a67 23 styleUrls: [ '../moderation.component.scss', './video-abuse-list.component.scss' ]
11ac88de 24})
d592e0a9 25export class VideoAbuseListComponent extends RestTable implements OnInit {
f36da21e 26 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
efc9e845 27
41d71344 28 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
d592e0a9 29 totalRecords = 0
86521a67 30 rowsPerPageOptions = [ 20, 50, 100 ]
9b4241e3 31 rowsPerPage = this.rowsPerPageOptions[0]
ab998f7b 32 sort: SortMeta = { field: 'createdAt', order: 1 }
d592e0a9 33 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
11ac88de 34
bb152476 35 videoAbuseActions: DropdownAction<VideoAbuse>[][] = []
efc9e845 36
df98563e 37 constructor (
f8b2c1b4 38 private notifier: Notifier,
b1d40cff 39 private videoAbuseService: VideoAbuseService,
bb152476 40 private blocklistService: BlocklistService,
9b4241e3 41 private videoService: VideoService,
bb152476 42 private videoBlacklistService: VideoBlacklistService,
efc9e845 43 private confirmService: ConfirmService,
1506307f 44 private i18n: I18n,
d6af8146
RK
45 private markdownRenderer: MarkdownService,
46 private sanitizer: DomSanitizer
28798b5d 47 ) {
d592e0a9 48 super()
efc9e845
C
49
50 this.videoAbuseActions = [
bb152476
RK
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'),
9b4241e3
RK
84 isHeader: true,
85 isDisplayed: videoAbuse => !videoAbuse.video.deleted
bb152476
RK
86 },
87 {
88 label: this.i18n('Blacklist video'),
86521a67 89 isDisplayed: videoAbuse => !videoAbuse.video.deleted && !videoAbuse.video.blacklisted,
bb152476
RK
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
9b4241e3
RK
99 err => this.notifier.error(err.message)
100 )
101 }
102 },
86521a67
RK
103 {
104 label: this.i18n('Unblacklist video'),
105 isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted,
106 handler: videoAbuse => {
107 this.videoBlacklistService.removeVideoFromBlacklist(videoAbuse.video.id)
108 .subscribe(
109 () => {
110 this.notifier.success(this.i18n('Video unblacklisted.'))
111
112 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
113 },
114
115 err => this.notifier.error(err.message)
116 )
117 }
118 },
9b4241e3
RK
119 {
120 label: this.i18n('Delete video'),
121 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
122 handler: async videoAbuse => {
86521a67
RK
123 const res = await this.confirmService.confirm(
124 this.i18n('Do you really want to delete this video?'),
125 this.i18n('Delete')
126 )
9b4241e3
RK
127 if (res === false) return
128
129 this.videoService.removeVideo(videoAbuse.video.id)
130 .subscribe(
131 () => {
132 this.notifier.success(this.i18n('Video deleted.'))
133
134 this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED)
135 },
136
137 err => this.notifier.error(err.message)
138 )
139 }
140 }
141 ],
142 [
143 {
144 label: this.i18n('Actions for the reporter'),
145 isHeader: true
146 },
147 {
86521a67 148 label: this.i18n('Mute reporter'),
9b4241e3
RK
149 handler: async videoAbuse => {
150 const account = videoAbuse.reporterAccount as Account
151
152 this.blocklistService.blockAccountByInstance(account)
153 .subscribe(
154 () => {
86521a67
RK
155 this.notifier.success(
156 this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })
157 )
9b4241e3
RK
158
159 account.mutedByInstance = true
160 },
161
86521a67
RK
162 err => this.notifier.error(err.message)
163 )
164 }
165 },
166 {
167 label: this.i18n('Mute server'),
168 isDisplayed: videoAbuse => !videoAbuse.reporterAccount.userId,
169 handler: async videoAbuse => {
170 this.blocklistService.blockServerByInstance(videoAbuse.reporterAccount.host)
171 .subscribe(
172 () => {
173 this.notifier.success(
174 this.i18n('Server {{host}} muted by the instance.', { host: videoAbuse.reporterAccount.host })
175 )
176 },
177
bb152476
RK
178 err => this.notifier.error(err.message)
179 )
180 }
181 }
182 ]
efc9e845 183 ]
d592e0a9
C
184 }
185
186 ngOnInit () {
24b9417c 187 this.initialize()
df98563e 188 }
11ac88de 189
8e11a1b3
C
190 getIdentifier () {
191 return 'VideoAbuseListComponent'
192 }
193
efc9e845
C
194 openModerationCommentModal (videoAbuse: VideoAbuse) {
195 this.moderationCommentModal.openModal(videoAbuse)
196 }
197
198 onModerationCommentUpdated () {
199 this.loadData()
200 }
201
19a3b914
C
202 createByString (account: Account) {
203 return Account.CREATE_BY_STRING(account.name, account.host)
d592e0a9
C
204 }
205
efc9e845
C
206 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
207 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
208 }
209
210 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
211 return videoAbuse.state.id === VideoAbuseState.REJECTED
212 }
213
191764f3
C
214 getVideoUrl (videoAbuse: VideoAbuse) {
215 return Video.buildClientUrl(videoAbuse.video.uuid)
216 }
217
d6af8146
RK
218 getVideoEmbed (videoAbuse: VideoAbuse) {
219 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
220 const embedUrl = buildVideoLink({
221 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
222 warningTitle: false
223 })
224 return buildVideoEmbed(embedUrl)
225 }
226
227 switchToDefaultAvatar ($event: Event) {
228 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
229 }
230
efc9e845 231 async removeVideoAbuse (videoAbuse: VideoAbuse) {
198d764f 232 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
efc9e845
C
233 if (res === false) return
234
235 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
236 () => {
f8b2c1b4 237 this.notifier.success(this.i18n('Abuse deleted.'))
efc9e845
C
238 this.loadData()
239 },
240
f8b2c1b4 241 err => this.notifier.error(err.message)
efc9e845
C
242 )
243 }
244
245 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
246 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
247 .subscribe(
248 () => this.loadData(),
249
f8b2c1b4 250 err => this.notifier.error(err.message)
efc9e845
C
251 )
252
253 }
254
d592e0a9
C
255 protected loadData () {
256 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
257 .subscribe(
41d71344 258 async resultList => {
d592e0a9 259 this.totalRecords = resultList.total
41d71344
C
260
261 this.videoAbuses = resultList.data
262
263 for (const abuse of this.videoAbuses) {
264 Object.assign(abuse, {
265 reasonHtml: await this.toHtml(abuse.reason),
d6af8146 266 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
9b4241e3
RK
267 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)),
268 reporterAccount: new Account(abuse.reporterAccount)
41d71344
C
269 })
270 }
271
d592e0a9
C
272 },
273
f8b2c1b4 274 err => this.notifier.error(err.message)
d592e0a9 275 )
11ac88de 276 }
41d71344
C
277
278 private toHtml (text: string) {
279 return this.markdownRenderer.textMarkdownToHTML(text)
280 }
11ac88de 281}