]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Actor as ActorServer, Avatar } from '@shared/models'
2 import { getAbsoluteAPIUrl } from '@app/helpers'
3
4 export abstract class Actor implements ActorServer {
5 id: number
6 url: string
7 name: string
8 host: string
9 followingCount: number
10 followersCount: number
11 createdAt: Date | string
12 updatedAt: Date | string
13 avatar: Avatar
14
15 avatarUrl: string
16
17 isLocal: boolean
18
19 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
20 if (actor?.avatar?.url) return actor.avatar.url
21
22 if (actor && actor.avatar) {
23 const absoluteAPIUrl = getAbsoluteAPIUrl()
24
25 return absoluteAPIUrl + actor.avatar.path
26 }
27 }
28
29 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
30 const absoluteAPIUrl = getAbsoluteAPIUrl()
31 const thisHost = new URL(absoluteAPIUrl).host
32
33 if (host.trim() === thisHost && !forceHostname) return accountName
34
35 return accountName + '@' + host
36 }
37
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
45 protected constructor (hash: ActorServer) {
46 this.id = hash.id
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
52
53 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
54 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
55
56 this.avatar = hash.avatar
57 this.isLocal = Actor.IS_LOCAL(this.host)
58 }
59 }