]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { mapValues, pickBy } from 'lodash-es' |
66357162 | 2 | import { buildVideoLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' |
df98563e | 3 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
67ed6552 | 4 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
f8b2c1b4 | 5 | import { Notifier } from '@app/core' |
7ed1edbb C |
6 | import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators' |
7 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
63347a0f C |
8 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
bd45d503 C |
10 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
11 | import { AbusePredefinedReasonsString } from '@shared/models' | |
cfde28ba C |
12 | import { Video } from '../../shared-main' |
13 | import { 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 | }) |
20 | export 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 | 34 | private abuseService: AbuseService, |
f8b2c1b4 | 35 | private notifier: Notifier, |
66357162 | 36 | private sanitizer: DomSanitizer |
b1d40cff | 37 | ) { |
df98563e | 38 | super() |
4f8c0eb0 C |
39 | } |
40 | ||
a1b2f876 C |
41 | get currentHost () { |
42 | return window.location.host | |
43 | } | |
44 | ||
45 | get originHost () { | |
cfde28ba | 46 | if (this.isRemote()) { |
a1b2f876 C |
47 | return this.video.account.host |
48 | } | |
49 | ||
50 | return '' | |
51 | } | |
52 | ||
1ebddadd RK |
53 | get timestamp () { |
54 | return this.form.get('timestamp').value | |
55 | } | |
56 | ||
57 | getVideoEmbed () { | |
58 | return this.sanitizer.bypassSecurityTrustHtml( | |
951b582f | 59 | buildVideoOrPlaylistEmbed( |
1ebddadd RK |
60 | buildVideoLink({ |
61 | baseUrl: this.video.embedUrl, | |
62 | title: false, | |
63 | warningTitle: false | |
64 | }) | |
65 | ) | |
66 | ) | |
67 | } | |
68 | ||
df98563e | 69 | ngOnInit () { |
d18d6478 | 70 | this.buildForm({ |
7ed1edbb | 71 | reason: ABUSE_REASON_VALIDATOR, |
d95d1559 | 72 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null), |
1ebddadd RK |
73 | timestamp: { |
74 | hasStart: null, | |
75 | startAt: null, | |
76 | hasEnd: null, | |
77 | endAt: null | |
78 | } | |
df98563e | 79 | }) |
1ebddadd | 80 | |
8ca56654 | 81 | this.predefinedReasons = this.abuseService.getPrefefinedReasons('video') |
1ebddadd RK |
82 | |
83 | this.embedHtml = this.getVideoEmbed() | |
4f8c0eb0 C |
84 | } |
85 | ||
df98563e | 86 | show () { |
1ebddadd | 87 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) |
4f8c0eb0 C |
88 | } |
89 | ||
df98563e | 90 | hide () { |
63347a0f C |
91 | this.openedModal.close() |
92 | this.openedModal = null | |
4f8c0eb0 C |
93 | } |
94 | ||
df98563e | 95 | report () { |
1ebddadd | 96 | const reason = this.form.get('reason').value |
d95d1559 | 97 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] |
1ebddadd | 98 | const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value |
4f8c0eb0 | 99 | |
d95d1559 | 100 | this.abuseService.reportVideo({ |
1ebddadd RK |
101 | reason, |
102 | predefinedReasons, | |
d95d1559 C |
103 | video: { |
104 | id: this.video.id, | |
105 | startAt: hasStart && startAt ? startAt : undefined, | |
106 | endAt: hasEnd && endAt ? endAt : undefined | |
107 | } | |
1ebddadd RK |
108 | }).subscribe( |
109 | () => { | |
66357162 | 110 | this.notifier.success($localize`Video reported.`) |
1ebddadd RK |
111 | this.hide() |
112 | }, | |
4f8c0eb0 | 113 | |
1ebddadd RK |
114 | err => this.notifier.error(err.message) |
115 | ) | |
4f8c0eb0 | 116 | } |
a1b2f876 | 117 | |
cfde28ba | 118 | isRemote () { |
a1b2f876 C |
119 | return !this.video.isLocal |
120 | } | |
4f8c0eb0 | 121 | } |