]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor.model.ts
Add new default different avatar for channel and account
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor.model.ts
CommitLineData
67ed6552
C
1import { Actor as ActorServer, Avatar } from '@shared/models'
2import { getAbsoluteAPIUrl } from '@app/helpers'
d3e91a5f
C
3
4export abstract class Actor implements ActorServer {
5 id: number
d3e91a5f
C
6 url: string
7 name: string
8 host: string
9 followingCount: number
10 followersCount: number
db400f44
C
11 createdAt: Date | string
12 updatedAt: Date | string
d3e91a5f
C
13 avatar: Avatar
14
15 avatarUrl: string
16
cfde28ba
C
17 isLocal: boolean
18
d95d1559 19 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
5fb2e288 20 if (actor?.avatar?.url) return actor.avatar.url
d3e91a5f 21
5fb2e288
C
22 if (actor && actor.avatar) {
23 const absoluteAPIUrl = getAbsoluteAPIUrl()
24
25 return absoluteAPIUrl + actor.avatar.path
26 }
d3e91a5f
C
27 }
28
e379f813 29 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
d3e91a5f
C
30 const absoluteAPIUrl = getAbsoluteAPIUrl()
31 const thisHost = new URL(absoluteAPIUrl).host
32
e379f813 33 if (host.trim() === thisHost && !forceHostname) return accountName
d3e91a5f
C
34
35 return accountName + '@' + host
36 }
37
94148c90
C
38 static IS_LOCAL (host: string) {
39 const absoluteAPIUrl = getAbsoluteAPIUrl()
40 const thisHost = new URL(absoluteAPIUrl).host
41
42 return host.trim() === thisHost
43 }
44
d3e91a5f
C
45 protected constructor (hash: ActorServer) {
46 this.id = hash.id
d3e91a5f
C
47 this.url = hash.url
48 this.name = hash.name
49 this.host = hash.host
50 this.followingCount = hash.followingCount
51 this.followersCount = hash.followersCount
8ca56654
C
52
53 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
54 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
55
d3e91a5f 56 this.avatar = hash.avatar
94148c90 57 this.isLocal = Actor.IS_LOCAL(this.host)
d3e91a5f
C
58 }
59}