]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/report-modals/comment-report.component.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / comment-report.component.ts
CommitLineData
8ca56654
C
1import { mapValues, pickBy } from 'lodash-es'
2import { Component, Input, OnInit, ViewChild } from '@angular/core'
8ca56654
C
3import { Notifier } from '@app/core'
4import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms'
cfde28ba 5import { VideoComment } from '@app/shared/shared-video-comment'
8ca56654
C
6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
bd45d503
C
8import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
9import { AbusePredefinedReasonsString } from '@shared/models'
cfde28ba 10import { AbuseService } from '../abuse.service'
8ca56654
C
11
12@Component({
13 selector: 'my-comment-report',
cfde28ba
C
14 templateUrl: './report.component.html',
15 styleUrls: [ './report.component.scss' ]
8ca56654
C
16})
17export class CommentReportComponent extends FormReactive implements OnInit {
18 @Input() comment: VideoComment = null
19
20 @ViewChild('modal', { static: true }) modal: NgbModal
21
cfde28ba 22 modalTitle: string
8ca56654
C
23 error: string = null
24 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
8ca56654
C
25
26 private openedModal: NgbModalRef
27
28 constructor (
29 protected formValidatorService: FormValidatorService,
30 private modalService: NgbModal,
31 private abuseValidatorsService: AbuseValidatorsService,
32 private abuseService: AbuseService,
66357162 33 private notifier: Notifier
8ca56654
C
34 ) {
35 super()
36 }
37
38 get currentHost () {
39 return window.location.host
40 }
41
42 get originHost () {
cfde28ba 43 if (this.isRemote()) {
8ca56654
C
44 return this.comment.account.host
45 }
46
47 return ''
48 }
49
50 ngOnInit () {
66357162 51 this.modalTitle = $localize`Report comment`
cfde28ba 52
8ca56654
C
53 this.buildForm({
54 reason: this.abuseValidatorsService.ABUSE_REASON,
55 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
56 })
57
58 this.predefinedReasons = this.abuseService.getPrefefinedReasons('comment')
59 }
60
61 show () {
62 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
63 }
64
65 hide () {
66 this.openedModal.close()
67 this.openedModal = null
68 }
69
70 report () {
71 const reason = this.form.get('reason').value
72 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
73
74 this.abuseService.reportVideo({
75 reason,
76 predefinedReasons,
77 comment: {
78 id: this.comment.id
79 }
80 }).subscribe(
81 () => {
66357162 82 this.notifier.success($localize`Comment reported.`)
8ca56654
C
83 this.hide()
84 },
85
86 err => this.notifier.error(err.message)
87 )
88 }
89
cfde28ba 90 isRemote () {
8ca56654
C
91 return !this.comment.isLocal
92 }
93}