1 import { mapValues, pickBy } from 'lodash-es'
2 import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils'
3 import { Component, Input, OnInit, ViewChild } from '@angular/core'
4 import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
5 import { Notifier } from '@app/core'
6 import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
7 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
8 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
9 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
10 import { decorateVideoLink } from '@shared/core-utils'
11 import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
12 import { AbusePredefinedReasonsString } from '@shared/models'
13 import { Video } from '../../shared-main'
14 import { AbuseService } from '../abuse.service'
17 selector: 'my-video-report',
18 templateUrl: './video-report.component.html',
19 styleUrls: [ './report.component.scss' ]
21 export class VideoReportComponent extends FormReactive implements OnInit {
22 @Input() video: Video = null
24 @ViewChild('modal', { static: true }) modal: NgbModal
27 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
30 private openedModal: NgbModalRef
33 protected formValidatorService: FormValidatorService,
34 private modalService: NgbModal,
35 private abuseService: AbuseService,
36 private notifier: Notifier,
37 private sanitizer: DomSanitizer
43 return window.location.host
47 if (this.isRemote()) {
48 return this.video.account.host
55 return this.form.get('timestamp').value
59 return this.sanitizer.bypassSecurityTrustHtml(
60 buildVideoOrPlaylistEmbed(
62 url: this.video.embedUrl,
74 reason: ABUSE_REASON_VALIDATOR,
75 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
84 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
86 this.embedHtml = this.getVideoEmbed()
90 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
94 this.openedModal.close()
95 this.openedModal = null
99 const reason = this.form.get('reason').value
100 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
101 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
103 this.abuseService.reportVideo({
108 startAt: hasStart && startAt ? startAt : undefined,
109 endAt: hasEnd && endAt ? endAt : undefined
113 this.notifier.success($localize`Video reported.`)
117 err => this.notifier.error(err.message)
122 return !this.video.isLocal