1 import { Account as ServerAccount, ActorImage, BlockStatus } from '@shared/models'
2 import { Actor } from './actor.model'
4 export class Account extends Actor implements ServerAccount {
8 updatedAt: Date | string
11 nameWithHostForced: string
14 mutedByInstance: boolean
15 mutedServerByUser: boolean
16 mutedServerByInstance: boolean
20 static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size?: number) {
21 return Actor.GET_ACTOR_AVATAR_URL(actor, size)
24 static GET_DEFAULT_AVATAR_URL (size?: number) {
25 if (size && size <= 48) {
26 return `${window.location.origin}/client/assets/images/default-avatar-account-48x48.png`
29 return `${window.location.origin}/client/assets/images/default-avatar-account.png`
32 constructor (hash: ServerAccount) {
35 this.displayName = hash.displayName
36 this.description = hash.description
37 this.userId = hash.userId
38 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
39 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
41 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
43 this.mutedByUser = false
44 this.mutedByInstance = false
45 this.mutedServerByUser = false
46 this.mutedServerByInstance = false
49 updateAvatar (newAvatars: ActorImage[]) {
50 this.avatars = newAvatars
57 updateBlockStatus (blockStatus: BlockStatus) {
58 this.mutedByInstance = blockStatus.accounts[this.nameWithHostForced].blockedByServer
59 this.mutedByUser = blockStatus.accounts[this.nameWithHostForced].blockedByUser
60 this.mutedServerByUser = blockStatus.hosts[this.host].blockedByUser
61 this.mutedServerByInstance = blockStatus.hosts[this.host].blockedByServer