]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/account/account.model.ts
Video channel API routes refractor
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / account / account.model.ts
1 import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model'
2 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
3 import { getAbsoluteAPIUrl } from '../misc/utils'
4
5 export class Account implements ServerAccount {
6 id: number
7 uuid: string
8 url: string
9 name: string
10 displayName: string
11 description: string
12 host: string
13 followingCount: number
14 followersCount: number
15 createdAt: Date
16 updatedAt: Date
17 avatar: Avatar
18
19 static GET_ACCOUNT_AVATAR_URL (account: Account) {
20 const absoluteAPIUrl = getAbsoluteAPIUrl()
21
22 if (account && account.avatar) return absoluteAPIUrl + account.avatar.path
23
24 return window.location.origin + '/client/assets/images/default-avatar.png'
25 }
26
27 static CREATE_BY_STRING (accountName: string, host: string) {
28 const absoluteAPIUrl = getAbsoluteAPIUrl()
29 const thisHost = new URL(absoluteAPIUrl).host
30
31 if (host.trim() === thisHost) return accountName
32
33 return accountName + '@' + host
34 }
35
36 constructor (hash: ServerAccount) {
37 this.id = hash.id
38 this.uuid = hash.uuid
39 this.url = hash.url
40 this.name = hash.name
41 this.displayName = hash.displayName
42 this.description = hash.description
43 this.host = hash.host
44 this.followingCount = hash.followingCount
45 this.followersCount = hash.followersCount
46 this.createdAt = new Date(hash.createdAt.toString())
47 this.updatedAt = new Date(hash.updatedAt.toString())
48 this.avatar = hash.avatar
49 }
50 }