]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor.model.ts
Fix report modal error
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor.model.ts
CommitLineData
67ed6552 1import { getAbsoluteAPIUrl } from '@app/helpers'
126a6352 2import { Actor as ServerActor, ActorImage } from '@shared/models'
d3e91a5f 3
126a6352 4export 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
cdeddff1 16 avatar: ActorImage
d3e91a5f 17
cfde28ba
C
18 isLocal: boolean
19
d95d1559 20 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
5fb2e288 21 if (actor?.avatar?.url) return actor.avatar.url
d3e91a5f 22
9df52d66 23 if (actor?.avatar) {
5fb2e288
C
24 const absoluteAPIUrl = getAbsoluteAPIUrl()
25
26 return absoluteAPIUrl + actor.avatar.path
27 }
cdeddff1
C
28
29 return ''
d3e91a5f
C
30 }
31
e379f813 32 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
d3e91a5f
C
33 const absoluteAPIUrl = getAbsoluteAPIUrl()
34 const thisHost = new URL(absoluteAPIUrl).host
35
e379f813 36 if (host.trim() === thisHost && !forceHostname) return accountName
d3e91a5f
C
37
38 return accountName + '@' + host
39 }
40
94148c90
C
41 static IS_LOCAL (host: string) {
42 const absoluteAPIUrl = getAbsoluteAPIUrl()
43 const thisHost = new URL(absoluteAPIUrl).host
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
d3e91a5f 58 this.avatar = hash.avatar
94148c90 59 this.isLocal = Actor.IS_LOCAL(this.host)
d3e91a5f
C
60 }
61}