]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/account/account.model.ts
a26a9c11cc274f5f122f61e20f1fa702b29422e9
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / account.model.ts
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: { avatars: { width: number, url?: string, path: string }[] }, size: number) {
21 return Actor.GET_ACTOR_AVATAR_URL(actor, size)
22 }
23
24 static GET_DEFAULT_AVATAR_URL (size: number) {
25 if (size <= 48) {
26 return `${window.location.origin}/client/assets/images/default-avatar-account-48x48.png`
27 }
28
29 return `${window.location.origin}/client/assets/images/default-avatar-account.png`
30 }
31
32 constructor (hash: ServerAccount) {
33 super(hash)
34
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)
40
41 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
42
43 this.mutedByUser = false
44 this.mutedByInstance = false
45 this.mutedServerByUser = false
46 this.mutedServerByInstance = false
47 }
48
49 updateAvatar (newAvatars: ActorImage[]) {
50 this.avatars = newAvatars
51 }
52
53 resetAvatar () {
54 this.avatars = []
55 }
56
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
62 }
63 }