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'
13 export class AbuseService {
14 private static BASE_ABUSE_URL = environment.apiUrl + '/api/v1/abuses'
18 private authHttp: HttpClient,
19 private restService: RestService,
20 private restExtractor: RestExtractor
24 pagination: RestPagination,
27 }): Observable<ResultList<Abuse>> {
28 const { pagination, sort, search } = options
29 const url = AbuseService.BASE_ABUSE_URL
31 let params = new HttpParams()
32 params = this.restService.addRestGetParams(params, pagination, sort)
35 const filters = this.restService.parseQueryStringFilter(search, {
40 if (v === 'accepted') return AbuseState.ACCEPTED
41 if (v === 'pending') return AbuseState.PENDING
42 if (v === 'rejected') return AbuseState.REJECTED
50 if (v === 'deleted') return v
51 if (v === 'blacklisted') return v
56 searchReporter: { prefix: 'reporter:' },
57 searchReportee: { prefix: 'reportee:' },
58 predefinedReason: { prefix: 'tag:' }
61 params = this.restService.addObjectParams(params, filters)
64 return this.authHttp.get<ResultList<Abuse>>(url, { params })
66 catchError(res => this.restExtractor.handleError(res))
70 reportVideo (parameters: AbuseCreate) {
71 const url = AbuseService.BASE_ABUSE_URL
73 const body = omit(parameters, ['id'])
75 return this.authHttp.post(url, body)
77 map(this.restExtractor.extractDataBool),
78 catchError(res => this.restExtractor.handleError(res))
82 updateAbuse (abuse: Abuse, abuseUpdate: AbuseUpdate) {
83 const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id
85 return this.authHttp.put(url, abuseUpdate)
87 map(this.restExtractor.extractDataBool),
88 catchError(res => this.restExtractor.handleError(res))
92 removeAbuse (abuse: Abuse) {
93 const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id
95 return this.authHttp.delete(url)
97 map(this.restExtractor.extractDataBool),
98 catchError(res => this.restExtractor.handleError(res))
102 getPrefefinedReasons (type: AbuseFilter) {
103 let reasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [
105 id: 'violentOrRepulsive',
106 label: this.i18n('Violent or repulsive'),
107 help: this.i18n('Contains offensive, violent, or coarse language or iconography.')
110 id: 'hatefulOrAbusive',
111 label: this.i18n('Hateful or abusive'),
112 help: this.i18n('Contains abusive, racist or sexist language or iconography.')
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.')
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).')
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.')
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.')
136 if (type === 'video') {
137 reasons = reasons.concat([
140 label: this.i18n('Thumbnails'),
141 help: this.i18n('The above can only be seen in thumbnails.')
145 label: this.i18n('Captions'),
146 help: this.i18n('The above can only be seen in captions (please describe which).')