]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
fix missing title attribute on <iframe> tag suggested for embedding (#3901)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / video-report.component.ts
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'
14
15 @Component({
16 selector: 'my-video-report',
17 templateUrl: './video-report.component.html',
18 styleUrls: [ './report.component.scss' ]
19 })
20 export class VideoReportComponent extends FormReactive implements OnInit {
21 @Input() video: Video = null
22
23 @ViewChild('modal', { static: true }) modal: NgbModal
24
25 error: string = null
26 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
27 embedHtml: SafeHtml
28
29 private openedModal: NgbModalRef
30
31 constructor (
32 protected formValidatorService: FormValidatorService,
33 private modalService: NgbModal,
34 private abuseService: AbuseService,
35 private notifier: Notifier,
36 private sanitizer: DomSanitizer
37 ) {
38 super()
39 }
40
41 get currentHost () {
42 return window.location.host
43 }
44
45 get originHost () {
46 if (this.isRemote()) {
47 return this.video.account.host
48 }
49
50 return ''
51 }
52
53 get timestamp () {
54 return this.form.get('timestamp').value
55 }
56
57 getVideoEmbed () {
58 return this.sanitizer.bypassSecurityTrustHtml(
59 buildVideoOrPlaylistEmbed(
60 buildVideoLink({
61 baseUrl: this.video.embedUrl,
62 title: false,
63 warningTitle: false
64 }),
65 this.video.name
66 )
67 )
68 }
69
70 ngOnInit () {
71 this.buildForm({
72 reason: ABUSE_REASON_VALIDATOR,
73 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
74 timestamp: {
75 hasStart: null,
76 startAt: null,
77 hasEnd: null,
78 endAt: null
79 }
80 })
81
82 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
83
84 this.embedHtml = this.getVideoEmbed()
85 }
86
87 show () {
88 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
89 }
90
91 hide () {
92 this.openedModal.close()
93 this.openedModal = null
94 }
95
96 report () {
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
100
101 this.abuseService.reportVideo({
102 reason,
103 predefinedReasons,
104 video: {
105 id: this.video.id,
106 startAt: hasStart && startAt ? startAt : undefined,
107 endAt: hasEnd && endAt ? endAt : undefined
108 }
109 }).subscribe(
110 () => {
111 this.notifier.success($localize`Video reported.`)
112 this.hide()
113 },
114
115 err => this.notifier.error(err.message)
116 )
117 }
118
119 isRemote () {
120 return !this.video.isLocal
121 }
122 }