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