diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/instance/follow.service.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/instance/follow.service.ts')
-rw-r--r-- | client/src/app/shared/instance/follow.service.ts | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/client/src/app/shared/instance/follow.service.ts b/client/src/app/shared/instance/follow.service.ts deleted file mode 100644 index ef4c09583..000000000 --- a/client/src/app/shared/instance/follow.service.ts +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { Observable } from 'rxjs' | ||
5 | import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/index' | ||
6 | import { environment } from '../../../environments/environment' | ||
7 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
8 | import { SortMeta } from 'primeng/api' | ||
9 | |||
10 | @Injectable() | ||
11 | export class FollowService { | ||
12 | private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/server' | ||
13 | |||
14 | constructor ( | ||
15 | private authHttp: HttpClient, | ||
16 | private restService: RestService, | ||
17 | private restExtractor: RestExtractor | ||
18 | ) { | ||
19 | } | ||
20 | |||
21 | getFollowing (options: { | ||
22 | pagination: RestPagination, | ||
23 | sort: SortMeta, | ||
24 | search?: string, | ||
25 | actorType?: ActivityPubActorType, | ||
26 | state?: FollowState | ||
27 | }): Observable<ResultList<ActorFollow>> { | ||
28 | const { pagination, sort, search, state, actorType } = options | ||
29 | |||
30 | let params = new HttpParams() | ||
31 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
32 | |||
33 | if (search) params = params.append('search', search) | ||
34 | if (state) params = params.append('state', state) | ||
35 | if (actorType) params = params.append('actorType', actorType) | ||
36 | |||
37 | return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/following', { params }) | ||
38 | .pipe( | ||
39 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
40 | catchError(res => this.restExtractor.handleError(res)) | ||
41 | ) | ||
42 | } | ||
43 | |||
44 | getFollowers (options: { | ||
45 | pagination: RestPagination, | ||
46 | sort: SortMeta, | ||
47 | search?: string, | ||
48 | actorType?: ActivityPubActorType, | ||
49 | state?: FollowState | ||
50 | }): Observable<ResultList<ActorFollow>> { | ||
51 | const { pagination, sort, search, state, actorType } = options | ||
52 | |||
53 | let params = new HttpParams() | ||
54 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
55 | |||
56 | if (search) params = params.append('search', search) | ||
57 | if (state) params = params.append('state', state) | ||
58 | if (actorType) params = params.append('actorType', actorType) | ||
59 | |||
60 | return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/followers', { params }) | ||
61 | .pipe( | ||
62 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
63 | catchError(res => this.restExtractor.handleError(res)) | ||
64 | ) | ||
65 | } | ||
66 | |||
67 | follow (notEmptyHosts: string[]) { | ||
68 | const body = { | ||
69 | hosts: notEmptyHosts | ||
70 | } | ||
71 | |||
72 | return this.authHttp.post(FollowService.BASE_APPLICATION_URL + '/following', body) | ||
73 | .pipe( | ||
74 | map(this.restExtractor.extractDataBool), | ||
75 | catchError(res => this.restExtractor.handleError(res)) | ||
76 | ) | ||
77 | } | ||
78 | |||
79 | unfollow (follow: ActorFollow) { | ||
80 | return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host) | ||
81 | .pipe( | ||
82 | map(this.restExtractor.extractDataBool), | ||
83 | catchError(res => this.restExtractor.handleError(res)) | ||
84 | ) | ||
85 | } | ||
86 | |||
87 | acceptFollower (follow: ActorFollow) { | ||
88 | const handle = follow.follower.name + '@' + follow.follower.host | ||
89 | |||
90 | return this.authHttp.post(`${FollowService.BASE_APPLICATION_URL}/followers/${handle}/accept`, {}) | ||
91 | .pipe( | ||
92 | map(this.restExtractor.extractDataBool), | ||
93 | catchError(res => this.restExtractor.handleError(res)) | ||
94 | ) | ||
95 | } | ||
96 | |||
97 | rejectFollower (follow: ActorFollow) { | ||
98 | const handle = follow.follower.name + '@' + follow.follower.host | ||
99 | |||
100 | return this.authHttp.post(`${FollowService.BASE_APPLICATION_URL}/followers/${handle}/reject`, {}) | ||
101 | .pipe( | ||
102 | map(this.restExtractor.extractDataBool), | ||
103 | catchError(res => this.restExtractor.handleError(res)) | ||
104 | ) | ||
105 | } | ||
106 | |||
107 | removeFollower (follow: ActorFollow) { | ||
108 | const handle = follow.follower.name + '@' + follow.follower.host | ||
109 | |||
110 | return this.authHttp.delete(`${FollowService.BASE_APPLICATION_URL}/followers/${handle}`) | ||
111 | .pipe( | ||
112 | map(this.restExtractor.extractDataBool), | ||
113 | catchError(res => this.restExtractor.handleError(res)) | ||
114 | ) | ||
115 | } | ||
116 | } | ||