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'
14 export class User implements UserServerModel {
18 pendingEmail: string | null
20 emailVerified: boolean
21 nsfwPolicy: NSFWPolicyType
23 adminFlags?: UserAdminFlag
25 autoPlayVideo: boolean
26 autoPlayNextVideo: boolean
27 autoPlayNextVideoPlaylist: boolean
28 webTorrentEnabled: boolean
29 videosHistoryEnabled: boolean
30 videoLanguages: string[]
36 videoQuotaDaily: number
37 videoQuotaUsed?: number
38 videoQuotaUsedDaily?: number
41 videoCommentsCount?: number
44 abusesAcceptedCount?: number
45 abusesCreatedCount?: number
50 notificationSettings?: UserNotificationSetting
51 videoChannels?: VideoChannel[]
54 blockedReason?: string
56 noInstanceConfigWarningModal: boolean
57 noWelcomeModal: boolean
58 noAccountSetupWarningModal: boolean
60 pluginAuth: string | null
62 lastLoginDate: Date | null
66 constructor (hash: Partial<UserServerModel>) {
68 this.username = hash.username
69 this.email = hash.email
73 this.videoChannels = hash.videoChannels
75 this.videoQuota = hash.videoQuota
76 this.videoQuotaDaily = hash.videoQuotaDaily
77 this.videoQuotaUsed = hash.videoQuotaUsed
78 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
79 this.videosCount = hash.videosCount
80 this.abusesCount = hash.abusesCount
81 this.abusesAcceptedCount = hash.abusesAcceptedCount
82 this.abusesCreatedCount = hash.abusesCreatedCount
83 this.videoCommentsCount = hash.videoCommentsCount
85 this.nsfwPolicy = hash.nsfwPolicy
86 this.webTorrentEnabled = hash.webTorrentEnabled
87 this.autoPlayVideo = hash.autoPlayVideo
88 this.autoPlayNextVideo = hash.autoPlayNextVideo
89 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
90 this.videosHistoryEnabled = hash.videosHistoryEnabled
91 this.videoLanguages = hash.videoLanguages
93 this.theme = hash.theme
95 this.adminFlags = hash.adminFlags
97 this.blocked = hash.blocked
98 this.blockedReason = hash.blockedReason
100 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
101 this.noWelcomeModal = hash.noWelcomeModal
102 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
104 this.notificationSettings = hash.notificationSettings
106 this.createdAt = hash.createdAt
108 this.pluginAuth = hash.pluginAuth
109 this.lastLoginDate = hash.lastLoginDate
111 if (hash.account !== undefined) {
112 this.account = new Account(hash.account)
116 hasRight (right: UserRight) {
117 return hasUserRight(this.role, right)
120 patch (obj: UserServerModel) {
121 for (const key of Object.keys(obj)) {
125 if (obj.account !== undefined) {
126 this.account = new Account(obj.account)
130 updateAccountAvatar (newAccountAvatar?: ActorImage) {
131 if (newAccountAvatar) this.account.updateAvatar(newAccountAvatar)
132 else this.account.resetAvatar()
135 isUploadDisabled () {
136 return this.videoQuota === 0 || this.videoQuotaDaily === 0
140 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST