]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
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',
83b5fe9c 23 styleUrls: [ '../moderation.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
9b4241e3
RK
30 rowsPerPageOptions = [ 20, 50, 100 ]
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'),
9b4241e3 89 isDisplayed: videoAbuse => !videoAbuse.video.deleted,
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 },
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
bb152476
RK
141 err => this.notifier.error(err.message)
142 )
143 }
144 }
145 ]
efc9e845 146 ]
d592e0a9
C
147 }
148
149 ngOnInit () {
24b9417c 150 this.initialize()
df98563e 151 }
11ac88de 152
8e11a1b3
C
153 getIdentifier () {
154 return 'VideoAbuseListComponent'
155 }
156
efc9e845
C
157 openModerationCommentModal (videoAbuse: VideoAbuse) {
158 this.moderationCommentModal.openModal(videoAbuse)
159 }
160
161 onModerationCommentUpdated () {
162 this.loadData()
163 }
164
19a3b914
C
165 createByString (account: Account) {
166 return Account.CREATE_BY_STRING(account.name, account.host)
d592e0a9
C
167 }
168
efc9e845
C
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
191764f3
C
177 getVideoUrl (videoAbuse: VideoAbuse) {
178 return Video.buildClientUrl(videoAbuse.video.uuid)
179 }
180
d6af8146
RK
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
efc9e845 194 async removeVideoAbuse (videoAbuse: VideoAbuse) {
198d764f 195 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
efc9e845
C
196 if (res === false) return
197
198 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
199 () => {
f8b2c1b4 200 this.notifier.success(this.i18n('Abuse deleted.'))
efc9e845
C
201 this.loadData()
202 },
203
f8b2c1b4 204 err => this.notifier.error(err.message)
efc9e845
C
205 )
206 }
207
208 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
209 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
210 .subscribe(
211 () => this.loadData(),
212
f8b2c1b4 213 err => this.notifier.error(err.message)
efc9e845
C
214 )
215
216 }
217
d592e0a9
C
218 protected loadData () {
219 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
220 .subscribe(
41d71344 221 async resultList => {
d592e0a9 222 this.totalRecords = resultList.total
41d71344
C
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),
d6af8146 229 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
9b4241e3
RK
230 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)),
231 reporterAccount: new Account(abuse.reporterAccount)
41d71344
C
232 })
233 }
234
d592e0a9
C
235 },
236
f8b2c1b4 237 err => this.notifier.error(err.message)
d592e0a9 238 )
11ac88de 239 }
41d71344
C
240
241 private toHtml (text: string) {
242 return this.markdownRenderer.textMarkdownToHTML(text)
243 }
11ac88de 244}