aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/instance/follow.service.ts96
-rw-r--r--client/src/app/shared/shared.module.ts3
-rw-r--r--client/src/app/shared/video/abstract-video-list.html1
3 files changed, 99 insertions, 1 deletions
diff --git a/client/src/app/shared/instance/follow.service.ts b/client/src/app/shared/instance/follow.service.ts
new file mode 100644
index 000000000..5a44c64f1
--- /dev/null
+++ b/client/src/app/shared/instance/follow.service.ts
@@ -0,0 +1,96 @@
1import { catchError, map } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core'
4import { SortMeta } from 'primeng/primeng'
5import { Observable } from 'rxjs'
6import { ActorFollow, ResultList } from '@shared/index'
7import { environment } from '../../../environments/environment'
8import { RestExtractor, RestPagination, RestService } from '../rest'
9
10@Injectable()
11export class FollowService {
12 private static BASE_APPLICATION_URL = 'https://peertube2.cpy.re' + '/api/v1/server'
13
14 constructor (
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
18 ) {
19 }
20
21 getFollowing (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<ActorFollow>> {
22 let params = new HttpParams()
23 params = this.restService.addRestGetParams(params, pagination, sort)
24
25 if (search) params = params.append('search', search)
26
27 return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/following', { params })
28 .pipe(
29 map(res => this.restExtractor.convertResultListDateToHuman(res)),
30 catchError(res => this.restExtractor.handleError(res))
31 )
32 }
33
34 getFollowers (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<ActorFollow>> {
35 let params = new HttpParams()
36 params = this.restService.addRestGetParams(params, pagination, sort)
37
38 if (search) params = params.append('search', search)
39
40 return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/followers', { params })
41 .pipe(
42 map(res => this.restExtractor.convertResultListDateToHuman(res)),
43 catchError(res => this.restExtractor.handleError(res))
44 )
45 }
46
47 follow (notEmptyHosts: string[]) {
48 const body = {
49 hosts: notEmptyHosts
50 }
51
52 return this.authHttp.post(FollowService.BASE_APPLICATION_URL + '/following', body)
53 .pipe(
54 map(this.restExtractor.extractDataBool),
55 catchError(res => this.restExtractor.handleError(res))
56 )
57 }
58
59 unfollow (follow: ActorFollow) {
60 return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host)
61 .pipe(
62 map(this.restExtractor.extractDataBool),
63 catchError(res => this.restExtractor.handleError(res))
64 )
65 }
66
67 acceptFollower (follow: ActorFollow) {
68 const handle = follow.follower.name + '@' + follow.follower.host
69
70 return this.authHttp.post(`${FollowService.BASE_APPLICATION_URL}/followers/${handle}/accept`, {})
71 .pipe(
72 map(this.restExtractor.extractDataBool),
73 catchError(res => this.restExtractor.handleError(res))
74 )
75 }
76
77 rejectFollower (follow: ActorFollow) {
78 const handle = follow.follower.name + '@' + follow.follower.host
79
80 return this.authHttp.post(`${FollowService.BASE_APPLICATION_URL}/followers/${handle}/reject`, {})
81 .pipe(
82 map(this.restExtractor.extractDataBool),
83 catchError(res => this.restExtractor.handleError(res))
84 )
85 }
86
87 removeFollower (follow: ActorFollow) {
88 const handle = follow.follower.name + '@' + follow.follower.host
89
90 return this.authHttp.delete(`${FollowService.BASE_APPLICATION_URL}/followers/${handle}`)
91 .pipe(
92 map(this.restExtractor.extractDataBool),
93 catchError(res => this.restExtractor.handleError(res))
94 )
95 }
96}
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts
index 39f1a69e2..1d49c7bc8 100644
--- a/client/src/app/shared/shared.module.ts
+++ b/client/src/app/shared/shared.module.ts
@@ -85,6 +85,7 @@ import { VideoBlacklistComponent } from '@app/shared/video/modals/video-blacklis
85import { VideoDownloadComponent } from '@app/shared/video/modals/video-download.component' 85import { VideoDownloadComponent } from '@app/shared/video/modals/video-download.component'
86import { VideoReportComponent } from '@app/shared/video/modals/video-report.component' 86import { VideoReportComponent } from '@app/shared/video/modals/video-report.component'
87import { ClipboardModule } from 'ngx-clipboard' 87import { ClipboardModule } from 'ngx-clipboard'
88import { FollowService } from '@app/shared/instance/follow.service'
88 89
89@NgModule({ 90@NgModule({
90 imports: [ 91 imports: [
@@ -271,6 +272,8 @@ import { ClipboardModule } from 'ngx-clipboard'
271 272
272 UserNotificationService, 273 UserNotificationService,
273 274
275 FollowService,
276
274 I18n 277 I18n
275 ] 278 ]
276}) 279})
diff --git a/client/src/app/shared/video/abstract-video-list.html b/client/src/app/shared/video/abstract-video-list.html
index 11cf1bd92..efd369bca 100644
--- a/client/src/app/shared/video/abstract-video-list.html
+++ b/client/src/app/shared/video/abstract-video-list.html
@@ -27,7 +27,6 @@
27 {{ getCurrentGroupedDateLabel(video) }} 27 {{ getCurrentGroupedDateLabel(video) }}
28 </div> 28 </div>
29 29
30
31 <my-video-miniature 30 <my-video-miniature
32 [video]="video" [user]="user" [ownerDisplayType]="ownerDisplayType" 31 [video]="video" [user]="user" [ownerDisplayType]="ownerDisplayType"
33 [displayVideoActions]="displayVideoActions" [displayOptions]="displayOptions" 32 [displayVideoActions]="displayVideoActions" [displayOptions]="displayOptions"