1 import { Actor as ActorServer } from '../../../../../shared/models/actors/actor.model'
2 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
3 import { getAbsoluteAPIUrl } from '@app/shared/misc/utils'
5 export abstract class Actor implements ActorServer {
11 followingCount: number
12 followersCount: number
13 createdAt: Date | string
14 updatedAt: Date | string
19 static GET_ACTOR_AVATAR_URL (actor: { avatar: Avatar }) {
20 const absoluteAPIUrl = getAbsoluteAPIUrl()
22 if (actor && actor.avatar) return absoluteAPIUrl + actor.avatar.path
24 return window.location.origin + '/client/assets/images/default-avatar.png'
27 static CREATE_BY_STRING (accountName: string, host: string) {
28 const absoluteAPIUrl = getAbsoluteAPIUrl()
29 const thisHost = new URL(absoluteAPIUrl).host
31 if (host.trim() === thisHost) return accountName
33 return accountName + '@' + host
36 protected constructor (hash: ActorServer) {
42 this.followingCount = hash.followingCount
43 this.followersCount = hash.followersCount
44 this.createdAt = new Date(hash.createdAt.toString())
45 this.updatedAt = new Date(hash.updatedAt.toString())
46 this.avatar = hash.avatar
48 this.updateComputedAttributes()
51 updateAvatar (newAvatar: Avatar) {
52 this.avatar = newAvatar
54 this.updateComputedAttributes()
57 private updateComputedAttributes () {
58 this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this)