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 videoQuotaDaily?: number,
20 nsfwPolicy?: NSFWPolicyType,
21 autoPlayVideo?: boolean,
23 account?: AccountServerModel,
24 videoChannels?: VideoChannel[]
27 blockedReason?: string
29 export class User implements UserServerModel {
34 nsfwPolicy: NSFWPolicyType
35 autoPlayVideo: boolean
37 videoQuotaDaily: number
39 videoChannels: VideoChannel[]
43 blockedReason?: string
45 constructor (hash: UserConstructorHash) {
47 this.username = hash.username
48 this.email = hash.email
51 this.videoChannels = hash.videoChannels
52 this.videoQuota = hash.videoQuota
53 this.videoQuotaDaily = hash.videoQuotaDaily
54 this.nsfwPolicy = hash.nsfwPolicy
55 this.autoPlayVideo = hash.autoPlayVideo
56 this.createdAt = hash.createdAt
57 this.blocked = hash.blocked
58 this.blockedReason = hash.blockedReason
60 if (hash.account !== undefined) {
61 this.account = new Account(hash.account)
65 get accountAvatarUrl () {
66 if (!this.account) return ''
68 return this.account.avatarUrl
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)
85 updateAccountAvatar (newAccountAvatar: Avatar) {
86 this.account.updateAvatar(newAccountAvatar)