]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/account/account.model.ts
Update video channel routes
[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 constructor (hash: ServerAccount) {
20 this.id = hash.id
21 this.uuid = hash.uuid
22 this.url = hash.url
23 this.name = hash.name
24 this.displayName = hash.displayName
25 this.description = hash.description
26 this.host = hash.host
27 this.followingCount = hash.followingCount
28 this.followersCount = hash.followersCount
29 this.createdAt = new Date(hash.createdAt.toString())
30 this.updatedAt = new Date(hash.updatedAt.toString())
31 this.avatar = hash.avatar
32 }
33
34 static GET_ACCOUNT_AVATAR_URL (account: Account) {
35 const absoluteAPIUrl = getAbsoluteAPIUrl()
36
37 if (account && account.avatar) return absoluteAPIUrl + account.avatar.path
38
39 return window.location.origin + '/client/assets/images/default-avatar.png'
40 }
41
42 static CREATE_BY_STRING (accountName: string, host: string) {
43 const absoluteAPIUrl = getAbsoluteAPIUrl()
44 const thisHost = new URL(absoluteAPIUrl).host
45
46 if (host.trim() === thisHost) return accountName
47
48 return accountName + '@' + host
49 }
50 }