]>
Commit | Line | Data |
---|---|---|
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 { AdminAbuse, AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, ResultList, UserAbuse, AbuseMessage } 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 | getAdminAbuses (options: { | |
24 | pagination: RestPagination, | |
25 | sort: SortMeta, | |
26 | search?: string | |
27 | }): Observable<ResultList<AdminAbuse>> { | |
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<AdminAbuse>>(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: AdminAbuse, 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: AdminAbuse) { | |
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 | addAbuseMessage (abuse: UserAbuse, message: string) { | |
103 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id + '/messages' | |
104 | ||
105 | return this.authHttp.post(url, { message }) | |
106 | .pipe( | |
107 | map(this.restExtractor.extractDataBool), | |
108 | catchError(res => this.restExtractor.handleError(res)) | |
109 | ) | |
110 | } | |
111 | ||
112 | listAbuseMessages (abuse: UserAbuse) { | |
113 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id + '/messages' | |
114 | ||
115 | return this.authHttp.get<ResultList<AbuseMessage>>(url) | |
116 | .pipe( | |
117 | catchError(res => this.restExtractor.handleError(res)) | |
118 | ) | |
119 | } | |
120 | ||
121 | deleteAbuseMessage (abuse: UserAbuse, abuseMessage: AbuseMessage) { | |
122 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id + '/messages/' + abuseMessage.id | |
123 | ||
124 | return this.authHttp.delete(url) | |
125 | .pipe( | |
126 | map(this.restExtractor.extractDataBool), | |
127 | catchError(res => this.restExtractor.handleError(res)) | |
128 | ) | |
129 | } | |
130 | ||
131 | getPrefefinedReasons (type: AbuseFilter) { | |
132 | let reasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [ | |
133 | { | |
134 | id: 'violentOrRepulsive', | |
135 | label: this.i18n('Violent or repulsive'), | |
136 | help: this.i18n('Contains offensive, violent, or coarse language or iconography.') | |
137 | }, | |
138 | { | |
139 | id: 'hatefulOrAbusive', | |
140 | label: this.i18n('Hateful or abusive'), | |
141 | help: this.i18n('Contains abusive, racist or sexist language or iconography.') | |
142 | }, | |
143 | { | |
144 | id: 'spamOrMisleading', | |
145 | label: this.i18n('Spam, ad or false news'), | |
146 | help: this.i18n('Contains marketing, spam, purposefully deceitful news, or otherwise misleading thumbnail/text/tags. Please provide reputable sources to report hoaxes.') | |
147 | }, | |
148 | { | |
149 | id: 'privacy', | |
150 | label: this.i18n('Privacy breach or doxxing'), | |
151 | 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).') | |
152 | }, | |
153 | { | |
154 | id: 'rights', | |
155 | label: this.i18n('Intellectual property violation'), | |
156 | help: this.i18n('Infringes my intellectual property or copyright, wrt. the regional rules with which the server must comply.') | |
157 | }, | |
158 | { | |
159 | id: 'serverRules', | |
160 | label: this.i18n('Breaks server rules'), | |
161 | 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.') | |
162 | } | |
163 | ] | |
164 | ||
165 | if (type === 'video') { | |
166 | reasons = reasons.concat([ | |
167 | { | |
168 | id: 'thumbnails', | |
169 | label: this.i18n('Thumbnails'), | |
170 | help: this.i18n('The above can only be seen in thumbnails.') | |
171 | }, | |
172 | { | |
173 | id: 'captions', | |
174 | label: this.i18n('Captions'), | |
175 | help: this.i18n('The above can only be seen in captions (please describe which).') | |
176 | } | |
177 | ]) | |
178 | } | |
179 | ||
180 | return reasons | |
181 | } | |
182 | ||
183 | } |