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 = {
18 emailVerified?: boolean,
20 videoQuotaDaily?: number,
21 nsfwPolicy?: NSFWPolicyType,
22 webTorrentEnabled?: boolean,
23 autoPlayVideo?: boolean,
25 account?: AccountServerModel,
26 videoChannels?: VideoChannel[]
29 blockedReason?: string
31 export class User implements UserServerModel {
35 emailVerified: boolean
37 nsfwPolicy: NSFWPolicyType
38 webTorrentEnabled: boolean
39 autoPlayVideo: boolean
41 videoQuotaDaily: number
43 videoChannels: VideoChannel[]
47 blockedReason?: string
49 constructor (hash: UserConstructorHash) {
51 this.username = hash.username
52 this.email = hash.email
55 this.videoChannels = hash.videoChannels
56 this.videoQuota = hash.videoQuota
57 this.videoQuotaDaily = hash.videoQuotaDaily
58 this.nsfwPolicy = hash.nsfwPolicy
59 this.webTorrentEnabled = hash.webTorrentEnabled
60 this.autoPlayVideo = hash.autoPlayVideo
61 this.createdAt = hash.createdAt
62 this.blocked = hash.blocked
63 this.blockedReason = hash.blockedReason
65 if (hash.account !== undefined) {
66 this.account = new Account(hash.account)
70 get accountAvatarUrl () {
71 if (!this.account) return ''
73 return this.account.avatarUrl
76 hasRight (right: UserRight) {
77 return hasUserRight(this.role, right)
80 patch (obj: UserServerModel) {
81 for (const key of Object.keys(obj)) {
85 if (obj.account !== undefined) {
86 this.account = new Account(obj.account)
90 updateAccountAvatar (newAccountAvatar: Avatar) {
91 this.account.updateAvatar(newAccountAvatar)