2 Account as AccountServerModel,
4 User as UserServerModel,
8 } from '../../../../../shared'
9 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
10 import { Actor } from '@app/shared/actor/actor.model'
11 import { Account } from '@app/shared/account/account.model'
12 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
14 export type UserConstructorHash = {
20 nsfwPolicy?: NSFWPolicyType,
21 autoPlayVideo?: boolean,
23 account?: AccountServerModel,
24 videoChannels?: VideoChannel[]
26 export class User implements UserServerModel {
31 nsfwPolicy: NSFWPolicyType
32 autoPlayVideo: boolean
35 videoChannels: VideoChannel[]
37 accountAvatarUrl: string
39 constructor (hash: UserConstructorHash) {
41 this.username = hash.username
42 this.email = hash.email
45 if (hash.account !== undefined) {
46 this.account = new Account(hash.account)
49 if (hash.videoChannels !== undefined) {
50 this.videoChannels = hash.videoChannels
53 if (hash.videoQuota !== undefined) {
54 this.videoQuota = hash.videoQuota
57 if (hash.nsfwPolicy !== undefined) {
58 this.nsfwPolicy = hash.nsfwPolicy
61 if (hash.autoPlayVideo !== undefined) {
62 this.autoPlayVideo = hash.autoPlayVideo
65 if (hash.createdAt !== undefined) {
66 this.createdAt = hash.createdAt
69 this.updateComputedAttributes()
72 hasRight (right: UserRight) {
73 return hasUserRight(this.role, right)
76 patch (obj: UserServerModel) {
77 for (const key of Object.keys(obj)) {
81 if (obj.account !== undefined) {
82 this.account = new Account(obj.account)
85 this.updateComputedAttributes()
88 updateAccountAvatar (newAccountAvatar: Avatar) {
89 this.account.avatar = newAccountAvatar
91 this.updateComputedAttributes()
94 private updateComputedAttributes () {
95 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)