]>
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' |
8ca56654 | 8 | import { Abuse, AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, ResultList } 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 | |
d95d1559 | 23 | getAbuses (options: { |
844db39e RK |
24 | pagination: RestPagination, |
25 | sort: SortMeta, | |
26 | search?: string | |
d95d1559 | 27 | }): Observable<ResultList<Abuse>> { |
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 | |
d95d1559 | 64 | return this.authHttp.get<ResultList<Abuse>>(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 | |
d95d1559 C |
82 | updateAbuse (abuse: Abuse, abuseUpdate: AbuseUpdate) { |
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 | ||
d95d1559 C |
92 | removeAbuse (abuse: Abuse) { |
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 | ) | |
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 | } |