1 import { Actor as ActorServer, ActorImage } from '@shared/models'
2 import { getAbsoluteAPIUrl } from '@app/helpers'
4 export abstract class Actor implements ActorServer {
11 followingCount: number
12 followersCount: number
14 createdAt: Date | string
15 updatedAt: Date | string
22 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
23 if (actor?.avatar?.url) return actor.avatar.url
25 if (actor && actor.avatar) {
26 const absoluteAPIUrl = getAbsoluteAPIUrl()
28 return absoluteAPIUrl + actor.avatar.path
34 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
35 const absoluteAPIUrl = getAbsoluteAPIUrl()
36 const thisHost = new URL(absoluteAPIUrl).host
38 if (host.trim() === thisHost && !forceHostname) return accountName
40 return accountName + '@' + host
43 static IS_LOCAL (host: string) {
44 const absoluteAPIUrl = getAbsoluteAPIUrl()
45 const thisHost = new URL(absoluteAPIUrl).host
47 return host.trim() === thisHost
50 protected constructor (hash: ActorServer) {
55 this.followingCount = hash.followingCount
56 this.followersCount = hash.followersCount
58 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
59 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
61 this.avatar = hash.avatar
62 this.isLocal = Actor.IS_LOCAL(this.host)