]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/account/actor.model.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor.model.ts
index 0fa161ce6fc3a1f6e25685089cd47bde44ab51ac..2fccc472a64fe4e87bedf9ba14200f61c89005b3 100644 (file)
@@ -1,18 +1,21 @@
-import { Actor as ActorServer, Avatar } from '@shared/models'
 import { getAbsoluteAPIUrl } from '@app/helpers'
+import { Actor as ServerActor, ActorImage } from '@shared/models'
 
-export abstract class Actor implements ActorServer {
+export abstract class Actor implements ServerActor {
   id: number
-  url: string
   name: string
+
   host: string
+  url: string
+
   followingCount: number
   followersCount: number
+
   createdAt: Date | string
-  updatedAt: Date | string
-  avatar: Avatar
 
-  avatarUrl: string
+  avatar: ActorImage
+
+  isLocal: boolean
 
   static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
     if (actor?.avatar?.url) return actor.avatar.url
@@ -23,11 +26,7 @@ export abstract class Actor implements ActorServer {
       return absoluteAPIUrl + actor.avatar.path
     }
 
-    return this.GET_DEFAULT_AVATAR_URL()
-  }
-
-  static GET_DEFAULT_AVATAR_URL () {
-    return window.location.origin + '/client/assets/images/default-avatar.png'
+    return ''
   }
 
   static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
@@ -39,27 +38,24 @@ export abstract class Actor implements ActorServer {
     return accountName + '@' + host
   }
 
-  protected constructor (hash: ActorServer) {
-    this.id = hash.id
-    this.url = hash.url
-    this.name = hash.name
-    this.host = hash.host
-    this.followingCount = hash.followingCount
-    this.followersCount = hash.followersCount
-    this.createdAt = new Date(hash.createdAt.toString())
-    this.updatedAt = new Date(hash.updatedAt.toString())
-    this.avatar = hash.avatar
+  static IS_LOCAL (host: string) {
+    const absoluteAPIUrl = getAbsoluteAPIUrl()
+    const thisHost = new URL(absoluteAPIUrl).host
 
-    this.updateComputedAttributes()
+    return host.trim() === thisHost
   }
 
-  updateAvatar (newAvatar: Avatar) {
-    this.avatar = newAvatar
+  protected constructor (hash: Partial<ServerActor>) {
+    this.id = hash.id
+    this.url = hash.url ?? ''
+    this.name = hash.name ?? ''
+    this.host = hash.host ?? ''
+    this.followingCount = hash.followingCount
+    this.followersCount = hash.followersCount
 
-    this.updateComputedAttributes()
-  }
+    if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
 
-  private updateComputedAttributes () {
-    this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this)
+    this.avatar = hash.avatar
+    this.isLocal = Actor.IS_LOCAL(this.host)
   }
 }