]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
Migrate to $localize
[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'
d95d1559 6import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms'
63347a0f
C
7import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
bd45d503
C
9import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
10import { AbusePredefinedReasonsString } from '@shared/models'
cfde28ba
C
11import { Video } from '../../shared-main'
12import { AbuseService } from '../abuse.service'
4f8c0eb0
C
13
14@Component({
15 selector: 'my-video-report',
5f0805d3 16 templateUrl: './video-report.component.html',
cfde28ba 17 styleUrls: [ './report.component.scss' ]
4f8c0eb0
C
18})
19export class VideoReportComponent extends FormReactive implements OnInit {
be27ef3b 20 @Input() video: Video = null
4f8c0eb0 21
f36da21e 22 @ViewChild('modal', { static: true }) modal: NgbModal
4f8c0eb0 23
df98563e 24 error: string = null
d95d1559 25 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
1ebddadd 26 embedHtml: SafeHtml
4f8c0eb0 27
63347a0f
C
28 private openedModal: NgbModalRef
29
df98563e 30 constructor (
d18d6478 31 protected formValidatorService: FormValidatorService,
63347a0f 32 private modalService: NgbModal,
d95d1559
C
33 private abuseValidatorsService: AbuseValidatorsService,
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
64 })
65 )
66 )
67 }
68
df98563e 69 ngOnInit () {
d18d6478 70 this.buildForm({
d95d1559
C
71 reason: this.abuseValidatorsService.ABUSE_REASON,
72 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
1ebddadd
RK
73 timestamp: {
74 hasStart: null,
75 startAt: null,
76 hasEnd: null,
77 endAt: null
78 }
df98563e 79 })
1ebddadd 80
8ca56654 81 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
1ebddadd
RK
82
83 this.embedHtml = this.getVideoEmbed()
4f8c0eb0
C
84 }
85
df98563e 86 show () {
1ebddadd 87 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
4f8c0eb0
C
88 }
89
df98563e 90 hide () {
63347a0f
C
91 this.openedModal.close()
92 this.openedModal = null
4f8c0eb0
C
93 }
94
df98563e 95 report () {
1ebddadd 96 const reason = this.form.get('reason').value
d95d1559 97 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
1ebddadd 98 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
4f8c0eb0 99
d95d1559 100 this.abuseService.reportVideo({
1ebddadd
RK
101 reason,
102 predefinedReasons,
d95d1559
C
103 video: {
104 id: this.video.id,
105 startAt: hasStart && startAt ? startAt : undefined,
106 endAt: hasEnd && endAt ? endAt : undefined
107 }
1ebddadd
RK
108 }).subscribe(
109 () => {
66357162 110 this.notifier.success($localize`Video reported.`)
1ebddadd
RK
111 this.hide()
112 },
4f8c0eb0 113
1ebddadd
RK
114 err => this.notifier.error(err.message)
115 )
4f8c0eb0 116 }
a1b2f876 117
cfde28ba 118 isRemote () {
a1b2f876
C
119 return !this.video.isLocal
120 }
4f8c0eb0 121}