diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-19 09:44:43 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-20 09:25:44 +0200 |
commit | 4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 (patch) | |
tree | 6244a10b286d66c6dcd7799aee630670d0493781 /client/src/app/shared/shared-user-subscription | |
parent | 9593a78ae1368a9ad8bb11044fce6fde2892701a (diff) | |
download | PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.gz PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.zst PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.zip |
Add ability to view my followers
Diffstat (limited to 'client/src/app/shared/shared-user-subscription')
-rw-r--r-- | client/src/app/shared/shared-user-subscription/user-subscription.service.ts | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/client/src/app/shared/shared-user-subscription/user-subscription.service.ts b/client/src/app/shared/shared-user-subscription/user-subscription.service.ts index f289fb6cf..ede65ff39 100644 --- a/client/src/app/shared/shared-user-subscription/user-subscription.service.ts +++ b/client/src/app/shared/shared-user-subscription/user-subscription.service.ts | |||
@@ -6,7 +6,7 @@ import { Injectable } from '@angular/core' | |||
6 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' | 6 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' |
7 | import { buildBulkObservable } from '@app/helpers' | 7 | import { buildBulkObservable } from '@app/helpers' |
8 | import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' | 8 | import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' |
9 | import { ResultList, VideoChannel as VideoChannelServer, VideoSortField } from '@shared/models' | 9 | import { ActorFollow, ResultList, VideoChannel as VideoChannelServer, VideoSortField } from '@shared/models' |
10 | import { environment } from '../../../environments/environment' | 10 | import { environment } from '../../../environments/environment' |
11 | 11 | ||
12 | const logger = debug('peertube:subscriptions:UserSubscriptionService') | 12 | const logger = debug('peertube:subscriptions:UserSubscriptionService') |
@@ -17,6 +17,8 @@ type SubscriptionExistResultObservable = { [ uri: string ]: Observable<boolean> | |||
17 | @Injectable() | 17 | @Injectable() |
18 | export class UserSubscriptionService { | 18 | export class UserSubscriptionService { |
19 | static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/users/me/subscriptions' | 19 | static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/users/me/subscriptions' |
20 | static BASE_VIDEO_CHANNELS_URL = environment.apiUrl + '/api/v1/video-channels' | ||
21 | static BASE_ACCOUNTS_URL = environment.apiUrl + '/api/v1/accounts' | ||
20 | 22 | ||
21 | // Use a replay subject because we "next" a value before subscribing | 23 | // Use a replay subject because we "next" a value before subscribing |
22 | private existsSubject = new ReplaySubject<string>(1) | 24 | private existsSubject = new ReplaySubject<string>(1) |
@@ -43,13 +45,46 @@ export class UserSubscriptionService { | |||
43 | ) | 45 | ) |
44 | } | 46 | } |
45 | 47 | ||
48 | listFollowers (parameters: { | ||
49 | pagination: ComponentPaginationLight | ||
50 | nameWithHost: string | ||
51 | search?: string | ||
52 | }) { | ||
53 | const { pagination, nameWithHost, search } = parameters | ||
54 | |||
55 | let url = `${UserSubscriptionService.BASE_ACCOUNTS_URL}/${nameWithHost}/followers` | ||
56 | |||
57 | let params = new HttpParams() | ||
58 | params = this.restService.addRestGetParams(params, this.restService.componentToRestPagination(pagination), '-createdAt') | ||
59 | |||
60 | if (search) { | ||
61 | const filters = this.restService.parseQueryStringFilter(search, { | ||
62 | channel: { | ||
63 | prefix: 'channel:' | ||
64 | } | ||
65 | }) | ||
66 | |||
67 | if (filters.channel) { | ||
68 | url = `${UserSubscriptionService.BASE_VIDEO_CHANNELS_URL}/${filters.channel}/followers` | ||
69 | } | ||
70 | |||
71 | params = this.restService.addObjectParams(params, { search: filters.search }) | ||
72 | } | ||
73 | |||
74 | return this.authHttp | ||
75 | .get<ResultList<ActorFollow>>(url, { params }) | ||
76 | .pipe( | ||
77 | catchError(err => this.restExtractor.handleError(err)) | ||
78 | ) | ||
79 | } | ||
80 | |||
46 | getUserSubscriptionVideos (parameters: { | 81 | getUserSubscriptionVideos (parameters: { |
47 | videoPagination: ComponentPaginationLight | 82 | videoPagination: ComponentPaginationLight |
48 | sort: VideoSortField | 83 | sort: VideoSortField |
49 | skipCount?: boolean | 84 | skipCount?: boolean |
50 | }): Observable<ResultList<Video>> { | 85 | }): Observable<ResultList<Video>> { |
51 | const { videoPagination, sort, skipCount } = parameters | 86 | const { videoPagination, sort, skipCount } = parameters |
52 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 87 | const pagination = this.restService.componentToRestPagination(videoPagination) |
53 | 88 | ||
54 | let params = new HttpParams() | 89 | let params = new HttpParams() |
55 | params = this.restService.addRestGetParams(params, pagination, sort) | 90 | params = this.restService.addRestGetParams(params, pagination, sort) |
@@ -106,7 +141,7 @@ export class UserSubscriptionService { | |||
106 | const { pagination, search } = parameters | 141 | const { pagination, search } = parameters |
107 | const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL | 142 | const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL |
108 | 143 | ||
109 | const restPagination = this.restService.componentPaginationToRestPagination(pagination) | 144 | const restPagination = this.restService.componentToRestPagination(pagination) |
110 | 145 | ||
111 | let params = new HttpParams() | 146 | let params = new HttpParams() |
112 | params = this.restService.addRestGetParams(params, restPagination) | 147 | params = this.restService.addRestGetParams(params, restPagination) |