]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/account.model.ts
Use account initial as default avatar (#4002)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / account.model.ts
CommitLineData
126a6352 1import { Account as ServerAccount, Actor as ServerActor, ActorImage } from '@shared/models'
67ed6552 2import { Actor } from './actor.model'
b1fa3eba 3
d3e91a5f 4export class Account extends Actor implements ServerAccount {
c5911fd3 5 displayName: string
2422c46b 6 description: string
ad9e39fb 7 nameWithHost: string
e379f813 8 nameWithHostForced: string
65b21c96
C
9 mutedByUser: boolean
10 mutedByInstance: boolean
11 mutedServerByUser: boolean
12 mutedServerByInstance: boolean
6b738c7a 13
79bd2632
C
14 userId?: number
15
126a6352 16 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
09790754 17 return Actor.GET_ACTOR_AVATAR_URL(actor)
c418d483 18 }
19
20 static GET_DEFAULT_AVATAR_URL () {
21 return `${window.location.origin}/client/assets/images/default-avatar-account.png`
22 }
23
6b738c7a 24 constructor (hash: ServerAccount) {
d3e91a5f
C
25 super(hash)
26
c418d483 27 this.updateComputedAttributes()
28
6b738c7a
C
29 this.displayName = hash.displayName
30 this.description = hash.description
79bd2632 31 this.userId = hash.userId
ad9e39fb 32 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
e379f813 33 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
af5767ff 34
65b21c96
C
35 this.mutedByUser = false
36 this.mutedByInstance = false
37 this.mutedServerByUser = false
38 this.mutedServerByInstance = false
6b738c7a 39 }
c418d483 40
f4796856 41 updateAvatar (newAvatar: ActorImage) {
c418d483 42 this.avatar = newAvatar
43
44 this.updateComputedAttributes()
45 }
46
1ea7da81
RK
47 resetAvatar () {
48 this.avatar = null
09790754 49 this.avatarUrl = null
1ea7da81
RK
50 }
51
c418d483 52 private updateComputedAttributes () {
53 this.avatarUrl = Account.GET_ACTOR_AVATAR_URL(this)
54 }
b1fa3eba 55}