1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import { hasUserRight } from '@shared/core-utils/users'
6 User as UserServerModel,
8 UserNotificationSetting,
12 } from '@shared/models'
13 import { UserKeys } from '@root-helpers/user-keys'
15 export class User implements UserServerModel {
16 static KEYS = UserKeys
21 pendingEmail: string | null
23 emailVerified: boolean
24 nsfwPolicy: NSFWPolicyType
26 adminFlags?: UserAdminFlag
28 autoPlayVideo: boolean
29 autoPlayNextVideo: boolean
30 autoPlayNextVideoPlaylist: boolean
31 webTorrentEnabled: boolean
32 videosHistoryEnabled: boolean
33 videoLanguages: string[]
39 videoQuotaDaily: number
40 videoQuotaUsed?: number
41 videoQuotaUsedDaily?: number
44 videoCommentsCount?: number
47 abusesAcceptedCount?: number
48 abusesCreatedCount?: number
53 notificationSettings?: UserNotificationSetting
54 videoChannels?: VideoChannel[]
57 blockedReason?: string
59 noInstanceConfigWarningModal: boolean
60 noWelcomeModal: boolean
62 pluginAuth: string | null
64 lastLoginDate: Date | null
68 constructor (hash: Partial<UserServerModel>) {
70 this.username = hash.username
71 this.email = hash.email
75 this.videoChannels = hash.videoChannels
77 this.videoQuota = hash.videoQuota
78 this.videoQuotaDaily = hash.videoQuotaDaily
79 this.videoQuotaUsed = hash.videoQuotaUsed
80 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
81 this.videosCount = hash.videosCount
82 this.abusesCount = hash.abusesCount
83 this.abusesAcceptedCount = hash.abusesAcceptedCount
84 this.abusesCreatedCount = hash.abusesCreatedCount
85 this.videoCommentsCount = hash.videoCommentsCount
87 this.nsfwPolicy = hash.nsfwPolicy
88 this.webTorrentEnabled = hash.webTorrentEnabled
89 this.autoPlayVideo = hash.autoPlayVideo
90 this.autoPlayNextVideo = hash.autoPlayNextVideo
91 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
92 this.videosHistoryEnabled = hash.videosHistoryEnabled
93 this.videoLanguages = hash.videoLanguages
95 this.theme = hash.theme
97 this.adminFlags = hash.adminFlags
99 this.blocked = hash.blocked
100 this.blockedReason = hash.blockedReason
102 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
103 this.noWelcomeModal = hash.noWelcomeModal
105 this.notificationSettings = hash.notificationSettings
107 this.createdAt = hash.createdAt
109 this.pluginAuth = hash.pluginAuth
110 this.lastLoginDate = hash.lastLoginDate
112 if (hash.account !== undefined) {
113 this.account = new Account(hash.account)
117 get accountAvatarUrl () {
118 if (!this.account) return ''
120 return this.account.avatarUrl
123 hasRight (right: UserRight) {
124 return hasUserRight(this.role, right)
127 patch (obj: UserServerModel) {
128 for (const key of Object.keys(obj)) {
132 if (obj.account !== undefined) {
133 this.account = new Account(obj.account)
137 updateAccountAvatar (newAccountAvatar: Avatar) {
138 this.account.updateAvatar(newAccountAvatar)
141 isUploadDisabled () {
142 return this.videoQuota === 0 || this.videoQuotaDaily === 0