]>
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' |
441e453a | 8 | import { AdminAbuse, AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, ResultList, UserAbuse, AbuseMessage } from '@shared/models' |
63c4db6d | 9 | import { environment } from '../../../environments/environment' |
8ca56654 | 10 | import { I18n } from '@ngx-translate/i18n-polyfill' |
11ac88de C |
11 | |
12 | @Injectable() | |
d95d1559 C |
13 | export class AbuseService { |
14 | private static BASE_ABUSE_URL = environment.apiUrl + '/api/v1/abuses' | |
11ac88de | 15 | |
df98563e | 16 | constructor ( |
8ca56654 | 17 | private i18n: I18n, |
d592e0a9 C |
18 | private authHttp: HttpClient, |
19 | private restService: RestService, | |
11ac88de | 20 | private restExtractor: RestExtractor |
8ca56654 | 21 | ) { } |
11ac88de | 22 | |
441e453a | 23 | getAdminAbuses (options: { |
844db39e RK |
24 | pagination: RestPagination, |
25 | sort: SortMeta, | |
26 | search?: string | |
441e453a | 27 | }): Observable<ResultList<AdminAbuse>> { |
844db39e | 28 | const { pagination, sort, search } = options |
8ca56654 | 29 | const url = AbuseService.BASE_ABUSE_URL |
d592e0a9 C |
30 | |
31 | let params = new HttpParams() | |
32 | params = this.restService.addRestGetParams(params, pagination, sort) | |
33 | ||
feb34f6b C |
34 | if (search) { |
35 | const filters = this.restService.parseQueryStringFilter(search, { | |
36 | id: { prefix: '#' }, | |
37 | state: { | |
38 | prefix: 'state:', | |
39 | handler: v => { | |
d95d1559 C |
40 | if (v === 'accepted') return AbuseState.ACCEPTED |
41 | if (v === 'pending') return AbuseState.PENDING | |
42 | if (v === 'rejected') return AbuseState.REJECTED | |
feb34f6b C |
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:' }, | |
1ebddadd RK |
57 | searchReportee: { prefix: 'reportee:' }, |
58 | predefinedReason: { prefix: 'tag:' } | |
feb34f6b C |
59 | }) |
60 | ||
61 | params = this.restService.addObjectParams(params, filters) | |
62 | } | |
844db39e | 63 | |
441e453a | 64 | return this.authHttp.get<ResultList<AdminAbuse>>(url, { params }) |
8ca56654 C |
65 | .pipe( |
66 | catchError(res => this.restExtractor.handleError(res)) | |
67 | ) | |
11ac88de C |
68 | } |
69 | ||
d95d1559 C |
70 | reportVideo (parameters: AbuseCreate) { |
71 | const url = AbuseService.BASE_ABUSE_URL | |
1ebddadd | 72 | |
8ca56654 | 73 | const body = omit(parameters, ['id']) |
11ac88de C |
74 | |
75 | return this.authHttp.post(url, body) | |
8ca56654 C |
76 | .pipe( |
77 | map(this.restExtractor.extractDataBool), | |
78 | catchError(res => this.restExtractor.handleError(res)) | |
79 | ) | |
11ac88de | 80 | } |
efc9e845 | 81 | |
441e453a | 82 | updateAbuse (abuse: AdminAbuse, abuseUpdate: AbuseUpdate) { |
d95d1559 | 83 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id |
efc9e845 C |
84 | |
85 | return this.authHttp.put(url, abuseUpdate) | |
8ca56654 C |
86 | .pipe( |
87 | map(this.restExtractor.extractDataBool), | |
88 | catchError(res => this.restExtractor.handleError(res)) | |
89 | ) | |
efc9e845 C |
90 | } |
91 | ||
441e453a | 92 | removeAbuse (abuse: AdminAbuse) { |
d95d1559 | 93 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id |
efc9e845 C |
94 | |
95 | return this.authHttp.delete(url) | |
8ca56654 C |
96 | .pipe( |
97 | map(this.restExtractor.extractDataBool), | |
98 | catchError(res => this.restExtractor.handleError(res)) | |
99 | ) | |
441e453a C |
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 | ) | |
8ca56654 C |
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 | } |