]>
Commit | Line | Data |
---|---|---|
1 | import { Account as ServerAccount, Actor as ServerActor, ActorImage } from '@shared/models' | |
2 | import { Actor } from './actor.model' | |
3 | ||
4 | export class Account extends Actor implements ServerAccount { | |
5 | displayName: string | |
6 | description: string | |
7 | nameWithHost: string | |
8 | nameWithHostForced: string | |
9 | mutedByUser: boolean | |
10 | mutedByInstance: boolean | |
11 | mutedServerByUser: boolean | |
12 | mutedServerByInstance: boolean | |
13 | ||
14 | userId?: number | |
15 | ||
16 | static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) { | |
17 | return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL() | |
18 | } | |
19 | ||
20 | static GET_DEFAULT_AVATAR_URL () { | |
21 | return `${window.location.origin}/client/assets/images/default-avatar-account.png` | |
22 | } | |
23 | ||
24 | constructor (hash: ServerAccount) { | |
25 | super(hash) | |
26 | ||
27 | this.updateComputedAttributes() | |
28 | ||
29 | this.displayName = hash.displayName | |
30 | this.description = hash.description | |
31 | this.userId = hash.userId | |
32 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) | |
33 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) | |
34 | ||
35 | this.mutedByUser = false | |
36 | this.mutedByInstance = false | |
37 | this.mutedServerByUser = false | |
38 | this.mutedServerByInstance = false | |
39 | } | |
40 | ||
41 | updateAvatar (newAvatar: ActorImage) { | |
42 | this.avatar = newAvatar | |
43 | ||
44 | this.updateComputedAttributes() | |
45 | } | |
46 | ||
47 | resetAvatar () { | |
48 | this.avatar = null | |
49 | this.avatarUrl = Account.GET_DEFAULT_AVATAR_URL() | |
50 | } | |
51 | ||
52 | private updateComputedAttributes () { | |
53 | this.avatarUrl = Account.GET_ACTOR_AVATAR_URL(this) | |
54 | } | |
55 | } |