]>
Commit | Line | Data |
---|---|---|
36004aa7 | 1 | import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core' |
bb152476 | 2 | import { Account } from '@app/shared/account/account.model' |
f8b2c1b4 | 3 | import { Notifier } from '@app/core' |
f77eb73b | 4 | import { SortMeta } from 'primeng/api' |
efc9e845 | 5 | import { VideoAbuse, VideoAbuseState } from '../../../../../../shared' |
bb152476 | 6 | import { RestPagination, RestTable, VideoAbuseService, VideoBlacklistService } from '../../../shared' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
614d1ae9 C |
8 | import { DropdownAction } from '../../../shared/buttons/action-dropdown.component' |
9 | import { ConfirmService } from '../../../core/index' | |
efc9e845 | 10 | import { ModerationCommentModalComponent } from './moderation-comment-modal.component' |
614d1ae9 | 11 | import { Video } from '../../../shared/video/video.model' |
1506307f | 12 | import { MarkdownService } from '@app/shared/renderer' |
d6af8146 RK |
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' | |
bb152476 | 17 | import { BlocklistService } from '@app/shared/blocklist' |
9b4241e3 | 18 | import { VideoService } from '@app/shared/video/video.service' |
844db39e | 19 | import { ActivatedRoute } from '@angular/router' |
36004aa7 | 20 | import { filter } from 'rxjs/operators' |
19a3b914 | 21 | |
11ac88de | 22 | @Component({ |
df98563e | 23 | selector: 'my-video-abuse-list', |
f595d394 | 24 | templateUrl: './video-abuse-list.component.html', |
86521a67 | 25 | styleUrls: [ '../moderation.component.scss', './video-abuse-list.component.scss' ] |
11ac88de | 26 | }) |
36004aa7 | 27 | export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit { |
f36da21e | 28 | @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent |
efc9e845 | 29 | |
41d71344 | 30 | videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = [] |
d592e0a9 | 31 | totalRecords = 0 |
86521a67 | 32 | rowsPerPageOptions = [ 20, 50, 100 ] |
9b4241e3 | 33 | rowsPerPage = this.rowsPerPageOptions[0] |
ab998f7b | 34 | sort: SortMeta = { field: 'createdAt', order: 1 } |
d592e0a9 | 35 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
11ac88de | 36 | |
bb152476 | 37 | videoAbuseActions: DropdownAction<VideoAbuse>[][] = [] |
efc9e845 | 38 | |
df98563e | 39 | constructor ( |
f8b2c1b4 | 40 | private notifier: Notifier, |
b1d40cff | 41 | private videoAbuseService: VideoAbuseService, |
bb152476 | 42 | private blocklistService: BlocklistService, |
9b4241e3 | 43 | private videoService: VideoService, |
bb152476 | 44 | private videoBlacklistService: VideoBlacklistService, |
efc9e845 | 45 | private confirmService: ConfirmService, |
1506307f | 46 | private i18n: I18n, |
d6af8146 | 47 | private markdownRenderer: MarkdownService, |
844db39e | 48 | private sanitizer: DomSanitizer, |
5fd4ca00 | 49 | private route: ActivatedRoute |
28798b5d | 50 | ) { |
d592e0a9 | 51 | super() |
efc9e845 C |
52 | |
53 | this.videoAbuseActions = [ | |
bb152476 RK |
54 | [ |
55 | { | |
56 | label: this.i18n('Internal actions'), | |
57 | isHeader: true | |
58 | }, | |
59 | { | |
60 | label: this.i18n('Delete report'), | |
61 | handler: videoAbuse => this.removeVideoAbuse(videoAbuse) | |
62 | }, | |
63 | { | |
64 | label: this.i18n('Add note'), | |
65 | handler: videoAbuse => this.openModerationCommentModal(videoAbuse), | |
66 | isDisplayed: videoAbuse => !videoAbuse.moderationComment | |
67 | }, | |
68 | { | |
69 | label: this.i18n('Update note'), | |
70 | handler: videoAbuse => this.openModerationCommentModal(videoAbuse), | |
71 | isDisplayed: videoAbuse => !!videoAbuse.moderationComment | |
72 | }, | |
73 | { | |
74 | label: this.i18n('Mark as accepted'), | |
75 | handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED), | |
76 | isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse) | |
77 | }, | |
78 | { | |
79 | label: this.i18n('Mark as rejected'), | |
80 | handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED), | |
81 | isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse) | |
82 | } | |
83 | ], | |
84 | [ | |
85 | { | |
86 | label: this.i18n('Actions for the video'), | |
9b4241e3 RK |
87 | isHeader: true, |
88 | isDisplayed: videoAbuse => !videoAbuse.video.deleted | |
bb152476 RK |
89 | }, |
90 | { | |
91 | label: this.i18n('Blacklist video'), | |
86521a67 | 92 | isDisplayed: videoAbuse => !videoAbuse.video.deleted && !videoAbuse.video.blacklisted, |
bb152476 RK |
93 | handler: videoAbuse => { |
94 | this.videoBlacklistService.blacklistVideo(videoAbuse.video.id, undefined, true) | |
95 | .subscribe( | |
96 | () => { | |
97 | this.notifier.success(this.i18n('Video blacklisted.')) | |
98 | ||
99 | this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) | |
100 | }, | |
101 | ||
9b4241e3 RK |
102 | err => this.notifier.error(err.message) |
103 | ) | |
104 | } | |
105 | }, | |
86521a67 RK |
106 | { |
107 | label: this.i18n('Unblacklist video'), | |
108 | isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted, | |
109 | handler: videoAbuse => { | |
110 | this.videoBlacklistService.removeVideoFromBlacklist(videoAbuse.video.id) | |
111 | .subscribe( | |
112 | () => { | |
113 | this.notifier.success(this.i18n('Video unblacklisted.')) | |
114 | ||
115 | this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) | |
116 | }, | |
117 | ||
118 | err => this.notifier.error(err.message) | |
119 | ) | |
120 | } | |
121 | }, | |
9b4241e3 RK |
122 | { |
123 | label: this.i18n('Delete video'), | |
124 | isDisplayed: videoAbuse => !videoAbuse.video.deleted, | |
125 | handler: async videoAbuse => { | |
86521a67 RK |
126 | const res = await this.confirmService.confirm( |
127 | this.i18n('Do you really want to delete this video?'), | |
128 | this.i18n('Delete') | |
129 | ) | |
9b4241e3 RK |
130 | if (res === false) return |
131 | ||
132 | this.videoService.removeVideo(videoAbuse.video.id) | |
133 | .subscribe( | |
134 | () => { | |
135 | this.notifier.success(this.i18n('Video deleted.')) | |
136 | ||
137 | this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) | |
138 | }, | |
139 | ||
140 | err => this.notifier.error(err.message) | |
141 | ) | |
142 | } | |
143 | } | |
144 | ], | |
145 | [ | |
146 | { | |
147 | label: this.i18n('Actions for the reporter'), | |
148 | isHeader: true | |
149 | }, | |
150 | { | |
86521a67 | 151 | label: this.i18n('Mute reporter'), |
9b4241e3 RK |
152 | handler: async videoAbuse => { |
153 | const account = videoAbuse.reporterAccount as Account | |
154 | ||
155 | this.blocklistService.blockAccountByInstance(account) | |
156 | .subscribe( | |
157 | () => { | |
86521a67 RK |
158 | this.notifier.success( |
159 | this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }) | |
160 | ) | |
9b4241e3 RK |
161 | |
162 | account.mutedByInstance = true | |
163 | }, | |
164 | ||
86521a67 RK |
165 | err => this.notifier.error(err.message) |
166 | ) | |
167 | } | |
168 | }, | |
169 | { | |
170 | label: this.i18n('Mute server'), | |
171 | isDisplayed: videoAbuse => !videoAbuse.reporterAccount.userId, | |
172 | handler: async videoAbuse => { | |
173 | this.blocklistService.blockServerByInstance(videoAbuse.reporterAccount.host) | |
174 | .subscribe( | |
175 | () => { | |
176 | this.notifier.success( | |
177 | this.i18n('Server {{host}} muted by the instance.', { host: videoAbuse.reporterAccount.host }) | |
178 | ) | |
179 | }, | |
180 | ||
bb152476 RK |
181 | err => this.notifier.error(err.message) |
182 | ) | |
183 | } | |
184 | } | |
185 | ] | |
efc9e845 | 186 | ] |
d592e0a9 C |
187 | } |
188 | ||
189 | ngOnInit () { | |
24b9417c | 190 | this.initialize() |
844db39e RK |
191 | |
192 | this.route.queryParams | |
36004aa7 RK |
193 | .pipe(filter(params => params.search !== undefined && params.search !== null)) |
194 | .subscribe(params => { | |
195 | this.search = params.search | |
196 | this.setTableFilter(params.search) | |
197 | this.loadData() | |
198 | }) | |
199 | } | |
200 | ||
201 | ngAfterViewInit () { | |
202 | this.setTableFilter(this.search) | |
df98563e | 203 | } |
11ac88de | 204 | |
8e11a1b3 C |
205 | getIdentifier () { |
206 | return 'VideoAbuseListComponent' | |
207 | } | |
208 | ||
efc9e845 C |
209 | openModerationCommentModal (videoAbuse: VideoAbuse) { |
210 | this.moderationCommentModal.openModal(videoAbuse) | |
211 | } | |
212 | ||
213 | onModerationCommentUpdated () { | |
214 | this.loadData() | |
215 | } | |
216 | ||
19a3b914 C |
217 | createByString (account: Account) { |
218 | return Account.CREATE_BY_STRING(account.name, account.host) | |
d592e0a9 C |
219 | } |
220 | ||
36004aa7 RK |
221 | setTableFilter (filter: string) { |
222 | const filterInput = document.getElementById('table-filter') as HTMLInputElement | |
223 | if (filterInput) filterInput.value = filter | |
224 | } | |
225 | ||
efc9e845 C |
226 | isVideoAbuseAccepted (videoAbuse: VideoAbuse) { |
227 | return videoAbuse.state.id === VideoAbuseState.ACCEPTED | |
228 | } | |
229 | ||
230 | isVideoAbuseRejected (videoAbuse: VideoAbuse) { | |
231 | return videoAbuse.state.id === VideoAbuseState.REJECTED | |
232 | } | |
233 | ||
191764f3 C |
234 | getVideoUrl (videoAbuse: VideoAbuse) { |
235 | return Video.buildClientUrl(videoAbuse.video.uuid) | |
236 | } | |
237 | ||
d6af8146 | 238 | getVideoEmbed (videoAbuse: VideoAbuse) { |
042daa70 | 239 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
d6af8146 RK |
240 | const embedUrl = buildVideoLink({ |
241 | baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid, | |
242 | warningTitle: false | |
243 | }) | |
244 | return buildVideoEmbed(embedUrl) | |
245 | } | |
246 | ||
247 | switchToDefaultAvatar ($event: Event) { | |
248 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | |
249 | } | |
250 | ||
efc9e845 | 251 | async removeVideoAbuse (videoAbuse: VideoAbuse) { |
198d764f | 252 | const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete')) |
efc9e845 C |
253 | if (res === false) return |
254 | ||
255 | this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe( | |
256 | () => { | |
f8b2c1b4 | 257 | this.notifier.success(this.i18n('Abuse deleted.')) |
efc9e845 C |
258 | this.loadData() |
259 | }, | |
260 | ||
f8b2c1b4 | 261 | err => this.notifier.error(err.message) |
efc9e845 C |
262 | ) |
263 | } | |
264 | ||
265 | updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) { | |
266 | this.videoAbuseService.updateVideoAbuse(videoAbuse, { state }) | |
267 | .subscribe( | |
268 | () => this.loadData(), | |
269 | ||
f8b2c1b4 | 270 | err => this.notifier.error(err.message) |
efc9e845 C |
271 | ) |
272 | ||
273 | } | |
274 | ||
d592e0a9 | 275 | protected loadData () { |
844db39e RK |
276 | return this.videoAbuseService.getVideoAbuses({ |
277 | pagination: this.pagination, | |
042daa70 | 278 | sort: this.sort, |
844db39e RK |
279 | search: this.search |
280 | }).subscribe( | |
281 | async resultList => { | |
282 | this.totalRecords = resultList.total | |
283 | ||
284 | this.videoAbuses = resultList.data | |
285 | ||
286 | for (const abuse of this.videoAbuses) { | |
287 | Object.assign(abuse, { | |
288 | reasonHtml: await this.toHtml(abuse.reason), | |
289 | moderationCommentHtml: await this.toHtml(abuse.moderationComment), | |
290 | embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)), | |
291 | reporterAccount: new Account(abuse.reporterAccount) | |
292 | }) | |
293 | } | |
294 | ||
295 | }, | |
296 | ||
297 | err => this.notifier.error(err.message) | |
298 | ) | |
11ac88de | 299 | } |
41d71344 C |
300 | |
301 | private toHtml (text: string) { | |
302 | return this.markdownRenderer.textMarkdownToHTML(text) | |
303 | } | |
11ac88de | 304 | } |