1 import { mapValues, pickBy } from 'lodash-es'
2 import { buildVideoLink, 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 { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
11 import { AbusePredefinedReasonsString } from '@shared/models'
12 import { Video } from '../../shared-main'
13 import { AbuseService } from '../abuse.service'
16 selector: 'my-video-report',
17 templateUrl: './video-report.component.html',
18 styleUrls: [ './report.component.scss' ]
20 export class VideoReportComponent extends FormReactive implements OnInit {
21 @Input() video: Video = null
23 @ViewChild('modal', { static: true }) modal: NgbModal
26 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
29 private openedModal: NgbModalRef
32 protected formValidatorService: FormValidatorService,
33 private modalService: NgbModal,
34 private abuseService: AbuseService,
35 private notifier: Notifier,
36 private sanitizer: DomSanitizer
42 return window.location.host
46 if (this.isRemote()) {
47 return this.video.account.host
54 return this.form.get('timestamp').value
58 return this.sanitizer.bypassSecurityTrustHtml(
59 buildVideoOrPlaylistEmbed(
61 baseUrl: this.video.embedUrl,
71 reason: ABUSE_REASON_VALIDATOR,
72 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
81 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
83 this.embedHtml = this.getVideoEmbed()
87 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
91 this.openedModal.close()
92 this.openedModal = null
96 const reason = this.form.get('reason').value
97 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
98 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
100 this.abuseService.reportVideo({
105 startAt: hasStart && startAt ? startAt : undefined,
106 endAt: hasEnd && endAt ? endAt : undefined
110 this.notifier.success($localize`Video reported.`)
114 err => this.notifier.error(err.message)
119 return !this.video.isLocal