diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-09 15:54:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-10 14:02:41 +0200 |
commit | cfde28bac33c3644e1b6218eb471b675a37def60 (patch) | |
tree | eb648fc358a2face0f14c598c8eec7769e6b0ed5 /client/src/app/shared/shared-moderation/video-report.component.ts | |
parent | 8ca56654a176ee8f350d31282c6cac4a59f58499 (diff) | |
download | PeerTube-cfde28bac33c3644e1b6218eb471b675a37def60.tar.gz PeerTube-cfde28bac33c3644e1b6218eb471b675a37def60.tar.zst PeerTube-cfde28bac33c3644e1b6218eb471b675a37def60.zip |
Add ability to report account
Diffstat (limited to 'client/src/app/shared/shared-moderation/video-report.component.ts')
-rw-r--r-- | client/src/app/shared/shared-moderation/video-report.component.ts | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/client/src/app/shared/shared-moderation/video-report.component.ts b/client/src/app/shared/shared-moderation/video-report.component.ts deleted file mode 100644 index 26e7b62ba..000000000 --- a/client/src/app/shared/shared-moderation/video-report.component.ts +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | import { mapValues, pickBy } from 'lodash-es' | ||
2 | import { buildVideoEmbed, buildVideoLink } from 'src/assets/player/utils' | ||
3 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | ||
4 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | ||
5 | import { Notifier } from '@app/core' | ||
6 | import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms' | ||
7 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
8 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
10 | import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models' | ||
11 | import { Video } from '../shared-main' | ||
12 | import { AbuseService } from './abuse.service' | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-video-report', | ||
16 | templateUrl: './video-report.component.html', | ||
17 | styleUrls: [ './video-report.component.scss' ] | ||
18 | }) | ||
19 | export class VideoReportComponent extends FormReactive implements OnInit { | ||
20 | @Input() video: Video = null | ||
21 | |||
22 | @ViewChild('modal', { static: true }) modal: NgbModal | ||
23 | |||
24 | error: string = null | ||
25 | predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [] | ||
26 | embedHtml: SafeHtml | ||
27 | |||
28 | private openedModal: NgbModalRef | ||
29 | |||
30 | constructor ( | ||
31 | protected formValidatorService: FormValidatorService, | ||
32 | private modalService: NgbModal, | ||
33 | private abuseValidatorsService: AbuseValidatorsService, | ||
34 | private abuseService: AbuseService, | ||
35 | private notifier: Notifier, | ||
36 | private sanitizer: DomSanitizer, | ||
37 | private i18n: I18n | ||
38 | ) { | ||
39 | super() | ||
40 | } | ||
41 | |||
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 | |||
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 | |||
70 | ngOnInit () { | ||
71 | this.buildForm({ | ||
72 | reason: this.abuseValidatorsService.ABUSE_REASON, | ||
73 | predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null), | ||
74 | timestamp: { | ||
75 | hasStart: null, | ||
76 | startAt: null, | ||
77 | hasEnd: null, | ||
78 | endAt: null | ||
79 | } | ||
80 | }) | ||
81 | |||
82 | this.predefinedReasons = this.abuseService.getPrefefinedReasons('video') | ||
83 | |||
84 | this.embedHtml = this.getVideoEmbed() | ||
85 | } | ||
86 | |||
87 | show () { | ||
88 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' }) | ||
89 | } | ||
90 | |||
91 | hide () { | ||
92 | this.openedModal.close() | ||
93 | this.openedModal = null | ||
94 | } | ||
95 | |||
96 | report () { | ||
97 | const reason = this.form.get('reason').value | ||
98 | const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[] | ||
99 | const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value | ||
100 | |||
101 | this.abuseService.reportVideo({ | ||
102 | reason, | ||
103 | predefinedReasons, | ||
104 | video: { | ||
105 | id: this.video.id, | ||
106 | startAt: hasStart && startAt ? startAt : undefined, | ||
107 | endAt: hasEnd && endAt ? endAt : undefined | ||
108 | } | ||
109 | }).subscribe( | ||
110 | () => { | ||
111 | this.notifier.success(this.i18n('Video reported.')) | ||
112 | this.hide() | ||
113 | }, | ||
114 | |||
115 | err => this.notifier.error(err.message) | ||
116 | ) | ||
117 | } | ||
118 | |||
119 | isRemoteVideo () { | ||
120 | return !this.video.isLocal | ||
121 | } | ||
122 | } | ||