1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Actor as ServerActor, ActorImage } from '@shared/models'
4 export abstract class Actor implements ServerActor {
11 followingCount: number
12 followersCount: number
14 createdAt: Date | string
20 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
21 if (actor?.avatar?.url) return actor.avatar.url
24 const absoluteAPIUrl = getAbsoluteAPIUrl()
26 return absoluteAPIUrl + actor.avatar.path
32 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
33 const absoluteAPIUrl = getAbsoluteAPIUrl()
34 const thisHost = new URL(absoluteAPIUrl).host
36 if (host.trim() === thisHost && !forceHostname) return accountName
38 return accountName + '@' + host
41 static IS_LOCAL (host: string) {
42 const absoluteAPIUrl = getAbsoluteAPIUrl()
43 const thisHost = new URL(absoluteAPIUrl).host
45 return host.trim() === thisHost
48 protected constructor (hash: Partial<ServerActor>) {
50 this.url = hash.url ?? ''
51 this.name = hash.name ?? ''
52 this.host = hash.host ?? ''
53 this.followingCount = hash.followingCount
54 this.followersCount = hash.followersCount
56 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
58 this.avatar = hash.avatar
59 this.isLocal = Actor.IS_LOCAL(this.host)