2 Account as AccountServerModel,
4 User as UserServerModel,
8 } from '../../../../../shared'
9 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
10 import { Account } from '@app/shared/account/account.model'
11 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
13 export type UserConstructorHash = {
19 nsfwPolicy?: NSFWPolicyType,
20 autoPlayVideo?: boolean,
22 account?: AccountServerModel,
23 videoChannels?: VideoChannel[]
26 blockedReason?: string
28 export class User implements UserServerModel {
33 nsfwPolicy: NSFWPolicyType
34 autoPlayVideo: boolean
37 videoChannels: VideoChannel[]
41 blockedReason?: string
43 constructor (hash: UserConstructorHash) {
45 this.username = hash.username
46 this.email = hash.email
49 this.videoChannels = hash.videoChannels
50 this.videoQuota = hash.videoQuota
51 this.nsfwPolicy = hash.nsfwPolicy
52 this.autoPlayVideo = hash.autoPlayVideo
53 this.createdAt = hash.createdAt
54 this.blocked = hash.blocked
55 this.blockedReason = hash.blockedReason
57 if (hash.account !== undefined) {
58 this.account = new Account(hash.account)
62 get accountAvatarUrl () {
63 if (!this.account) return ''
65 return this.account.avatarUrl
68 hasRight (right: UserRight) {
69 return hasUserRight(this.role, right)
72 patch (obj: UserServerModel) {
73 for (const key of Object.keys(obj)) {
77 if (obj.account !== undefined) {
78 this.account = new Account(obj.account)
82 updateAccountAvatar (newAccountAvatar: Avatar) {
83 this.account.updateAvatar(newAccountAvatar)