aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/user-subscription/user-subscription.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-23 17:58:39 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitf37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch)
tree2050443febcdb2a3eec68b7bbf9687e26dcb24dc /client/src/app/shared/user-subscription/user-subscription.service.ts
parent240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff)
downloadPeerTube-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.ts47
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 @@
1import { catchError, map } from 'rxjs/operators' 1import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http' 2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { ResultList } from '../../../../../shared' 4import { ResultList } from '../../../../../shared'
5import { environment } from '../../../environments/environment' 5import { environment } from '../../../environments/environment'
6import { RestExtractor } from '../rest' 6import { RestExtractor, RestService } from '../rest'
7import { Observable, of } from 'rxjs' 7import { Observable, ReplaySubject, Subject } from 'rxjs'
8import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' 9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
10import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' 10import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
11 11
12type SubscriptionExistResult = { [ uri: string ]: boolean }
13
12@Injectable() 14@Injectable()
13export class UserSubscriptionService { 15export 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}