]>
Commit | Line | Data |
---|---|---|
1 | import { Account as ServerAccount, ActorImage, BlockStatus } 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 | ||
8 | updatedAt: Date | string | |
9 | ||
10 | nameWithHost: string | |
11 | nameWithHostForced: string | |
12 | ||
13 | mutedByUser: boolean | |
14 | mutedByInstance: boolean | |
15 | mutedServerByUser: boolean | |
16 | mutedServerByInstance: boolean | |
17 | ||
18 | userId?: number | |
19 | ||
20 | static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) { | |
21 | return Actor.GET_ACTOR_AVATAR_URL(actor) | |
22 | } | |
23 | ||
24 | static GET_DEFAULT_AVATAR_URL () { | |
25 | return `${window.location.origin}/client/assets/images/default-avatar-account.png` | |
26 | } | |
27 | ||
28 | constructor (hash: ServerAccount) { | |
29 | super(hash) | |
30 | ||
31 | this.displayName = hash.displayName | |
32 | this.description = hash.description | |
33 | this.userId = hash.userId | |
34 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) | |
35 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) | |
36 | ||
37 | if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString()) | |
38 | ||
39 | this.mutedByUser = false | |
40 | this.mutedByInstance = false | |
41 | this.mutedServerByUser = false | |
42 | this.mutedServerByInstance = false | |
43 | } | |
44 | ||
45 | updateAvatar (newAvatar: ActorImage) { | |
46 | this.avatar = newAvatar | |
47 | } | |
48 | ||
49 | resetAvatar () { | |
50 | this.avatar = null | |
51 | } | |
52 | ||
53 | updateBlockStatus (blockStatus: BlockStatus) { | |
54 | this.mutedByInstance = blockStatus.accounts[this.nameWithHostForced].blockedByServer | |
55 | this.mutedByUser = blockStatus.accounts[this.nameWithHostForced].blockedByUser | |
56 | this.mutedServerByUser = blockStatus.hosts[this.host].blockedByUser | |
57 | this.mutedServerByInstance = blockStatus.hosts[this.host].blockedByServer | |
58 | } | |
59 | } |