1 import { mapValues, pickBy } from 'lodash-es'
2 import { Component, Input, OnInit, ViewChild } from '@angular/core'
3 import { DomSanitizer } from '@angular/platform-browser'
4 import { Notifier } from '@app/core'
5 import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
6 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
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 { Video } from '../../shared-main'
12 import { AbuseService } from '../abuse.service'
15 selector: 'my-video-report',
16 templateUrl: './video-report.component.html',
17 styleUrls: [ './report.component.scss' ]
19 export class VideoReportComponent extends FormReactive implements OnInit {
20 @Input() video: Video = null
22 @ViewChild('modal', { static: true }) modal: NgbModal
25 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,
34 private sanitizer: DomSanitizer
40 return window.location.host
44 if (this.isRemote()) {
45 return this.video.account.host
52 return this.form.get('timestamp').value
57 reason: ABUSE_REASON_VALIDATOR,
58 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
67 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
71 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
75 this.openedModal.close()
76 this.openedModal = null
80 const reason = this.form.get('reason').value
81 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
82 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
84 this.abuseService.reportVideo({
89 startAt: hasStart && startAt ? startAt : undefined,
90 endAt: hasEnd && endAt ? endAt : undefined
94 this.notifier.success($localize`Video reported.`)
98 error: err => this.notifier.error(err.message)
103 return !this.video.isLocal