1 import { mapValues, pickBy } from 'lodash-es'
2 import { Component, Input, 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 @Input() account: Account = null
21 @ViewChild('modal', { static: true }) modal: NgbModal
24 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
27 private openedModal: NgbModalRef
30 protected formValidatorService: FormValidatorService,
31 private modalService: NgbModal,
32 private abuseService: AbuseService,
33 private notifier: Notifier
39 return window.location.host
43 if (this.isRemote()) {
44 return this.account.host
51 this.modalTitle = $localize`Report ${this.account.displayName}`
54 reason: ABUSE_REASON_VALIDATOR,
55 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
58 this.predefinedReasons = this.abuseService.getPrefefinedReasons('account')
62 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
66 this.openedModal.close()
67 this.openedModal = null
71 const reason = this.form.get('reason').value
72 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
74 this.abuseService.reportVideo({
82 this.notifier.success($localize`Account reported.`)
86 err => this.notifier.error(err.message)
91 return !this.account.isLocal