1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import { hasUserRight } from '@shared/core-utils/users'
7 User as UserServerModel,
9 UserNotificationSetting,
13 } from '@shared/models'
15 export class User implements UserServerModel {
19 pendingEmail: string | null
21 emailVerified: boolean
22 nsfwPolicy: NSFWPolicyType
24 adminFlags?: UserAdminFlag
26 autoPlayVideo: boolean
27 autoPlayNextVideo: boolean
28 autoPlayNextVideoPlaylist: boolean
31 // FIXME: deprecated in 4.1
32 webTorrentEnabled: never
34 videosHistoryEnabled: boolean
35 videoLanguages: string[]
41 videoQuotaDaily: number
42 videoQuotaUsed?: number
43 videoQuotaUsedDaily?: number
46 videoCommentsCount?: number
49 abusesAcceptedCount?: number
50 abusesCreatedCount?: number
55 notificationSettings?: UserNotificationSetting
56 videoChannels?: VideoChannel[]
59 blockedReason?: string
61 noInstanceConfigWarningModal: boolean
62 noWelcomeModal: boolean
63 noAccountSetupWarningModal: boolean
65 pluginAuth: string | null
67 lastLoginDate: Date | null
71 constructor (hash: Partial<UserServerModel>) {
73 this.username = hash.username
74 this.email = hash.email
78 this.videoChannels = hash.videoChannels
80 this.videoQuota = hash.videoQuota
81 this.videoQuotaDaily = hash.videoQuotaDaily
82 this.videoQuotaUsed = hash.videoQuotaUsed
83 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
84 this.videosCount = hash.videosCount
85 this.abusesCount = hash.abusesCount
86 this.abusesAcceptedCount = hash.abusesAcceptedCount
87 this.abusesCreatedCount = hash.abusesCreatedCount
88 this.videoCommentsCount = hash.videoCommentsCount
90 this.nsfwPolicy = hash.nsfwPolicy
91 this.p2pEnabled = hash.p2pEnabled
92 this.autoPlayVideo = hash.autoPlayVideo
93 this.autoPlayNextVideo = hash.autoPlayNextVideo
94 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
95 this.videosHistoryEnabled = hash.videosHistoryEnabled
96 this.videoLanguages = hash.videoLanguages
98 this.theme = hash.theme
100 this.adminFlags = hash.adminFlags
102 this.blocked = hash.blocked
103 this.blockedReason = hash.blockedReason
105 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
106 this.noWelcomeModal = hash.noWelcomeModal
107 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
109 this.notificationSettings = hash.notificationSettings
111 this.createdAt = hash.createdAt
113 this.pluginAuth = hash.pluginAuth
114 this.lastLoginDate = hash.lastLoginDate
116 if (hash.account !== undefined) {
117 this.account = new Account(hash.account)
121 hasRight (right: UserRight) {
122 return hasUserRight(this.role, right)
125 patch (obj: UserServerModel) {
126 for (const key of Object.keys(obj)) {
130 if (obj.account !== undefined) {
131 this.account = new Account(obj.account)
135 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
136 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
137 else this.account.resetAvatar()
140 isUploadDisabled () {
141 return this.videoQuota === 0 || this.videoQuotaDaily === 0
144 isAutoBlocked (serverConfig: HTMLServerConfig) {
145 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
147 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST