1 import { mapValues, pickBy } from 'lodash-es'
2 import { buildVideoEmbed, buildVideoLink } 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 { AbuseValidatorsService, 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 { I18n } from '@ngx-translate/i18n-polyfill'
10 import { abusePredefinedReasonsMap, 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 }[] = []
28 private openedModal: NgbModalRef
31 protected formValidatorService: FormValidatorService,
32 private modalService: NgbModal,
33 private abuseValidatorsService: AbuseValidatorsService,
34 private abuseService: AbuseService,
35 private notifier: Notifier,
36 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(
62 baseUrl: this.video.embedUrl,
72 reason: this.abuseValidatorsService.ABUSE_REASON,
73 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
82 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
84 this.embedHtml = this.getVideoEmbed()
88 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
92 this.openedModal.close()
93 this.openedModal = null
97 const reason = this.form.get('reason').value
98 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
99 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
101 this.abuseService.reportVideo({
106 startAt: hasStart && startAt ? startAt : undefined,
107 endAt: hasEnd && endAt ? endAt : undefined
111 this.notifier.success(this.i18n('Video reported.'))
115 err => this.notifier.error(err.message)
120 return !this.video.isLocal