]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / video-report.component.ts
CommitLineData
67ed6552
C
1import { mapValues, pickBy } from 'lodash-es'
2import { buildVideoEmbed, buildVideoLink } 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'
67ed6552 9import { I18n } from '@ngx-translate/i18n-polyfill'
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
C
34 private abuseValidatorsService: AbuseValidatorsService,
35 private abuseService: AbuseService,
f8b2c1b4 36 private notifier: Notifier,
1ebddadd 37 private sanitizer: DomSanitizer,
b1d40cff
C
38 private i18n: I18n
39 ) {
df98563e 40 super()
4f8c0eb0
C
41 }
42
a1b2f876
C
43 get currentHost () {
44 return window.location.host
45 }
46
47 get originHost () {
cfde28ba 48 if (this.isRemote()) {
a1b2f876
C
49 return this.video.account.host
50 }
51
52 return ''
53 }
54
1ebddadd
RK
55 get timestamp () {
56 return this.form.get('timestamp').value
57 }
58
59 getVideoEmbed () {
60 return this.sanitizer.bypassSecurityTrustHtml(
61 buildVideoEmbed(
62 buildVideoLink({
63 baseUrl: this.video.embedUrl,
64 title: false,
65 warningTitle: false
66 })
67 )
68 )
69 }
70
df98563e 71 ngOnInit () {
d18d6478 72 this.buildForm({
d95d1559
C
73 reason: this.abuseValidatorsService.ABUSE_REASON,
74 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
1ebddadd
RK
75 timestamp: {
76 hasStart: null,
77 startAt: null,
78 hasEnd: null,
79 endAt: null
80 }
df98563e 81 })
1ebddadd 82
8ca56654 83 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
1ebddadd
RK
84
85 this.embedHtml = this.getVideoEmbed()
4f8c0eb0
C
86 }
87
df98563e 88 show () {
1ebddadd 89 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
4f8c0eb0
C
90 }
91
df98563e 92 hide () {
63347a0f
C
93 this.openedModal.close()
94 this.openedModal = null
4f8c0eb0
C
95 }
96
df98563e 97 report () {
1ebddadd 98 const reason = this.form.get('reason').value
d95d1559 99 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
1ebddadd 100 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
4f8c0eb0 101
d95d1559 102 this.abuseService.reportVideo({
1ebddadd
RK
103 reason,
104 predefinedReasons,
d95d1559
C
105 video: {
106 id: this.video.id,
107 startAt: hasStart && startAt ? startAt : undefined,
108 endAt: hasEnd && endAt ? endAt : undefined
109 }
1ebddadd
RK
110 }).subscribe(
111 () => {
112 this.notifier.success(this.i18n('Video reported.'))
113 this.hide()
114 },
4f8c0eb0 115
1ebddadd
RK
116 err => this.notifier.error(err.message)
117 )
4f8c0eb0 118 }
a1b2f876 119
cfde28ba 120 isRemote () {
a1b2f876
C
121 return !this.video.isLocal
122 }
4f8c0eb0 123}