diff options
author | Kimsible <kimsible@users.noreply.github.com> | 2021-05-03 19:03:08 +0200 |
---|---|---|
committer | Kimsible <kimsible@users.noreply.github.com> | 2021-05-05 11:48:25 +0200 |
commit | 030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (patch) | |
tree | 447ad863f826f964bcaf9405a5002b45b538c27d /client/src/app/shared/shared-main | |
parent | 718873964490d1aa31b0e99852002165637e4b9e (diff) | |
download | PeerTube-030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2.tar.gz PeerTube-030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2.tar.zst PeerTube-030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2.zip |
Use userId key to distinct Account or VideoChannel actor
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r-- | client/src/app/shared/shared-main/account/actor.service.ts | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/client/src/app/shared/shared-main/account/actor.service.ts b/client/src/app/shared/shared-main/account/actor.service.ts index a789b6f5b..464ed4519 100644 --- a/client/src/app/shared/shared-main/account/actor.service.ts +++ b/client/src/app/shared/shared-main/account/actor.service.ts | |||
@@ -5,34 +5,30 @@ import { Injectable } from '@angular/core' | |||
5 | import { RestExtractor } from '@app/core' | 5 | import { RestExtractor } from '@app/core' |
6 | import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models' | 6 | import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models' |
7 | import { environment } from '../../../../environments/environment' | 7 | import { environment } from '../../../../environments/environment' |
8 | import { Account } from './account.model' | 8 | |
9 | import { VideoChannel } from '../video-channel/video-channel.model' | 9 | type KeysOfUnion<T> = T extends T ? keyof T: never |
10 | type ServerActor = KeysOfUnion<ServerAccount | ServerVideoChannel> | ||
10 | 11 | ||
11 | @Injectable() | 12 | @Injectable() |
12 | export class ActorService { | 13 | export class ActorService { |
13 | static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/' | 14 | static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/' |
14 | 15 | ||
15 | actorLoaded = new ReplaySubject<Account | VideoChannel>(1) | 16 | actorLoaded = new ReplaySubject<string>(1) |
16 | 17 | ||
17 | constructor ( | 18 | constructor ( |
18 | private authHttp: HttpClient, | 19 | private authHttp: HttpClient, |
19 | private restExtractor: RestExtractor | 20 | private restExtractor: RestExtractor |
20 | ) {} | 21 | ) {} |
21 | 22 | ||
22 | getActor (actorName: string): Observable<Account | VideoChannel> { | 23 | getActorType (actorName: string): Observable<string> { |
23 | return this.authHttp.get<ServerAccount | ServerVideoChannel>(ActorService.BASE_ACTOR_API_URL + actorName) | 24 | return this.authHttp.get<ServerActor>(ActorService.BASE_ACTOR_API_URL + actorName) |
24 | .pipe( | 25 | .pipe( |
25 | map(actorHash => { | 26 | map(actorHash => { |
26 | const isAccount = /\/accounts\/.+/.test(actorHash.url) | 27 | if (actorHash[ 'userId' ]) { |
27 | const isVideoChannel = /\/video-channels\/.+/.test(actorHash.url) | 28 | return 'Account' |
28 | |||
29 | if (isAccount) { | ||
30 | return new Account(actorHash) | ||
31 | } | 29 | } |
32 | 30 | ||
33 | if (isVideoChannel) { | 31 | return 'VideoChannel' |
34 | return new VideoChannel(actorHash) | ||
35 | } | ||
36 | }), | 32 | }), |
37 | tap(actor => this.actorLoaded.next(actor)), | 33 | tap(actor => this.actorLoaded.next(actor)), |
38 | catchError(res => this.restExtractor.handleError(res)) | 34 | catchError(res => this.restExtractor.handleError(res)) |