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
59 pluginAuth: string | null
61 lastLoginDate: Date | null
65 constructor (hash: Partial<UserServerModel>) {
67 this.username = hash.username
68 this.email = hash.email
72 this.videoChannels = hash.videoChannels
74 this.videoQuota = hash.videoQuota
75 this.videoQuotaDaily = hash.videoQuotaDaily
76 this.videoQuotaUsed = hash.videoQuotaUsed
77 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
78 this.videosCount = hash.videosCount
79 this.abusesCount = hash.abusesCount
80 this.abusesAcceptedCount = hash.abusesAcceptedCount
81 this.abusesCreatedCount = hash.abusesCreatedCount
82 this.videoCommentsCount = hash.videoCommentsCount
84 this.nsfwPolicy = hash.nsfwPolicy
85 this.webTorrentEnabled = hash.webTorrentEnabled
86 this.autoPlayVideo = hash.autoPlayVideo
87 this.autoPlayNextVideo = hash.autoPlayNextVideo
88 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
89 this.videosHistoryEnabled = hash.videosHistoryEnabled
90 this.videoLanguages = hash.videoLanguages
92 this.theme = hash.theme
94 this.adminFlags = hash.adminFlags
96 this.blocked = hash.blocked
97 this.blockedReason = hash.blockedReason
99 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
100 this.noWelcomeModal = hash.noWelcomeModal
102 this.notificationSettings = hash.notificationSettings
104 this.createdAt = hash.createdAt
106 this.pluginAuth = hash.pluginAuth
107 this.lastLoginDate = hash.lastLoginDate
109 if (hash.account !== undefined) {
110 this.account = new Account(hash.account)
114 get accountAvatarUrl () {
115 if (!this.account) return ''
117 return this.account.avatarUrl
120 hasRight (right: UserRight) {
121 return hasUserRight(this.role, right)
124 patch (obj: UserServerModel) {
125 for (const key of Object.keys(obj)) {
129 if (obj.account !== undefined) {
130 this.account = new Account(obj.account)
134 updateAccountAvatar (newAccountAvatar?: Avatar) {
135 if (newAccountAvatar) this.account.updateAvatar(newAccountAvatar)
136 else this.account.resetAvatar()
139 isUploadDisabled () {
140 return this.videoQuota === 0 || this.videoQuotaDaily === 0