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 { VideoComment } from '@app/shared/shared-video-comment'
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, AbusePredefinedReasonsString } from '@shared/models'
10 import { AbuseService } from '../abuse.service'
13 selector: 'my-comment-report',
14 templateUrl: './report.component.html',
15 styleUrls: [ './report.component.scss' ]
17 export class CommentReportComponent extends FormReactive implements OnInit {
18 @Input() comment: VideoComment = null
20 @ViewChild('modal', { static: true }) modal: NgbModal
24 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
26 private openedModal: NgbModalRef
29 protected formValidatorService: FormValidatorService,
30 private modalService: NgbModal,
31 private abuseValidatorsService: AbuseValidatorsService,
32 private abuseService: AbuseService,
33 private notifier: Notifier,
40 return window.location.host
44 if (this.isRemote()) {
45 return this.comment.account.host
52 this.modalTitle = this.i18n('Report comment')
55 reason: this.abuseValidatorsService.ABUSE_REASON,
56 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
59 this.predefinedReasons = this.abuseService.getPrefefinedReasons('comment')
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(this.i18n('Comment reported.'))
87 err => this.notifier.error(err.message)
92 return !this.comment.isLocal