]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/account/actor.service.ts
Merge branch 'develop' into shorter-URLs-channels-accounts
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor.service.ts
index a789b6f5b363f0eb81115814c0ab3d128e191a49..464ed45195507e412e207426a6a761d2bfd31133 100644 (file)
@@ -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> = T extends T ? keyof T: never
+type ServerActor = KeysOfUnion<ServerAccount | ServerVideoChannel>
 
 @Injectable()
 export class ActorService {
   static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/'
 
-  actorLoaded = new ReplaySubject<Account | VideoChannel>(1)
+  actorLoaded = new ReplaySubject<string>(1)
 
   constructor (
     private authHttp: HttpClient,
     private restExtractor: RestExtractor
   ) {}
 
-  getActor (actorName: string): Observable<Account | VideoChannel> {
-    return this.authHttp.get<ServerAccount | ServerVideoChannel>(ActorService.BASE_ACTOR_API_URL + actorName)
+  getActorType (actorName: string): Observable<string> {
+    return this.authHttp.get<ServerActor>(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))