]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { mapValues, pickBy } from 'lodash-es' |
2 | import { buildVideoEmbed, buildVideoLink } 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' |
d95d1559 | 6 | import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms' |
63347a0f C |
7 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
8 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
67ed6552 | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d95d1559 | 10 | import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models' |
67ed6552 | 11 | import { Video } from '../shared-main' |
d95d1559 | 12 | import { AbuseService } from './abuse.service' |
4f8c0eb0 C |
13 | |
14 | @Component({ | |
15 | selector: 'my-video-report', | |
5f0805d3 C |
16 | templateUrl: './video-report.component.html', |
17 | styleUrls: [ './video-report.component.scss' ] | |
4f8c0eb0 C |
18 | }) |
19 | export class VideoReportComponent extends FormReactive implements OnInit { | |
be27ef3b | 20 | @Input() video: Video = null |
4f8c0eb0 | 21 | |
f36da21e | 22 | @ViewChild('modal', { static: true }) modal: NgbModal |
4f8c0eb0 | 23 | |
df98563e | 24 | error: string = null |
d95d1559 | 25 | predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [] |
1ebddadd | 26 | embedHtml: SafeHtml |
4f8c0eb0 | 27 | |
63347a0f C |
28 | private openedModal: NgbModalRef |
29 | ||
df98563e | 30 | constructor ( |
d18d6478 | 31 | protected formValidatorService: FormValidatorService, |
63347a0f | 32 | private modalService: NgbModal, |
d95d1559 C |
33 | private abuseValidatorsService: AbuseValidatorsService, |
34 | private abuseService: AbuseService, | |
f8b2c1b4 | 35 | private notifier: Notifier, |
1ebddadd | 36 | private sanitizer: DomSanitizer, |
b1d40cff C |
37 | private i18n: I18n |
38 | ) { | |
df98563e | 39 | super() |
4f8c0eb0 C |
40 | } |
41 | ||
a1b2f876 C |
42 | get currentHost () { |
43 | return window.location.host | |
44 | } | |
45 | ||
46 | get originHost () { | |
47 | if (this.isRemoteVideo()) { | |
48 | return this.video.account.host | |
49 | } | |
50 | ||
51 | return '' | |
52 | } | |
53 | ||
1ebddadd RK |
54 | get timestamp () { |
55 | return this.form.get('timestamp').value | |
56 | } | |
57 | ||
58 | getVideoEmbed () { | |
59 | return this.sanitizer.bypassSecurityTrustHtml( | |
60 | buildVideoEmbed( | |
61 | buildVideoLink({ | |
62 | baseUrl: this.video.embedUrl, | |
63 | title: false, | |
64 | warningTitle: false | |
65 | }) | |
66 | ) | |
67 | ) | |
68 | } | |
69 | ||
df98563e | 70 | ngOnInit () { |
d18d6478 | 71 | this.buildForm({ |
d95d1559 C |
72 | reason: this.abuseValidatorsService.ABUSE_REASON, |
73 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null), | |
1ebddadd RK |
74 | timestamp: { |
75 | hasStart: null, | |
76 | startAt: null, | |
77 | hasEnd: null, | |
78 | endAt: null | |
79 | } | |
df98563e | 80 | }) |
1ebddadd RK |
81 | |
82 | this.predefinedReasons = [ | |
83 | { | |
84 | id: 'violentOrRepulsive', | |
85 | label: this.i18n('Violent or repulsive'), | |
86 | help: this.i18n('Contains offensive, violent, or coarse language or iconography.') | |
87 | }, | |
88 | { | |
89 | id: 'hatefulOrAbusive', | |
90 | label: this.i18n('Hateful or abusive'), | |
91 | help: this.i18n('Contains abusive, racist or sexist language or iconography.') | |
92 | }, | |
93 | { | |
94 | id: 'spamOrMisleading', | |
95 | label: this.i18n('Spam, ad or false news'), | |
96 | help: this.i18n('Contains marketing, spam, purposefully deceitful news, or otherwise misleading thumbnail/text/tags. Please provide reputable sources to report hoaxes.') | |
97 | }, | |
98 | { | |
99 | id: 'privacy', | |
100 | label: this.i18n('Privacy breach or doxxing'), | |
101 | help: this.i18n('Contains personal information that could be used to track, identify, contact or impersonate someone (e.g. name, address, phone number, email, or credit card details).') | |
102 | }, | |
103 | { | |
104 | id: 'rights', | |
105 | label: this.i18n('Intellectual property violation'), | |
106 | help: this.i18n('Infringes my intellectual property or copyright, wrt. the regional rules with which the server must comply.') | |
107 | }, | |
108 | { | |
109 | id: 'serverRules', | |
110 | label: this.i18n('Breaks server rules'), | |
111 | description: this.i18n('Anything not included in the above that breaks the terms of service, code of conduct, or general rules in place on the server.') | |
112 | }, | |
113 | { | |
114 | id: 'thumbnails', | |
115 | label: this.i18n('Thumbnails'), | |
116 | help: this.i18n('The above can only be seen in thumbnails.') | |
117 | }, | |
118 | { | |
119 | id: 'captions', | |
120 | label: this.i18n('Captions'), | |
121 | help: this.i18n('The above can only be seen in captions (please describe which).') | |
122 | } | |
123 | ] | |
124 | ||
125 | this.embedHtml = this.getVideoEmbed() | |
4f8c0eb0 C |
126 | } |
127 | ||
df98563e | 128 | show () { |
1ebddadd | 129 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) |
4f8c0eb0 C |
130 | } |
131 | ||
df98563e | 132 | hide () { |
63347a0f C |
133 | this.openedModal.close() |
134 | this.openedModal = null | |
4f8c0eb0 C |
135 | } |
136 | ||
df98563e | 137 | report () { |
1ebddadd | 138 | const reason = this.form.get('reason').value |
d95d1559 | 139 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] |
1ebddadd | 140 | const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value |
4f8c0eb0 | 141 | |
d95d1559 C |
142 | this.abuseService.reportVideo({ |
143 | accountId: this.video.account.id, | |
1ebddadd RK |
144 | reason, |
145 | predefinedReasons, | |
d95d1559 C |
146 | video: { |
147 | id: this.video.id, | |
148 | startAt: hasStart && startAt ? startAt : undefined, | |
149 | endAt: hasEnd && endAt ? endAt : undefined | |
150 | } | |
1ebddadd RK |
151 | }).subscribe( |
152 | () => { | |
153 | this.notifier.success(this.i18n('Video reported.')) | |
154 | this.hide() | |
155 | }, | |
4f8c0eb0 | 156 | |
1ebddadd RK |
157 | err => this.notifier.error(err.message) |
158 | ) | |
4f8c0eb0 | 159 | } |
a1b2f876 C |
160 | |
161 | isRemoteVideo () { | |
162 | return !this.video.isLocal | |
163 | } | |
4f8c0eb0 | 164 | } |