]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/shared/follow.service.ts
Merge branch 'develop' into pr/1217
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / shared / follow.service.ts
CommitLineData
db400f44 1import { catchError, map } from 'rxjs/operators'
8a02bd04 2import { HttpClient, HttpParams } from '@angular/common/http'
63c4db6d
C
3import { Injectable } from '@angular/core'
4import { SortMeta } from 'primeng/primeng'
db400f44 5import { Observable } from 'rxjs'
c48e82b5 6import { ActorFollow, ResultList } from '../../../../../../shared'
63c4db6d
C
7import { environment } from '../../../../environments/environment'
8import { RestExtractor, RestPagination, RestService } from '../../../shared'
e2f555ca
C
9
10@Injectable()
51548b31 11export class FollowService {
63c4db6d 12 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/server'
e2f555ca
C
13
14 constructor (
d592e0a9 15 private authHttp: HttpClient,
8a02bd04 16 private restService: RestService,
de59c48f 17 private restExtractor: RestExtractor
db400f44
C
18 ) {
19 }
e2f555ca 20
b014b6b9 21 getFollowing (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<ActorFollow>> {
8a02bd04
C
22 let params = new HttpParams()
23 params = this.restService.addRestGetParams(params, pagination, sort)
24
b014b6b9
C
25 if (search) params = params.append('search', search)
26
c48e82b5 27 return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/following', { params })
db400f44
C
28 .pipe(
29 map(res => this.restExtractor.convertResultListDateToHuman(res)),
30 catchError(res => this.restExtractor.handleError(res))
31 )
e2f555ca
C
32 }
33
b014b6b9 34 getFollowers (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<ActorFollow>> {
51548b31
C
35 let params = new HttpParams()
36 params = this.restService.addRestGetParams(params, pagination, sort)
37
b014b6b9
C
38 if (search) params = params.append('search', search)
39
c48e82b5 40 return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/followers', { params })
db400f44
C
41 .pipe(
42 map(res => this.restExtractor.convertResultListDateToHuman(res)),
43 catchError(res => this.restExtractor.handleError(res))
44 )
51548b31
C
45 }
46
7e9334c3 47 follow (notEmptyHosts: string[]) {
e105c19c 48 const body = {
49abbbbe 49 hosts: notEmptyHosts
df98563e 50 }
e105c19c 51
9a27cdc2 52 return this.authHttp.post(FollowService.BASE_APPLICATION_URL + '/following', body)
db400f44
C
53 .pipe(
54 map(this.restExtractor.extractDataBool),
55 catchError(res => this.restExtractor.handleError(res))
56 )
d5f5a670 57 }
7e9334c3 58
c48e82b5 59 unfollow (follow: ActorFollow) {
39fdb3c0 60 return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host)
db400f44
C
61 .pipe(
62 map(this.restExtractor.extractDataBool),
63 catchError(res => this.restExtractor.handleError(res))
64 )
7e9334c3 65 }
e2f555ca 66}