]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/report-modals/account-report.component.ts
Merge branch 'release/2.3.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / account-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 { Account } from '@app/shared/shared-main'
8ca56654
C
6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'
cfde28ba 10import { AbuseService } from '../abuse.service'
8ca56654
C
11
12@Component({
cfde28ba
C
13 selector: 'my-account-report',
14 templateUrl: './report.component.html',
15 styleUrls: [ './report.component.scss' ]
8ca56654 16})
cfde28ba
C
17export class AccountReportComponent extends FormReactive implements OnInit {
18 @Input() account: Account = null
8ca56654
C
19
20 @ViewChild('modal', { static: true }) modal: NgbModal
21
22 error: string = null
23 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
cfde28ba 24 modalTitle: 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
C
44 if (this.isRemote()) {
45 return this.account.host
8ca56654
C
46 }
47
48 return ''
49 }
50
51 ngOnInit () {
cfde28ba
C
52 this.modalTitle = this.i18n('Report {{displayName}}', { displayName: this.account.displayName })
53
8ca56654
C
54 this.buildForm({
55 reason: this.abuseValidatorsService.ABUSE_REASON,
56 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
57 })
58
cfde28ba 59 this.predefinedReasons = this.abuseService.getPrefefinedReasons('account')
8ca56654
C
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,
cfde28ba
C
78 account: {
79 id: this.account.id
8ca56654
C
80 }
81 }).subscribe(
82 () => {
cfde28ba 83 this.notifier.success(this.i18n('Account reported.'))
8ca56654
C
84 this.hide()
85 },
86
87 err => this.notifier.error(err.message)
88 )
89 }
90
cfde28ba
C
91 isRemote () {
92 return !this.account.isLocal
8ca56654
C
93 }
94}