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