]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { omit } from 'lodash-es' |
2 | import { SortMeta } from 'primeng/api' | |
3 | import { Observable } from 'rxjs' | |
db400f44 | 4 | import { catchError, map } from 'rxjs/operators' |
d592e0a9 | 5 | import { HttpClient, HttpParams } from '@angular/common/http' |
63c4db6d | 6 | import { Injectable } from '@angular/core' |
67ed6552 | 7 | import { RestExtractor, RestPagination, RestService } from '@app/core' |
94148c90 C |
8 | import { |
9 | AbuseCreate, | |
10 | AbuseFilter, | |
11 | AbuseMessage, | |
12 | AbusePredefinedReasonsString, | |
13 | AbuseState, | |
14 | AbuseUpdate, | |
15 | AdminAbuse, | |
16 | ResultList, | |
17 | UserAbuse | |
18 | } from '@shared/models' | |
19 | import { environment } from '../../../environments/environment' | |
11ac88de C |
20 | |
21 | @Injectable() | |
d95d1559 C |
22 | export class AbuseService { |
23 | private static BASE_ABUSE_URL = environment.apiUrl + '/api/v1/abuses' | |
94148c90 | 24 | private static BASE_MY_ABUSE_URL = environment.apiUrl + '/api/v1/users/me/abuses' |
11ac88de | 25 | |
df98563e | 26 | constructor ( |
d592e0a9 C |
27 | private authHttp: HttpClient, |
28 | private restService: RestService, | |
11ac88de | 29 | private restExtractor: RestExtractor |
8ca56654 | 30 | ) { } |
11ac88de | 31 | |
441e453a | 32 | getAdminAbuses (options: { |
844db39e RK |
33 | pagination: RestPagination, |
34 | sort: SortMeta, | |
35 | search?: string | |
441e453a | 36 | }): Observable<ResultList<AdminAbuse>> { |
844db39e | 37 | const { pagination, sort, search } = options |
8ca56654 | 38 | const url = AbuseService.BASE_ABUSE_URL |
d592e0a9 C |
39 | |
40 | let params = new HttpParams() | |
41 | params = this.restService.addRestGetParams(params, pagination, sort) | |
42 | ||
feb34f6b | 43 | if (search) { |
94148c90 | 44 | params = this.buildParamsFromSearch(search, params) |
feb34f6b | 45 | } |
844db39e | 46 | |
441e453a | 47 | return this.authHttp.get<ResultList<AdminAbuse>>(url, { params }) |
8ca56654 C |
48 | .pipe( |
49 | catchError(res => this.restExtractor.handleError(res)) | |
50 | ) | |
11ac88de C |
51 | } |
52 | ||
94148c90 C |
53 | getUserAbuses (options: { |
54 | pagination: RestPagination, | |
55 | sort: SortMeta, | |
56 | search?: string | |
57 | }): Observable<ResultList<UserAbuse>> { | |
58 | const { pagination, sort, search } = options | |
59 | const url = AbuseService.BASE_MY_ABUSE_URL | |
60 | ||
61 | let params = new HttpParams() | |
62 | params = this.restService.addRestGetParams(params, pagination, sort) | |
63 | ||
64 | if (search) { | |
65 | params = this.buildParamsFromSearch(search, params) | |
66 | } | |
67 | ||
68 | return this.authHttp.get<ResultList<UserAbuse>>(url, { params }) | |
69 | .pipe( | |
70 | catchError(res => this.restExtractor.handleError(res)) | |
71 | ) | |
72 | } | |
73 | ||
d95d1559 C |
74 | reportVideo (parameters: AbuseCreate) { |
75 | const url = AbuseService.BASE_ABUSE_URL | |
1ebddadd | 76 | |
8ca56654 | 77 | const body = omit(parameters, ['id']) |
11ac88de C |
78 | |
79 | return this.authHttp.post(url, body) | |
8ca56654 C |
80 | .pipe( |
81 | map(this.restExtractor.extractDataBool), | |
82 | catchError(res => this.restExtractor.handleError(res)) | |
83 | ) | |
11ac88de | 84 | } |
efc9e845 | 85 | |
441e453a | 86 | updateAbuse (abuse: AdminAbuse, abuseUpdate: AbuseUpdate) { |
d95d1559 | 87 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id |
efc9e845 C |
88 | |
89 | return this.authHttp.put(url, abuseUpdate) | |
8ca56654 C |
90 | .pipe( |
91 | map(this.restExtractor.extractDataBool), | |
92 | catchError(res => this.restExtractor.handleError(res)) | |
93 | ) | |
efc9e845 C |
94 | } |
95 | ||
441e453a | 96 | removeAbuse (abuse: AdminAbuse) { |
d95d1559 | 97 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id |
efc9e845 C |
98 | |
99 | return this.authHttp.delete(url) | |
8ca56654 C |
100 | .pipe( |
101 | map(this.restExtractor.extractDataBool), | |
102 | catchError(res => this.restExtractor.handleError(res)) | |
103 | ) | |
441e453a C |
104 | } |
105 | ||
106 | addAbuseMessage (abuse: UserAbuse, message: string) { | |
107 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id + '/messages' | |
108 | ||
109 | return this.authHttp.post(url, { message }) | |
110 | .pipe( | |
111 | map(this.restExtractor.extractDataBool), | |
112 | catchError(res => this.restExtractor.handleError(res)) | |
113 | ) | |
114 | } | |
115 | ||
116 | listAbuseMessages (abuse: UserAbuse) { | |
117 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id + '/messages' | |
118 | ||
119 | return this.authHttp.get<ResultList<AbuseMessage>>(url) | |
120 | .pipe( | |
121 | catchError(res => this.restExtractor.handleError(res)) | |
122 | ) | |
123 | } | |
124 | ||
125 | deleteAbuseMessage (abuse: UserAbuse, abuseMessage: AbuseMessage) { | |
126 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id + '/messages/' + abuseMessage.id | |
127 | ||
128 | return this.authHttp.delete(url) | |
129 | .pipe( | |
130 | map(this.restExtractor.extractDataBool), | |
131 | catchError(res => this.restExtractor.handleError(res)) | |
132 | ) | |
8ca56654 C |
133 | } |
134 | ||
135 | getPrefefinedReasons (type: AbuseFilter) { | |
136 | let reasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [ | |
137 | { | |
138 | id: 'violentOrRepulsive', | |
66357162 C |
139 | label: $localize`Violent or repulsive`, |
140 | help: $localize`Contains offensive, violent, or coarse language or iconography.` | |
8ca56654 C |
141 | }, |
142 | { | |
143 | id: 'hatefulOrAbusive', | |
66357162 C |
144 | label: $localize`Hateful or abusive`, |
145 | help: $localize`Contains abusive, racist or sexist language or iconography.` | |
8ca56654 C |
146 | }, |
147 | { | |
148 | id: 'spamOrMisleading', | |
66357162 C |
149 | label: $localize`Spam, ad or false news`, |
150 | help: $localize`Contains marketing, spam, purposefully deceitful news, or otherwise misleading thumbnail/text/tags. Please provide reputable sources to report hoaxes.` | |
8ca56654 C |
151 | }, |
152 | { | |
153 | id: 'privacy', | |
66357162 C |
154 | label: $localize`Privacy breach or doxxing`, |
155 | help: $localize`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).` | |
8ca56654 C |
156 | }, |
157 | { | |
158 | id: 'rights', | |
66357162 C |
159 | label: $localize`Copyright`, |
160 | help: $localize`Infringes your copyright wrt. the regional laws with which the server must comply.` | |
8ca56654 C |
161 | }, |
162 | { | |
163 | id: 'serverRules', | |
66357162 C |
164 | label: $localize`Breaks server rules`, |
165 | description: $localize`Anything not included in the above that breaks the terms of service, code of conduct, or general rules in place on the server.` | |
8ca56654 C |
166 | } |
167 | ] | |
168 | ||
169 | if (type === 'video') { | |
170 | reasons = reasons.concat([ | |
171 | { | |
172 | id: 'thumbnails', | |
66357162 C |
173 | label: $localize`Thumbnails`, |
174 | help: $localize`The above can only be seen in thumbnails.` | |
8ca56654 C |
175 | }, |
176 | { | |
177 | id: 'captions', | |
66357162 C |
178 | label: $localize`Captions`, |
179 | help: $localize`The above can only be seen in captions (please describe which).` | |
8ca56654 C |
180 | } |
181 | ]) | |
182 | } | |
183 | ||
184 | return reasons | |
185 | } | |
186 | ||
94148c90 C |
187 | private buildParamsFromSearch (search: string, params: HttpParams) { |
188 | const filters = this.restService.parseQueryStringFilter(search, { | |
189 | id: { prefix: '#' }, | |
190 | state: { | |
191 | prefix: 'state:', | |
192 | handler: v => { | |
193 | if (v === 'accepted') return AbuseState.ACCEPTED | |
194 | if (v === 'pending') return AbuseState.PENDING | |
195 | if (v === 'rejected') return AbuseState.REJECTED | |
196 | ||
197 | return undefined | |
198 | } | |
199 | }, | |
200 | videoIs: { | |
201 | prefix: 'videoIs:', | |
202 | handler: v => { | |
203 | if (v === 'deleted') return v | |
204 | if (v === 'blacklisted') return v | |
205 | ||
206 | return undefined | |
207 | } | |
208 | }, | |
209 | searchReporter: { prefix: 'reporter:' }, | |
210 | searchReportee: { prefix: 'reportee:' }, | |
211 | predefinedReason: { prefix: 'tag:' } | |
212 | }) | |
213 | ||
214 | return this.restService.addObjectParams(params, filters) | |
215 | } | |
8ca56654 | 216 | } |