1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import { mapValues, pickBy } from 'lodash-es'
import { Component, Input, OnInit, ViewChild } from '@angular/core'
import { DomSanitizer } from '@angular/platform-browser'
import { Notifier } from '@app/core'
import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbusePredefinedReasonsString } from '@shared/models'
import { Video } from '../../shared-main'
import { AbuseService } from '../abuse.service'
@Component({
selector: 'my-video-report',
templateUrl: './video-report.component.html',
styleUrls: [ './report.component.scss' ]
})
export class VideoReportComponent extends FormReactive implements OnInit {
@Input() video: Video = null
@ViewChild('modal', { static: true }) modal: NgbModal
error: string = null
predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
private openedModal: NgbModalRef
constructor (
protected formReactiveService: FormReactiveService,
private modalService: NgbModal,
private abuseService: AbuseService,
private notifier: Notifier,
private sanitizer: DomSanitizer
) {
super()
}
get currentHost () {
return window.location.host
}
get originHost () {
if (this.isRemote()) {
return this.video.account.host
}
return ''
}
get timestamp () {
return this.form.get('timestamp').value
}
ngOnInit () {
this.buildForm({
reason: ABUSE_REASON_VALIDATOR,
predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
timestamp: {
hasStart: null,
startAt: null,
hasEnd: null,
endAt: null
}
})
this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
}
show () {
this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
}
hide () {
this.openedModal.close()
this.openedModal = null
}
report () {
const reason = this.form.get('reason').value
const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
this.abuseService.reportVideo({
reason,
predefinedReasons,
video: {
id: this.video.id,
startAt: hasStart && startAt ? startAt : undefined,
endAt: hasEnd && endAt ? endAt : undefined
}
}).subscribe({
next: () => {
this.notifier.success($localize`Video reported.`)
this.hide()
},
error: err => this.notifier.error(err.message)
})
}
isRemote () {
return !this.video.isLocal
}
}
|