]>
Commit | Line | Data |
---|---|---|
f77eb73b | 1 | import { SortMeta } from 'primeng/api' |
1ebddadd | 2 | import { buildVideoEmbed, buildVideoLink } from 'src/assets/player/utils' |
67ed6552 C |
3 | import { environment } from 'src/environments/environment' |
4 | import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core' | |
d6af8146 | 5 | import { DomSanitizer } from '@angular/platform-browser' |
25a42e29 | 6 | import { ActivatedRoute, Params, Router } from '@angular/router' |
67ed6552 C |
7 | import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core' |
8 | import { Account, Actor, DropdownAction, Video, VideoService } from '@app/shared/shared-main' | |
d95d1559 | 9 | import { AbuseService, BlocklistService, VideoBlockService } from '@app/shared/shared-moderation' |
67ed6552 | 10 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d95d1559 | 11 | import { Abuse, AbuseState } from '@shared/models' |
67ed6552 | 12 | import { ModerationCommentModalComponent } from './moderation-comment-modal.component' |
19a3b914 | 13 | |
d95d1559 | 14 | export type ProcessedAbuse = Abuse & { |
25a42e29 RK |
15 | moderationCommentHtml?: string, |
16 | reasonHtml?: string | |
17 | embedHtml?: string | |
18 | updatedAt?: Date | |
d95d1559 | 19 | |
25a42e29 RK |
20 | // override bare server-side definitions with rich client-side definitions |
21 | reporterAccount: Account | |
d95d1559 C |
22 | |
23 | video: Abuse['video'] & { | |
24 | channel: Abuse['video']['channel'] & { | |
25a42e29 RK |
25 | ownerAccount: Account |
26 | } | |
27 | } | |
28 | } | |
29 | ||
11ac88de | 30 | @Component({ |
d95d1559 C |
31 | selector: 'my-abuse-list', |
32 | templateUrl: './abuse-list.component.html', | |
33 | styleUrls: [ '../moderation.component.scss', './abuse-list.component.scss' ] | |
11ac88de | 34 | }) |
d95d1559 | 35 | export class AbuseListComponent extends RestTable implements OnInit, AfterViewInit { |
f36da21e | 36 | @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent |
efc9e845 | 37 | |
d95d1559 | 38 | abuses: ProcessedAbuse[] = [] |
d592e0a9 | 39 | totalRecords = 0 |
ab998f7b | 40 | sort: SortMeta = { field: 'createdAt', order: 1 } |
d592e0a9 | 41 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
11ac88de | 42 | |
d95d1559 | 43 | abuseActions: DropdownAction<Abuse>[][] = [] |
efc9e845 | 44 | |
df98563e | 45 | constructor ( |
f8b2c1b4 | 46 | private notifier: Notifier, |
d95d1559 | 47 | private abuseService: AbuseService, |
bb152476 | 48 | private blocklistService: BlocklistService, |
9b4241e3 | 49 | private videoService: VideoService, |
5baee5fc | 50 | private videoBlocklistService: VideoBlockService, |
efc9e845 | 51 | private confirmService: ConfirmService, |
1506307f | 52 | private i18n: I18n, |
d6af8146 | 53 | private markdownRenderer: MarkdownService, |
844db39e | 54 | private sanitizer: DomSanitizer, |
25a42e29 RK |
55 | private route: ActivatedRoute, |
56 | private router: Router | |
28798b5d | 57 | ) { |
d592e0a9 | 58 | super() |
efc9e845 | 59 | |
d95d1559 | 60 | this.abuseActions = [ |
bb152476 RK |
61 | [ |
62 | { | |
63 | label: this.i18n('Internal actions'), | |
64 | isHeader: true | |
65 | }, | |
66 | { | |
67 | label: this.i18n('Delete report'), | |
d95d1559 | 68 | handler: abuse => this.removeAbuse(abuse) |
bb152476 RK |
69 | }, |
70 | { | |
71 | label: this.i18n('Add note'), | |
d95d1559 C |
72 | handler: abuse => this.openModerationCommentModal(abuse), |
73 | isDisplayed: abuse => !abuse.moderationComment | |
bb152476 RK |
74 | }, |
75 | { | |
76 | label: this.i18n('Update note'), | |
d95d1559 C |
77 | handler: abuse => this.openModerationCommentModal(abuse), |
78 | isDisplayed: abuse => !!abuse.moderationComment | |
bb152476 RK |
79 | }, |
80 | { | |
81 | label: this.i18n('Mark as accepted'), | |
d95d1559 C |
82 | handler: abuse => this.updateAbuseState(abuse, AbuseState.ACCEPTED), |
83 | isDisplayed: abuse => !this.isAbuseAccepted(abuse) | |
bb152476 RK |
84 | }, |
85 | { | |
86 | label: this.i18n('Mark as rejected'), | |
d95d1559 C |
87 | handler: abuse => this.updateAbuseState(abuse, AbuseState.REJECTED), |
88 | isDisplayed: abuse => !this.isAbuseRejected(abuse) | |
bb152476 RK |
89 | } |
90 | ], | |
91 | [ | |
92 | { | |
93 | label: this.i18n('Actions for the video'), | |
9b4241e3 | 94 | isHeader: true, |
d95d1559 | 95 | isDisplayed: abuse => !abuse.video.deleted |
bb152476 RK |
96 | }, |
97 | { | |
5baee5fc | 98 | label: this.i18n('Block video'), |
d95d1559 C |
99 | isDisplayed: abuse => !abuse.video.deleted && !abuse.video.blacklisted, |
100 | handler: abuse => { | |
101 | this.videoBlocklistService.blockVideo(abuse.video.id, undefined, true) | |
bb152476 RK |
102 | .subscribe( |
103 | () => { | |
3487330d | 104 | this.notifier.success(this.i18n('Video blocked.')) |
bb152476 | 105 | |
d95d1559 | 106 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) |
bb152476 RK |
107 | }, |
108 | ||
9b4241e3 RK |
109 | err => this.notifier.error(err.message) |
110 | ) | |
111 | } | |
112 | }, | |
86521a67 | 113 | { |
5baee5fc | 114 | label: this.i18n('Unblock video'), |
d95d1559 C |
115 | isDisplayed: abuse => !abuse.video.deleted && abuse.video.blacklisted, |
116 | handler: abuse => { | |
117 | this.videoBlocklistService.unblockVideo(abuse.video.id) | |
86521a67 RK |
118 | .subscribe( |
119 | () => { | |
3487330d | 120 | this.notifier.success(this.i18n('Video unblocked.')) |
86521a67 | 121 | |
d95d1559 | 122 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) |
86521a67 RK |
123 | }, |
124 | ||
125 | err => this.notifier.error(err.message) | |
126 | ) | |
127 | } | |
128 | }, | |
9b4241e3 RK |
129 | { |
130 | label: this.i18n('Delete video'), | |
d95d1559 C |
131 | isDisplayed: abuse => !abuse.video.deleted, |
132 | handler: async abuse => { | |
86521a67 RK |
133 | const res = await this.confirmService.confirm( |
134 | this.i18n('Do you really want to delete this video?'), | |
135 | this.i18n('Delete') | |
136 | ) | |
9b4241e3 RK |
137 | if (res === false) return |
138 | ||
d95d1559 | 139 | this.videoService.removeVideo(abuse.video.id) |
9b4241e3 RK |
140 | .subscribe( |
141 | () => { | |
142 | this.notifier.success(this.i18n('Video deleted.')) | |
143 | ||
d95d1559 | 144 | this.updateAbuseState(abuse, AbuseState.ACCEPTED) |
9b4241e3 RK |
145 | }, |
146 | ||
147 | err => this.notifier.error(err.message) | |
148 | ) | |
149 | } | |
150 | } | |
151 | ], | |
152 | [ | |
153 | { | |
154 | label: this.i18n('Actions for the reporter'), | |
155 | isHeader: true | |
156 | }, | |
157 | { | |
86521a67 | 158 | label: this.i18n('Mute reporter'), |
d95d1559 C |
159 | handler: async abuse => { |
160 | const account = abuse.reporterAccount as Account | |
9b4241e3 RK |
161 | |
162 | this.blocklistService.blockAccountByInstance(account) | |
163 | .subscribe( | |
164 | () => { | |
86521a67 RK |
165 | this.notifier.success( |
166 | this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }) | |
167 | ) | |
9b4241e3 RK |
168 | |
169 | account.mutedByInstance = true | |
170 | }, | |
171 | ||
86521a67 RK |
172 | err => this.notifier.error(err.message) |
173 | ) | |
174 | } | |
175 | }, | |
176 | { | |
177 | label: this.i18n('Mute server'), | |
d95d1559 C |
178 | isDisplayed: abuse => !abuse.reporterAccount.userId, |
179 | handler: async abuse => { | |
180 | this.blocklistService.blockServerByInstance(abuse.reporterAccount.host) | |
86521a67 RK |
181 | .subscribe( |
182 | () => { | |
183 | this.notifier.success( | |
d95d1559 | 184 | this.i18n('Server {{host}} muted by the instance.', { host: abuse.reporterAccount.host }) |
86521a67 RK |
185 | ) |
186 | }, | |
187 | ||
bb152476 RK |
188 | err => this.notifier.error(err.message) |
189 | ) | |
190 | } | |
191 | } | |
192 | ] | |
efc9e845 | 193 | ] |
d592e0a9 C |
194 | } |
195 | ||
196 | ngOnInit () { | |
24b9417c | 197 | this.initialize() |
844db39e RK |
198 | |
199 | this.route.queryParams | |
36004aa7 | 200 | .subscribe(params => { |
d8b38291 C |
201 | this.search = params.search || '' |
202 | ||
203 | this.setTableFilter(this.search) | |
36004aa7 RK |
204 | this.loadData() |
205 | }) | |
206 | } | |
207 | ||
208 | ngAfterViewInit () { | |
0251197e | 209 | if (this.search) this.setTableFilter(this.search) |
df98563e | 210 | } |
11ac88de | 211 | |
8e11a1b3 | 212 | getIdentifier () { |
d95d1559 | 213 | return 'AbuseListComponent' |
8e11a1b3 C |
214 | } |
215 | ||
d95d1559 C |
216 | openModerationCommentModal (abuse: Abuse) { |
217 | this.moderationCommentModal.openModal(abuse) | |
efc9e845 C |
218 | } |
219 | ||
220 | onModerationCommentUpdated () { | |
221 | this.loadData() | |
222 | } | |
223 | ||
25a42e29 RK |
224 | /* Table filter functions */ |
225 | onAbuseSearch (event: Event) { | |
226 | this.onSearch(event) | |
227 | this.setQueryParams((event.target as HTMLInputElement).value) | |
228 | } | |
229 | ||
230 | setQueryParams (search: string) { | |
231 | const queryParams: Params = {} | |
232 | if (search) Object.assign(queryParams, { search }) | |
d8b38291 | 233 | |
25a42e29 | 234 | this.router.navigate([ '/admin/moderation/video-abuses/list' ], { queryParams }) |
d592e0a9 C |
235 | } |
236 | ||
25a42e29 RK |
237 | resetTableFilter () { |
238 | this.setTableFilter('') | |
239 | this.setQueryParams('') | |
240 | this.resetSearch() | |
36004aa7 | 241 | } |
25a42e29 | 242 | /* END Table filter functions */ |
36004aa7 | 243 | |
d95d1559 C |
244 | isAbuseAccepted (abuse: Abuse) { |
245 | return abuse.state.id === AbuseState.ACCEPTED | |
efc9e845 C |
246 | } |
247 | ||
d95d1559 C |
248 | isAbuseRejected (abuse: Abuse) { |
249 | return abuse.state.id === AbuseState.REJECTED | |
efc9e845 C |
250 | } |
251 | ||
d95d1559 C |
252 | getVideoUrl (abuse: Abuse) { |
253 | return Video.buildClientUrl(abuse.video.uuid) | |
191764f3 C |
254 | } |
255 | ||
d95d1559 | 256 | getVideoEmbed (abuse: Abuse) { |
1ebddadd RK |
257 | return buildVideoEmbed( |
258 | buildVideoLink({ | |
d95d1559 | 259 | baseUrl: `${environment.embedUrl}/videos/embed/${abuse.video.uuid}`, |
1ebddadd RK |
260 | title: false, |
261 | warningTitle: false, | |
d95d1559 C |
262 | startTime: abuse.startAt, |
263 | stopTime: abuse.endAt | |
1ebddadd RK |
264 | }) |
265 | ) | |
d6af8146 RK |
266 | } |
267 | ||
268 | switchToDefaultAvatar ($event: Event) { | |
269 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | |
270 | } | |
271 | ||
d95d1559 | 272 | async removeAbuse (abuse: Abuse) { |
198d764f | 273 | const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete')) |
efc9e845 C |
274 | if (res === false) return |
275 | ||
d95d1559 | 276 | this.abuseService.removeAbuse(abuse).subscribe( |
efc9e845 | 277 | () => { |
f8b2c1b4 | 278 | this.notifier.success(this.i18n('Abuse deleted.')) |
efc9e845 C |
279 | this.loadData() |
280 | }, | |
281 | ||
f8b2c1b4 | 282 | err => this.notifier.error(err.message) |
efc9e845 C |
283 | ) |
284 | } | |
285 | ||
d95d1559 C |
286 | updateAbuseState (abuse: Abuse, state: AbuseState) { |
287 | this.abuseService.updateAbuse(abuse, { state }) | |
efc9e845 C |
288 | .subscribe( |
289 | () => this.loadData(), | |
290 | ||
f8b2c1b4 | 291 | err => this.notifier.error(err.message) |
efc9e845 | 292 | ) |
efc9e845 C |
293 | } |
294 | ||
d592e0a9 | 295 | protected loadData () { |
d95d1559 | 296 | return this.abuseService.getAbuses({ |
844db39e | 297 | pagination: this.pagination, |
042daa70 | 298 | sort: this.sort, |
844db39e RK |
299 | search: this.search |
300 | }).subscribe( | |
301 | async resultList => { | |
302 | this.totalRecords = resultList.total | |
d95d1559 | 303 | const abuses = [] |
844db39e | 304 | |
25a42e29 | 305 | for (const abuse of resultList.data) { |
844db39e RK |
306 | Object.assign(abuse, { |
307 | reasonHtml: await this.toHtml(abuse.reason), | |
308 | moderationCommentHtml: await this.toHtml(abuse.moderationComment), | |
309 | embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)), | |
310 | reporterAccount: new Account(abuse.reporterAccount) | |
311 | }) | |
25a42e29 RK |
312 | |
313 | if (abuse.video.channel?.ownerAccount) abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount) | |
0db536f1 | 314 | if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt |
25a42e29 | 315 | |
d95d1559 | 316 | abuses.push(abuse as ProcessedAbuse) |
844db39e RK |
317 | } |
318 | ||
d95d1559 | 319 | this.abuses = abuses |
844db39e RK |
320 | }, |
321 | ||
322 | err => this.notifier.error(err.message) | |
323 | ) | |
11ac88de | 324 | } |
41d71344 C |
325 | |
326 | private toHtml (text: string) { | |
327 | return this.markdownRenderer.textMarkdownToHTML(text) | |
328 | } | |
11ac88de | 329 | } |