]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
67ed6552 1import { mapValues, pickBy } from 'lodash-es'
66357162 2import { buildVideoLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils'
df98563e 3import { Component, Input, OnInit, ViewChild } from '@angular/core'
67ed6552 4import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
f8b2c1b4 5import { Notifier } from '@app/core'
7ed1edbb
C
6import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
7import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
63347a0f
C
8import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
9import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
bd45d503
C
10import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
11import { AbusePredefinedReasonsString } from '@shared/models'
cfde28ba
C
12import { Video } from '../../shared-main'
13import { AbuseService } from '../abuse.service'
4f8c0eb0
C
14
15@Component({
16 selector: 'my-video-report',
5f0805d3 17 templateUrl: './video-report.component.html',
cfde28ba 18 styleUrls: [ './report.component.scss' ]
4f8c0eb0
C
19})
20export class VideoReportComponent extends FormReactive implements OnInit {
be27ef3b 21 @Input() video: Video = null
4f8c0eb0 22
f36da21e 23 @ViewChild('modal', { static: true }) modal: NgbModal
4f8c0eb0 24
df98563e 25 error: string = null
d95d1559 26 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
1ebddadd 27 embedHtml: SafeHtml
4f8c0eb0 28
63347a0f
C
29 private openedModal: NgbModalRef
30
df98563e 31 constructor (
d18d6478 32 protected formValidatorService: FormValidatorService,
63347a0f 33 private modalService: NgbModal,
d95d1559 34 private abuseService: AbuseService,
f8b2c1b4 35 private notifier: Notifier,
66357162 36 private sanitizer: DomSanitizer
b1d40cff 37 ) {
df98563e 38 super()
4f8c0eb0
C
39 }
40
a1b2f876
C
41 get currentHost () {
42 return window.location.host
43 }
44
45 get originHost () {
cfde28ba 46 if (this.isRemote()) {
a1b2f876
C
47 return this.video.account.host
48 }
49
50 return ''
51 }
52
1ebddadd
RK
53 get timestamp () {
54 return this.form.get('timestamp').value
55 }
56
57 getVideoEmbed () {
58 return this.sanitizer.bypassSecurityTrustHtml(
951b582f 59 buildVideoOrPlaylistEmbed(
1ebddadd
RK
60 buildVideoLink({
61 baseUrl: this.video.embedUrl,
62 title: false,
63 warningTitle: false
4097c6d6
TP
64 }),
65 this.video.name
1ebddadd
RK
66 )
67 )
68 }
69
df98563e 70 ngOnInit () {
d18d6478 71 this.buildForm({
7ed1edbb 72 reason: ABUSE_REASON_VALIDATOR,
d95d1559 73 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
1ebddadd
RK
74 timestamp: {
75 hasStart: null,
76 startAt: null,
77 hasEnd: null,
78 endAt: null
79 }
df98563e 80 })
1ebddadd 81
8ca56654 82 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
1ebddadd
RK
83
84 this.embedHtml = this.getVideoEmbed()
4f8c0eb0
C
85 }
86
df98563e 87 show () {
1ebddadd 88 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
4f8c0eb0
C
89 }
90
df98563e 91 hide () {
63347a0f
C
92 this.openedModal.close()
93 this.openedModal = null
4f8c0eb0
C
94 }
95
df98563e 96 report () {
1ebddadd 97 const reason = this.form.get('reason').value
d95d1559 98 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
1ebddadd 99 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
4f8c0eb0 100
d95d1559 101 this.abuseService.reportVideo({
1ebddadd
RK
102 reason,
103 predefinedReasons,
d95d1559
C
104 video: {
105 id: this.video.id,
106 startAt: hasStart && startAt ? startAt : undefined,
107 endAt: hasEnd && endAt ? endAt : undefined
108 }
1ebddadd
RK
109 }).subscribe(
110 () => {
66357162 111 this.notifier.success($localize`Video reported.`)
1ebddadd
RK
112 this.hide()
113 },
4f8c0eb0 114
1ebddadd
RK
115 err => this.notifier.error(err.message)
116 )
4f8c0eb0 117 }
a1b2f876 118
cfde28ba 119 isRemote () {
a1b2f876
C
120 return !this.video.isLocal
121 }
4f8c0eb0 122}