]>
Commit | Line | Data |
---|---|---|
a282e4d8 | 1 | import { getAbsoluteAPIUrl, getAPIHost } from '@app/helpers' |
126a6352 | 2 | import { Actor as ServerActor, ActorImage } from '@shared/models' |
d3e91a5f | 3 | |
126a6352 | 4 | export abstract class Actor implements ServerActor { |
d3e91a5f | 5 | id: number |
d3e91a5f | 6 | name: string |
cdeddff1 | 7 | |
d3e91a5f | 8 | host: string |
cdeddff1 C |
9 | url: string |
10 | ||
d3e91a5f C |
11 | followingCount: number |
12 | followersCount: number | |
cdeddff1 | 13 | |
db400f44 | 14 | createdAt: Date | string |
d3e91a5f | 15 | |
d0800f76 | 16 | // TODO: remove, deprecated in 4.2 |
17 | avatar: never | |
18 | ||
19 | avatars: ActorImage[] | |
d3e91a5f | 20 | |
cfde28ba C |
21 | isLocal: boolean |
22 | ||
d0800f76 | 23 | static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size: number) { |
24 | const avatar = actor.avatars.sort((a, b) => a.width - b.width).find(a => a.width >= size) | |
d3e91a5f | 25 | |
d0800f76 | 26 | if (!avatar) return '' |
27 | if (avatar.url) return avatar.url | |
5fb2e288 | 28 | |
d0800f76 | 29 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
cdeddff1 | 30 | |
d0800f76 | 31 | return absoluteAPIUrl + avatar.path |
d3e91a5f C |
32 | } |
33 | ||
e379f813 | 34 | static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) { |
a282e4d8 | 35 | const thisHost = getAPIHost() |
d3e91a5f | 36 | |
e379f813 | 37 | if (host.trim() === thisHost && !forceHostname) return accountName |
d3e91a5f C |
38 | |
39 | return accountName + '@' + host | |
40 | } | |
41 | ||
94148c90 | 42 | static IS_LOCAL (host: string) { |
a282e4d8 | 43 | const thisHost = getAPIHost() |
94148c90 C |
44 | |
45 | return host.trim() === thisHost | |
46 | } | |
47 | ||
126a6352 | 48 | protected constructor (hash: Partial<ServerActor>) { |
d3e91a5f | 49 | this.id = hash.id |
27ec473f C |
50 | this.url = hash.url ?? '' |
51 | this.name = hash.name ?? '' | |
52 | this.host = hash.host ?? '' | |
d3e91a5f C |
53 | this.followingCount = hash.followingCount |
54 | this.followersCount = hash.followersCount | |
8ca56654 C |
55 | |
56 | if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString()) | |
8ca56654 | 57 | |
d0800f76 | 58 | this.avatars = hash.avatars |
94148c90 | 59 | this.isLocal = Actor.IS_LOCAL(this.host) |
d3e91a5f C |
60 | } |
61 | } |