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'
13 export type UserConstructorHash = {
19 nsfwPolicy?: NSFWPolicyType,
20 autoPlayVideo?: boolean,
22 account?: AccountServerModel,
23 videoChannels?: VideoChannel[]
25 export class User implements UserServerModel {
30 nsfwPolicy: NSFWPolicyType
31 autoPlayVideo: boolean
34 videoChannels: VideoChannel[]
36 accountAvatarUrl: string
38 constructor (hash: UserConstructorHash) {
40 this.username = hash.username
41 this.email = hash.email
44 if (hash.account !== undefined) {
45 this.account = new Account(hash.account)
48 if (hash.videoChannels !== undefined) {
49 this.videoChannels = hash.videoChannels
52 if (hash.videoQuota !== undefined) {
53 this.videoQuota = hash.videoQuota
56 if (hash.nsfwPolicy !== undefined) {
57 this.nsfwPolicy = hash.nsfwPolicy
60 if (hash.autoPlayVideo !== undefined) {
61 this.autoPlayVideo = hash.autoPlayVideo
64 if (hash.createdAt !== undefined) {
65 this.createdAt = hash.createdAt
68 this.updateComputedAttributes()
71 hasRight (right: UserRight) {
72 return hasUserRight(this.role, right)
75 patch (obj: UserServerModel) {
76 for (const key of Object.keys(obj)) {
80 if (obj.account !== undefined) {
81 this.account = new Account(obj.account)
84 this.updateComputedAttributes()
87 private updateComputedAttributes () {
88 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)