diff options
Diffstat (limited to 'client/src/app/shared/shared-moderation/abuse.service.ts')
-rw-r--r-- | client/src/app/shared/shared-moderation/abuse.service.ts | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-moderation/abuse.service.ts b/client/src/app/shared/shared-moderation/abuse.service.ts new file mode 100644 index 000000000..95ac16955 --- /dev/null +++ b/client/src/app/shared/shared-moderation/abuse.service.ts | |||
@@ -0,0 +1,154 @@ | |||
1 | import { omit } from 'lodash-es' | ||
2 | import { SortMeta } from 'primeng/api' | ||
3 | import { Observable } from 'rxjs' | ||
4 | import { catchError, map } from 'rxjs/operators' | ||
5 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
6 | import { Injectable } from '@angular/core' | ||
7 | import { RestExtractor, RestPagination, RestService } from '@app/core' | ||
8 | import { Abuse, AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, ResultList } from '@shared/models' | ||
9 | import { environment } from '../../../environments/environment' | ||
10 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
11 | |||
12 | @Injectable() | ||
13 | export class AbuseService { | ||
14 | private static BASE_ABUSE_URL = environment.apiUrl + '/api/v1/abuses' | ||
15 | |||
16 | constructor ( | ||
17 | private i18n: I18n, | ||
18 | private authHttp: HttpClient, | ||
19 | private restService: RestService, | ||
20 | private restExtractor: RestExtractor | ||
21 | ) { } | ||
22 | |||
23 | getAbuses (options: { | ||
24 | pagination: RestPagination, | ||
25 | sort: SortMeta, | ||
26 | search?: string | ||
27 | }): Observable<ResultList<Abuse>> { | ||
28 | const { pagination, sort, search } = options | ||
29 | const url = AbuseService.BASE_ABUSE_URL | ||
30 | |||
31 | let params = new HttpParams() | ||
32 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
33 | |||
34 | if (search) { | ||
35 | const filters = this.restService.parseQueryStringFilter(search, { | ||
36 | id: { prefix: '#' }, | ||
37 | state: { | ||
38 | prefix: 'state:', | ||
39 | handler: v => { | ||
40 | if (v === 'accepted') return AbuseState.ACCEPTED | ||
41 | if (v === 'pending') return AbuseState.PENDING | ||
42 | if (v === 'rejected') return AbuseState.REJECTED | ||
43 | |||
44 | return undefined | ||
45 | } | ||
46 | }, | ||
47 | videoIs: { | ||
48 | prefix: 'videoIs:', | ||
49 | handler: v => { | ||
50 | if (v === 'deleted') return v | ||
51 | if (v === 'blacklisted') return v | ||
52 | |||
53 | return undefined | ||
54 | } | ||
55 | }, | ||
56 | searchReporter: { prefix: 'reporter:' }, | ||
57 | searchReportee: { prefix: 'reportee:' }, | ||
58 | predefinedReason: { prefix: 'tag:' } | ||
59 | }) | ||
60 | |||
61 | params = this.restService.addObjectParams(params, filters) | ||
62 | } | ||
63 | |||
64 | return this.authHttp.get<ResultList<Abuse>>(url, { params }) | ||
65 | .pipe( | ||
66 | catchError(res => this.restExtractor.handleError(res)) | ||
67 | ) | ||
68 | } | ||
69 | |||
70 | reportVideo (parameters: AbuseCreate) { | ||
71 | const url = AbuseService.BASE_ABUSE_URL | ||
72 | |||
73 | const body = omit(parameters, ['id']) | ||
74 | |||
75 | return this.authHttp.post(url, body) | ||
76 | .pipe( | ||
77 | map(this.restExtractor.extractDataBool), | ||
78 | catchError(res => this.restExtractor.handleError(res)) | ||
79 | ) | ||
80 | } | ||
81 | |||
82 | updateAbuse (abuse: Abuse, abuseUpdate: AbuseUpdate) { | ||
83 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id | ||
84 | |||
85 | return this.authHttp.put(url, abuseUpdate) | ||
86 | .pipe( | ||
87 | map(this.restExtractor.extractDataBool), | ||
88 | catchError(res => this.restExtractor.handleError(res)) | ||
89 | ) | ||
90 | } | ||
91 | |||
92 | removeAbuse (abuse: Abuse) { | ||
93 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id | ||
94 | |||
95 | return this.authHttp.delete(url) | ||
96 | .pipe( | ||
97 | map(this.restExtractor.extractDataBool), | ||
98 | catchError(res => this.restExtractor.handleError(res)) | ||
99 | ) | ||
100 | } | ||
101 | |||
102 | getPrefefinedReasons (type: AbuseFilter) { | ||
103 | let reasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [ | ||
104 | { | ||
105 | id: 'violentOrRepulsive', | ||
106 | label: this.i18n('Violent or repulsive'), | ||
107 | help: this.i18n('Contains offensive, violent, or coarse language or iconography.') | ||
108 | }, | ||
109 | { | ||
110 | id: 'hatefulOrAbusive', | ||
111 | label: this.i18n('Hateful or abusive'), | ||
112 | help: this.i18n('Contains abusive, racist or sexist language or iconography.') | ||
113 | }, | ||
114 | { | ||
115 | id: 'spamOrMisleading', | ||
116 | label: this.i18n('Spam, ad or false news'), | ||
117 | help: this.i18n('Contains marketing, spam, purposefully deceitful news, or otherwise misleading thumbnail/text/tags. Please provide reputable sources to report hoaxes.') | ||
118 | }, | ||
119 | { | ||
120 | id: 'privacy', | ||
121 | label: this.i18n('Privacy breach or doxxing'), | ||
122 | 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).') | ||
123 | }, | ||
124 | { | ||
125 | id: 'rights', | ||
126 | label: this.i18n('Intellectual property violation'), | ||
127 | help: this.i18n('Infringes my intellectual property or copyright, wrt. the regional rules with which the server must comply.') | ||
128 | }, | ||
129 | { | ||
130 | id: 'serverRules', | ||
131 | label: this.i18n('Breaks server rules'), | ||
132 | 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.') | ||
133 | } | ||
134 | ] | ||
135 | |||
136 | if (type === 'video') { | ||
137 | reasons = reasons.concat([ | ||
138 | { | ||
139 | id: 'thumbnails', | ||
140 | label: this.i18n('Thumbnails'), | ||
141 | help: this.i18n('The above can only be seen in thumbnails.') | ||
142 | }, | ||
143 | { | ||
144 | id: 'captions', | ||
145 | label: this.i18n('Captions'), | ||
146 | help: this.i18n('The above can only be seen in captions (please describe which).') | ||
147 | } | ||
148 | ]) | ||
149 | } | ||
150 | |||
151 | return reasons | ||
152 | } | ||
153 | |||
154 | } | ||