1 import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
3 import { Account } from '@app/shared/account/account.model'
4 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
7 export class User implements UserServerModel {
11 pendingEmail: string | null
13 emailVerified: boolean
14 nsfwPolicy: NSFWPolicyType
16 adminFlags?: UserAdminFlag
18 autoPlayVideo: boolean
19 webTorrentEnabled: boolean
20 videosHistoryEnabled: boolean
21 videoLanguages: string[]
27 videoQuotaDaily: number
28 videoQuotaUsed?: number
29 videoQuotaUsedDaily?: number
34 notificationSettings?: UserNotificationSetting
35 videoChannels?: VideoChannel[]
38 blockedReason?: string
40 noInstanceConfigWarningModal: boolean
41 noWelcomeModal: boolean
45 constructor (hash: Partial<UserServerModel>) {
47 this.username = hash.username
48 this.email = hash.email
52 this.videoChannels = hash.videoChannels
54 this.videoQuota = hash.videoQuota
55 this.videoQuotaDaily = hash.videoQuotaDaily
56 this.videoQuotaUsed = hash.videoQuotaUsed
57 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
59 this.nsfwPolicy = hash.nsfwPolicy
60 this.webTorrentEnabled = hash.webTorrentEnabled
61 this.videosHistoryEnabled = hash.videosHistoryEnabled
62 this.autoPlayVideo = hash.autoPlayVideo
64 this.theme = hash.theme
66 this.adminFlags = hash.adminFlags
68 this.blocked = hash.blocked
69 this.blockedReason = hash.blockedReason
71 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
72 this.noWelcomeModal = hash.noWelcomeModal
74 this.notificationSettings = hash.notificationSettings
76 this.createdAt = hash.createdAt
78 if (hash.account !== undefined) {
79 this.account = new Account(hash.account)
83 get accountAvatarUrl () {
84 if (!this.account) return ''
86 return this.account.avatarUrl
89 hasRight (right: UserRight) {
90 return hasUserRight(this.role, right)
93 patch (obj: UserServerModel) {
94 for (const key of Object.keys(obj)) {
98 if (obj.account !== undefined) {
99 this.account = new Account(obj.account)
103 updateAccountAvatar (newAccountAvatar: Avatar) {
104 this.account.updateAvatar(newAccountAvatar)