]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { mapValues, pickBy } from 'lodash-es' |
df98563e | 2 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
33f6dce1 | 3 | import { DomSanitizer } from '@angular/platform-browser' |
f8b2c1b4 | 4 | import { Notifier } from '@app/core' |
7ed1edbb | 5 | import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators' |
5c5bcea2 | 6 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' |
63347a0f C |
7 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
8 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
bd45d503 C |
9 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
10 | import { AbusePredefinedReasonsString } from '@shared/models' | |
cfde28ba C |
11 | import { Video } from '../../shared-main' |
12 | import { AbuseService } from '../abuse.service' | |
4f8c0eb0 C |
13 | |
14 | @Component({ | |
15 | selector: 'my-video-report', | |
5f0805d3 | 16 | templateUrl: './video-report.component.html', |
cfde28ba | 17 | styleUrls: [ './report.component.scss' ] |
4f8c0eb0 C |
18 | }) |
19 | export class VideoReportComponent extends FormReactive implements OnInit { | |
be27ef3b | 20 | @Input() video: Video = null |
4f8c0eb0 | 21 | |
f36da21e | 22 | @ViewChild('modal', { static: true }) modal: NgbModal |
4f8c0eb0 | 23 | |
df98563e | 24 | error: string = null |
d95d1559 | 25 | predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [] |
4f8c0eb0 | 26 | |
63347a0f C |
27 | private openedModal: NgbModalRef |
28 | ||
df98563e | 29 | constructor ( |
5c5bcea2 | 30 | protected formReactiveService: FormReactiveService, |
63347a0f | 31 | private modalService: NgbModal, |
d95d1559 | 32 | private abuseService: AbuseService, |
f8b2c1b4 | 33 | private notifier: Notifier, |
66357162 | 34 | private sanitizer: DomSanitizer |
b1d40cff | 35 | ) { |
df98563e | 36 | super() |
4f8c0eb0 C |
37 | } |
38 | ||
a1b2f876 C |
39 | get currentHost () { |
40 | return window.location.host | |
41 | } | |
42 | ||
43 | get originHost () { | |
cfde28ba | 44 | if (this.isRemote()) { |
a1b2f876 C |
45 | return this.video.account.host |
46 | } | |
47 | ||
48 | return '' | |
49 | } | |
50 | ||
1ebddadd RK |
51 | get timestamp () { |
52 | return this.form.get('timestamp').value | |
53 | } | |
54 | ||
df98563e | 55 | ngOnInit () { |
d18d6478 | 56 | this.buildForm({ |
7ed1edbb | 57 | reason: ABUSE_REASON_VALIDATOR, |
d95d1559 | 58 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null), |
1ebddadd RK |
59 | timestamp: { |
60 | hasStart: null, | |
61 | startAt: null, | |
62 | hasEnd: null, | |
63 | endAt: null | |
64 | } | |
df98563e | 65 | }) |
1ebddadd | 66 | |
8ca56654 | 67 | this.predefinedReasons = this.abuseService.getPrefefinedReasons('video') |
4f8c0eb0 C |
68 | } |
69 | ||
df98563e | 70 | show () { |
1ebddadd | 71 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) |
4f8c0eb0 C |
72 | } |
73 | ||
df98563e | 74 | hide () { |
63347a0f C |
75 | this.openedModal.close() |
76 | this.openedModal = null | |
4f8c0eb0 C |
77 | } |
78 | ||
df98563e | 79 | report () { |
1ebddadd | 80 | const reason = this.form.get('reason').value |
d95d1559 | 81 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] |
1ebddadd | 82 | const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value |
4f8c0eb0 | 83 | |
d95d1559 | 84 | this.abuseService.reportVideo({ |
1ebddadd RK |
85 | reason, |
86 | predefinedReasons, | |
d95d1559 C |
87 | video: { |
88 | id: this.video.id, | |
89 | startAt: hasStart && startAt ? startAt : undefined, | |
90 | endAt: hasEnd && endAt ? endAt : undefined | |
91 | } | |
1378c0d3 C |
92 | }).subscribe({ |
93 | next: () => { | |
66357162 | 94 | this.notifier.success($localize`Video reported.`) |
1ebddadd RK |
95 | this.hide() |
96 | }, | |
4f8c0eb0 | 97 | |
1378c0d3 C |
98 | error: err => this.notifier.error(err.message) |
99 | }) | |
4f8c0eb0 | 100 | } |
a1b2f876 | 101 | |
cfde28ba | 102 | isRemote () { |
a1b2f876 C |
103 | return !this.video.isLocal |
104 | } | |
4f8c0eb0 | 105 | } |