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
29 webTorrentEnabled: boolean
30 videosHistoryEnabled: boolean
31 videoLanguages: string[]
37 videoQuotaDaily: number
38 videoQuotaUsed?: number
39 videoQuotaUsedDaily?: number
42 videoCommentsCount?: number
45 abusesAcceptedCount?: number
46 abusesCreatedCount?: number
51 notificationSettings?: UserNotificationSetting
52 videoChannels?: VideoChannel[]
55 blockedReason?: string
57 noInstanceConfigWarningModal: boolean
58 noWelcomeModal: boolean
59 noAccountSetupWarningModal: boolean
61 pluginAuth: string | null
63 lastLoginDate: Date | null
67 constructor (hash: Partial<UserServerModel>) {
69 this.username = hash.username
70 this.email = hash.email
74 this.videoChannels = hash.videoChannels
76 this.videoQuota = hash.videoQuota
77 this.videoQuotaDaily = hash.videoQuotaDaily
78 this.videoQuotaUsed = hash.videoQuotaUsed
79 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
80 this.videosCount = hash.videosCount
81 this.abusesCount = hash.abusesCount
82 this.abusesAcceptedCount = hash.abusesAcceptedCount
83 this.abusesCreatedCount = hash.abusesCreatedCount
84 this.videoCommentsCount = hash.videoCommentsCount
86 this.nsfwPolicy = hash.nsfwPolicy
87 this.webTorrentEnabled = hash.webTorrentEnabled
88 this.autoPlayVideo = hash.autoPlayVideo
89 this.autoPlayNextVideo = hash.autoPlayNextVideo
90 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
91 this.videosHistoryEnabled = hash.videosHistoryEnabled
92 this.videoLanguages = hash.videoLanguages
94 this.theme = hash.theme
96 this.adminFlags = hash.adminFlags
98 this.blocked = hash.blocked
99 this.blockedReason = hash.blockedReason
101 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
102 this.noWelcomeModal = hash.noWelcomeModal
103 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
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 hasRight (right: UserRight) {
118 return hasUserRight(this.role, right)
121 patch (obj: UserServerModel) {
122 for (const key of Object.keys(obj)) {
126 if (obj.account !== undefined) {
127 this.account = new Account(obj.account)
131 updateAccountAvatar (newAccountAvatar?: ActorImage) {
132 if (newAccountAvatar) this.account.updateAvatar(newAccountAvatar)
133 else this.account.resetAvatar()
136 isUploadDisabled () {
137 return this.videoQuota === 0 || this.videoQuotaDaily === 0
140 isAutoBlocked (serverConfig: HTMLServerConfig) {
141 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
143 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST