]>
Commit | Line | Data |
---|---|---|
8ca56654 C |
1 | import { mapValues, pickBy } from 'lodash-es' |
2 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | |
8ca56654 C |
3 | import { Notifier } from '@app/core' |
4 | import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
cfde28ba | 5 | import { VideoComment } from '@app/shared/shared-video-comment' |
8ca56654 C |
6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
7 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
9 | import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models' | |
cfde28ba | 10 | import { 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 | }) |
17 | export 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, | |
33 | private notifier: Notifier, | |
34 | private i18n: I18n | |
35 | ) { | |
36 | super() | |
37 | } | |
38 | ||
39 | get currentHost () { | |
40 | return window.location.host | |
41 | } | |
42 | ||
43 | get originHost () { | |
cfde28ba | 44 | if (this.isRemote()) { |
8ca56654 C |
45 | return this.comment.account.host |
46 | } | |
47 | ||
48 | return '' | |
49 | } | |
50 | ||
51 | ngOnInit () { | |
cfde28ba C |
52 | this.modalTitle = this.i18n('Report comment') |
53 | ||
8ca56654 C |
54 | this.buildForm({ |
55 | reason: this.abuseValidatorsService.ABUSE_REASON, | |
56 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null) | |
57 | }) | |
58 | ||
59 | this.predefinedReasons = this.abuseService.getPrefefinedReasons('comment') | |
60 | } | |
61 | ||
62 | show () { | |
63 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) | |
64 | } | |
65 | ||
66 | hide () { | |
67 | this.openedModal.close() | |
68 | this.openedModal = null | |
69 | } | |
70 | ||
71 | report () { | |
72 | const reason = this.form.get('reason').value | |
73 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] | |
74 | ||
75 | this.abuseService.reportVideo({ | |
76 | reason, | |
77 | predefinedReasons, | |
78 | comment: { | |
79 | id: this.comment.id | |
80 | } | |
81 | }).subscribe( | |
82 | () => { | |
83 | this.notifier.success(this.i18n('Comment reported.')) | |
84 | this.hide() | |
85 | }, | |
86 | ||
87 | err => this.notifier.error(err.message) | |
88 | ) | |
89 | } | |
90 | ||
cfde28ba | 91 | isRemote () { |
8ca56654 C |
92 | return !this.comment.isLocal |
93 | } | |
94 | } |