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
15 updatedAt: Date | string
21 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
22 if (actor?.avatar?.url) return actor.avatar.url
24 if (actor && actor.avatar) {
25 const absoluteAPIUrl = getAbsoluteAPIUrl()
27 return absoluteAPIUrl + actor.avatar.path
33 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
34 const absoluteAPIUrl = getAbsoluteAPIUrl()
35 const thisHost = new URL(absoluteAPIUrl).host
37 if (host.trim() === thisHost && !forceHostname) return accountName
39 return accountName + '@' + host
42 static IS_LOCAL (host: string) {
43 const absoluteAPIUrl = getAbsoluteAPIUrl()
44 const thisHost = new URL(absoluteAPIUrl).host
46 return host.trim() === thisHost
49 protected constructor (hash: Partial<ServerActor>) {
51 this.url = hash.url ?? ''
52 this.name = hash.name ?? ''
53 this.host = hash.host ?? ''
54 this.followingCount = hash.followingCount
55 this.followersCount = hash.followersCount
57 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
58 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
60 this.avatar = hash.avatar
61 this.isLocal = Actor.IS_LOCAL(this.host)