From 030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 Mon Sep 17 00:00:00 2001 From: Kimsible Date: Mon, 3 May 2021 19:03:08 +0200 Subject: Use userId key to distinct Account or VideoChannel actor --- .../shared/shared-main/account/actor.service.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'client/src/app/shared/shared-main') 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' import { RestExtractor } from '@app/core' import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models' import { environment } from '../../../../environments/environment' -import { Account } from './account.model' -import { VideoChannel } from '../video-channel/video-channel.model' + +type KeysOfUnion = T extends T ? keyof T: never +type ServerActor = KeysOfUnion @Injectable() export class ActorService { static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/' - actorLoaded = new ReplaySubject(1) + actorLoaded = new ReplaySubject(1) constructor ( private authHttp: HttpClient, private restExtractor: RestExtractor ) {} - getActor (actorName: string): Observable { - return this.authHttp.get(ActorService.BASE_ACTOR_API_URL + actorName) + getActorType (actorName: string): Observable { + return this.authHttp.get(ActorService.BASE_ACTOR_API_URL + actorName) .pipe( map(actorHash => { - const isAccount = /\/accounts\/.+/.test(actorHash.url) - const isVideoChannel = /\/video-channels\/.+/.test(actorHash.url) - - if (isAccount) { - return new Account(actorHash) + if (actorHash[ 'userId' ]) { + return 'Account' } - if (isVideoChannel) { - return new VideoChannel(actorHash) - } + return 'VideoChannel' }), tap(actor => this.actorLoaded.next(actor)), catchError(res => this.restExtractor.handleError(res)) -- cgit v1.2.3