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[]
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
69 get accountAvatarUrl () {
70 if (!this.account) return ''
72 return this.account.avatarUrl
75 hasRight (right: UserRight) {
76 return hasUserRight(this.role, right)
79 patch (obj: UserServerModel) {
80 for (const key of Object.keys(obj)) {
84 if (obj.account !== undefined) {
85 this.account = new Account(obj.account)
89 updateAccountAvatar (newAccountAvatar: Avatar) {
90 this.account.updateAvatar(newAccountAvatar)