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