diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-23 17:58:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch) | |
tree | 2050443febcdb2a3eec68b7bbf9687e26dcb24dc /client/src/app/shared/user-subscription/user-subscription.service.ts | |
parent | 240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff) | |
download | PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.gz PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.zst PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.zip |
Add ability to search video channels
Diffstat (limited to 'client/src/app/shared/user-subscription/user-subscription.service.ts')
-rw-r--r-- | client/src/app/shared/user-subscription/user-subscription.service.ts | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/client/src/app/shared/user-subscription/user-subscription.service.ts b/client/src/app/shared/user-subscription/user-subscription.service.ts index 3103706d1..cf622019f 100644 --- a/client/src/app/shared/user-subscription/user-subscription.service.ts +++ b/client/src/app/shared/user-subscription/user-subscription.service.ts | |||
@@ -1,22 +1,36 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | 1 | import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' |
2 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { ResultList } from '../../../../../shared' | 4 | import { ResultList } from '../../../../../shared' |
5 | import { environment } from '../../../environments/environment' | 5 | import { environment } from '../../../environments/environment' |
6 | import { RestExtractor } from '../rest' | 6 | import { RestExtractor, RestService } from '../rest' |
7 | import { Observable, of } from 'rxjs' | 7 | import { Observable, ReplaySubject, Subject } from 'rxjs' |
8 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | 8 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
9 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 9 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
10 | import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' | 10 | import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' |
11 | 11 | ||
12 | type SubscriptionExistResult = { [ uri: string ]: boolean } | ||
13 | |||
12 | @Injectable() | 14 | @Injectable() |
13 | export class UserSubscriptionService { | 15 | export class UserSubscriptionService { |
14 | static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/users/me/subscriptions' | 16 | static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/users/me/subscriptions' |
15 | 17 | ||
18 | // Use a replay subject because we "next" a value before subscribing | ||
19 | private existsSubject: Subject<string> = new ReplaySubject(1) | ||
20 | private existsObservable: Observable<SubscriptionExistResult> | ||
21 | |||
16 | constructor ( | 22 | constructor ( |
17 | private authHttp: HttpClient, | 23 | private authHttp: HttpClient, |
18 | private restExtractor: RestExtractor | 24 | private restExtractor: RestExtractor, |
25 | private restService: RestService | ||
19 | ) { | 26 | ) { |
27 | this.existsObservable = this.existsSubject.pipe( | ||
28 | tap(u => console.log(u)), | ||
29 | bufferTime(500), | ||
30 | filter(uris => uris.length !== 0), | ||
31 | switchMap(uris => this.areSubscriptionExist(uris)), | ||
32 | share() | ||
33 | ) | ||
20 | } | 34 | } |
21 | 35 | ||
22 | deleteSubscription (nameWithHost: string) { | 36 | deleteSubscription (nameWithHost: string) { |
@@ -50,17 +64,20 @@ export class UserSubscriptionService { | |||
50 | ) | 64 | ) |
51 | } | 65 | } |
52 | 66 | ||
53 | isSubscriptionExists (nameWithHost: string): Observable<boolean> { | 67 | isSubscriptionExists (nameWithHost: string) { |
54 | const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/' + nameWithHost | 68 | this.existsSubject.next(nameWithHost) |
55 | 69 | ||
56 | return this.authHttp.get(url) | 70 | return this.existsObservable |
57 | .pipe( | 71 | } |
58 | map(this.restExtractor.extractDataBool), | ||
59 | catchError(err => { | ||
60 | if (err.status === 404) return of(false) | ||
61 | 72 | ||
62 | return this.restExtractor.handleError(err) | 73 | private areSubscriptionExist (uris: string[]): Observable<SubscriptionExistResult> { |
63 | }) | 74 | console.log(uris) |
64 | ) | 75 | const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/exist' |
76 | let params = new HttpParams() | ||
77 | |||
78 | params = this.restService.addObjectParams(params, { uris }) | ||
79 | |||
80 | return this.authHttp.get<SubscriptionExistResult>(url, { params }) | ||
81 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
65 | } | 82 | } |
66 | } | 83 | } |