1 import { Actor as ActorServer, Avatar } from '@shared/models'
2 import { getAbsoluteAPIUrl } from '@app/helpers'
4 export abstract class Actor implements ActorServer {
10 followersCount: number
11 createdAt: Date | string
12 updatedAt: Date | string
19 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
20 if (actor?.avatar?.url) return actor.avatar.url
22 if (actor && actor.avatar) {
23 const absoluteAPIUrl = getAbsoluteAPIUrl()
25 return absoluteAPIUrl + actor.avatar.path
29 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
30 const absoluteAPIUrl = getAbsoluteAPIUrl()
31 const thisHost = new URL(absoluteAPIUrl).host
33 if (host.trim() === thisHost && !forceHostname) return accountName
35 return accountName + '@' + host
38 static IS_LOCAL (host: string) {
39 const absoluteAPIUrl = getAbsoluteAPIUrl()
40 const thisHost = new URL(absoluteAPIUrl).host
42 return host.trim() === thisHost
45 protected constructor (hash: ActorServer) {
50 this.followingCount = hash.followingCount
51 this.followersCount = hash.followersCount
53 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
54 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
56 this.avatar = hash.avatar
57 this.isLocal = Actor.IS_LOCAL(this.host)