1 import { mapValues, pickBy } from 'lodash-es'
2 import { Component, Input, OnInit, ViewChild } from '@angular/core'
3 import { Notifier } from '@app/core'
4 import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { Account } from '@app/shared/shared-main'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
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 abuseValidatorsService: AbuseValidatorsService,
33 private abuseService: AbuseService,
34 private notifier: Notifier,
41 return window.location.host
45 if (this.isRemote()) {
46 return this.account.host
53 this.modalTitle = this.i18n('Report {{displayName}}', { displayName: this.account.displayName })
56 reason: this.abuseValidatorsService.ABUSE_REASON,
57 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
60 this.predefinedReasons = this.abuseService.getPrefefinedReasons('account')
64 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
68 this.openedModal.close()
69 this.openedModal = null
73 const reason = this.form.get('reason').value
74 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
76 this.abuseService.reportVideo({
84 this.notifier.success(this.i18n('Account reported.'))
88 err => this.notifier.error(err.message)
93 return !this.account.isLocal