]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { getAbsoluteAPIUrl } 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 C |
14 | createdAt: Date | string |
15 | updatedAt: Date | string | |
d3e91a5f | 16 | |
cdeddff1 | 17 | avatar: ActorImage |
d3e91a5f | 18 | |
cfde28ba C |
19 | isLocal: boolean |
20 | ||
d95d1559 | 21 | static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) { |
5fb2e288 | 22 | if (actor?.avatar?.url) return actor.avatar.url |
d3e91a5f | 23 | |
5fb2e288 C |
24 | if (actor && actor.avatar) { |
25 | const absoluteAPIUrl = getAbsoluteAPIUrl() | |
26 | ||
27 | return absoluteAPIUrl + actor.avatar.path | |
28 | } | |
cdeddff1 C |
29 | |
30 | return '' | |
d3e91a5f C |
31 | } |
32 | ||
e379f813 | 33 | static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) { |
d3e91a5f C |
34 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
35 | const thisHost = new URL(absoluteAPIUrl).host | |
36 | ||
e379f813 | 37 | if (host.trim() === thisHost && !forceHostname) return accountName |
d3e91a5f C |
38 | |
39 | return accountName + '@' + host | |
40 | } | |
41 | ||
94148c90 C |
42 | static IS_LOCAL (host: string) { |
43 | const absoluteAPIUrl = getAbsoluteAPIUrl() | |
44 | const thisHost = new URL(absoluteAPIUrl).host | |
45 | ||
46 | return host.trim() === thisHost | |
47 | } | |
48 | ||
126a6352 | 49 | protected constructor (hash: Partial<ServerActor>) { |
d3e91a5f | 50 | this.id = hash.id |
27ec473f C |
51 | this.url = hash.url ?? '' |
52 | this.name = hash.name ?? '' | |
53 | this.host = hash.host ?? '' | |
d3e91a5f C |
54 | this.followingCount = hash.followingCount |
55 | this.followersCount = hash.followersCount | |
8ca56654 C |
56 | |
57 | if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString()) | |
58 | if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString()) | |
59 | ||
d3e91a5f | 60 | this.avatar = hash.avatar |
94148c90 | 61 | this.isLocal = Actor.IS_LOCAL(this.host) |
d3e91a5f C |
62 | } |
63 | } |