]>
Commit | Line | Data |
---|---|---|
8ca56654 C |
1 | import { mapValues, pickBy } from 'lodash-es' |
2 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | |
8ca56654 | 3 | import { Notifier } from '@app/core' |
7ed1edbb C |
4 | import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators' |
5 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
cfde28ba | 6 | import { Account } from '@app/shared/shared-main' |
8ca56654 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 | 11 | import { AbuseService } from '../abuse.service' |
8ca56654 C |
12 | |
13 | @Component({ | |
cfde28ba C |
14 | selector: 'my-account-report', |
15 | templateUrl: './report.component.html', | |
16 | styleUrls: [ './report.component.scss' ] | |
8ca56654 | 17 | }) |
cfde28ba C |
18 | export class AccountReportComponent extends FormReactive implements OnInit { |
19 | @Input() account: Account = null | |
8ca56654 C |
20 | |
21 | @ViewChild('modal', { static: true }) modal: NgbModal | |
22 | ||
23 | error: string = null | |
24 | predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [] | |
cfde28ba | 25 | modalTitle: string |
8ca56654 C |
26 | |
27 | private openedModal: NgbModalRef | |
28 | ||
29 | constructor ( | |
30 | protected formValidatorService: FormValidatorService, | |
31 | private modalService: NgbModal, | |
8ca56654 | 32 | private abuseService: AbuseService, |
66357162 | 33 | private notifier: Notifier |
8ca56654 C |
34 | ) { |
35 | super() | |
36 | } | |
37 | ||
38 | get currentHost () { | |
39 | return window.location.host | |
40 | } | |
41 | ||
42 | get originHost () { | |
cfde28ba C |
43 | if (this.isRemote()) { |
44 | return this.account.host | |
8ca56654 C |
45 | } |
46 | ||
47 | return '' | |
48 | } | |
49 | ||
50 | ngOnInit () { | |
66357162 | 51 | this.modalTitle = $localize`Report ${this.account.displayName}` |
cfde28ba | 52 | |
8ca56654 | 53 | this.buildForm({ |
7ed1edbb | 54 | reason: ABUSE_REASON_VALIDATOR, |
8ca56654 C |
55 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null) |
56 | }) | |
57 | ||
cfde28ba | 58 | this.predefinedReasons = this.abuseService.getPrefefinedReasons('account') |
8ca56654 C |
59 | } |
60 | ||
61 | show () { | |
62 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) | |
63 | } | |
64 | ||
65 | hide () { | |
66 | this.openedModal.close() | |
67 | this.openedModal = null | |
68 | } | |
69 | ||
70 | report () { | |
71 | const reason = this.form.get('reason').value | |
72 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] | |
73 | ||
74 | this.abuseService.reportVideo({ | |
75 | reason, | |
76 | predefinedReasons, | |
cfde28ba C |
77 | account: { |
78 | id: this.account.id | |
8ca56654 C |
79 | } |
80 | }).subscribe( | |
81 | () => { | |
66357162 | 82 | this.notifier.success($localize`Account reported.`) |
8ca56654 C |
83 | this.hide() |
84 | }, | |
85 | ||
86 | err => this.notifier.error(err.message) | |
87 | ) | |
88 | } | |
89 | ||
cfde28ba C |
90 | isRemote () { |
91 | return !this.account.isLocal | |
8ca56654 C |
92 | } |
93 | } |