]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { mapValues, pickBy } from 'lodash-es' |
9162fdd3 | 2 | import { buildVideoOrPlaylistEmbed, decorateVideoLink } 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( |
9162fdd3 C |
60 | decorateVideoLink({ |
61 | url: this.video.embedUrl, | |
1ebddadd RK |
62 | title: false, |
63 | warningTitle: false | |
4097c6d6 | 64 | }), |
9162fdd3 | 65 | |
4097c6d6 | 66 | this.video.name |
1ebddadd RK |
67 | ) |
68 | ) | |
69 | } | |
70 | ||
df98563e | 71 | ngOnInit () { |
d18d6478 | 72 | this.buildForm({ |
7ed1edbb | 73 | reason: ABUSE_REASON_VALIDATOR, |
d95d1559 | 74 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null), |
1ebddadd RK |
75 | timestamp: { |
76 | hasStart: null, | |
77 | startAt: null, | |
78 | hasEnd: null, | |
79 | endAt: null | |
80 | } | |
df98563e | 81 | }) |
1ebddadd | 82 | |
8ca56654 | 83 | this.predefinedReasons = this.abuseService.getPrefefinedReasons('video') |
1ebddadd RK |
84 | |
85 | this.embedHtml = this.getVideoEmbed() | |
4f8c0eb0 C |
86 | } |
87 | ||
df98563e | 88 | show () { |
1ebddadd | 89 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) |
4f8c0eb0 C |
90 | } |
91 | ||
df98563e | 92 | hide () { |
63347a0f C |
93 | this.openedModal.close() |
94 | this.openedModal = null | |
4f8c0eb0 C |
95 | } |
96 | ||
df98563e | 97 | report () { |
1ebddadd | 98 | const reason = this.form.get('reason').value |
d95d1559 | 99 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] |
1ebddadd | 100 | const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value |
4f8c0eb0 | 101 | |
d95d1559 | 102 | this.abuseService.reportVideo({ |
1ebddadd RK |
103 | reason, |
104 | predefinedReasons, | |
d95d1559 C |
105 | video: { |
106 | id: this.video.id, | |
107 | startAt: hasStart && startAt ? startAt : undefined, | |
108 | endAt: hasEnd && endAt ? endAt : undefined | |
109 | } | |
1ebddadd RK |
110 | }).subscribe( |
111 | () => { | |
66357162 | 112 | this.notifier.success($localize`Video reported.`) |
1ebddadd RK |
113 | this.hide() |
114 | }, | |
4f8c0eb0 | 115 | |
1ebddadd RK |
116 | err => this.notifier.error(err.message) |
117 | ) | |
4f8c0eb0 | 118 | } |
a1b2f876 | 119 | |
cfde28ba | 120 | isRemote () { |
a1b2f876 C |
121 | return !this.video.isLocal |
122 | } | |
4f8c0eb0 | 123 | } |