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