1 import { mapValues, pickBy } from 'lodash-es'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { Notifier } from '@app/core'
4 import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
5 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
6 import { Account } from '@app/shared/shared-main'
7 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
9 import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
10 import { AbusePredefinedReasonsString } from '@shared/models'
11 import { AbuseService } from '../abuse.service'
14 selector: 'my-account-report',
15 templateUrl: './report.component.html',
16 styleUrls: [ './report.component.scss' ]
18 export class AccountReportComponent extends FormReactive implements OnInit {
19 @ViewChild('modal', { static: true }) modal: NgbModal
22 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
24 account: Account = null
26 private openedModal: NgbModalRef
29 protected formValidatorService: FormValidatorService,
30 private modalService: NgbModal,
31 private abuseService: AbuseService,
32 private notifier: Notifier
38 return window.location.host
42 if (this.isRemote()) {
43 return this.account.host
51 reason: ABUSE_REASON_VALIDATOR,
52 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
55 this.predefinedReasons = this.abuseService.getPrefefinedReasons('account')
58 show (account: Account) {
59 this.account = account
61 this.modalTitle = $localize`Report ${this.account.displayName}`
63 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
67 this.openedModal.close()
68 this.openedModal = null
72 const reason = this.form.get('reason').value
73 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
75 this.abuseService.reportVideo({
83 this.notifier.success($localize`Account reported.`)
87 error: err => this.notifier.error(err.message)
92 return !this.account.isLocal