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 {
10 followingCount: number
11 followersCount: number
12 createdAt: Date | string
13 updatedAt: Date | string
18 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { path: string } }) {
19 const absoluteAPIUrl = getAbsoluteAPIUrl()
21 if (actor && actor.avatar) return absoluteAPIUrl + actor.avatar.path
23 this.GET_DEFAULT_AVATAR_URL()
26 static GET_DEFAULT_AVATAR_URL () {
27 return window.location.origin + '/client/assets/images/default-avatar.png'
30 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
31 const absoluteAPIUrl = getAbsoluteAPIUrl()
32 const thisHost = new URL(absoluteAPIUrl).host
34 if (host.trim() === thisHost && !forceHostname) return accountName
36 return accountName + '@' + host
39 protected constructor (hash: ActorServer) {
44 this.followingCount = hash.followingCount
45 this.followersCount = hash.followersCount
46 this.createdAt = new Date(hash.createdAt.toString())
47 this.updatedAt = new Date(hash.updatedAt.toString())
48 this.avatar = hash.avatar
50 this.updateComputedAttributes()
53 updateAvatar (newAvatar: Avatar) {
54 this.avatar = newAvatar
56 this.updateComputedAttributes()
59 private updateComputedAttributes () {
60 this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this)