1 import { Account } from '@app/shared/shared-main/account/account.model'
6 User as UserServerModel,
8 UserNotificationSetting,
12 } from '@shared/models'
14 export class User implements UserServerModel {
19 VIDEOS_HISTORY_ENABLED: 'videos-history-enabled',
21 NSFW_POLICY: 'nsfw_policy',
22 WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled',
23 AUTO_PLAY_VIDEO: 'auto_play_video',
24 SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO: 'auto_play_next_video',
25 AUTO_PLAY_VIDEO_PLAYLIST: 'auto_play_video_playlist',
27 LAST_ACTIVE_THEME: 'last_active_theme',
28 VIDEO_LANGUAGES: 'video_languages'
34 pendingEmail: string | null
36 emailVerified: boolean
37 nsfwPolicy: NSFWPolicyType
39 adminFlags?: UserAdminFlag
41 autoPlayVideo: boolean
42 autoPlayNextVideo: boolean
43 autoPlayNextVideoPlaylist: boolean
44 webTorrentEnabled: boolean
45 videosHistoryEnabled: boolean
46 videoLanguages: string[]
52 videoQuotaDaily: number
53 videoQuotaUsed?: number
54 videoQuotaUsedDaily?: number
57 videoCommentsCount?: number
60 abusesAcceptedCount?: number
61 abusesCreatedCount?: number
66 notificationSettings?: UserNotificationSetting
67 videoChannels?: VideoChannel[]
70 blockedReason?: string
72 noInstanceConfigWarningModal: boolean
73 noWelcomeModal: boolean
75 pluginAuth: string | null
77 lastLoginDate: Date | null
81 constructor (hash: Partial<UserServerModel>) {
83 this.username = hash.username
84 this.email = hash.email
88 this.videoChannels = hash.videoChannels
90 this.videoQuota = hash.videoQuota
91 this.videoQuotaDaily = hash.videoQuotaDaily
92 this.videoQuotaUsed = hash.videoQuotaUsed
93 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
94 this.videosCount = hash.videosCount
95 this.abusesCount = hash.abusesCount
96 this.abusesAcceptedCount = hash.abusesAcceptedCount
97 this.abusesCreatedCount = hash.abusesCreatedCount
98 this.videoCommentsCount = hash.videoCommentsCount
100 this.nsfwPolicy = hash.nsfwPolicy
101 this.webTorrentEnabled = hash.webTorrentEnabled
102 this.autoPlayVideo = hash.autoPlayVideo
103 this.autoPlayNextVideo = hash.autoPlayNextVideo
104 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
105 this.videosHistoryEnabled = hash.videosHistoryEnabled
106 this.videoLanguages = hash.videoLanguages
108 this.theme = hash.theme
110 this.adminFlags = hash.adminFlags
112 this.blocked = hash.blocked
113 this.blockedReason = hash.blockedReason
115 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
116 this.noWelcomeModal = hash.noWelcomeModal
118 this.notificationSettings = hash.notificationSettings
120 this.createdAt = hash.createdAt
122 this.pluginAuth = hash.pluginAuth
123 this.lastLoginDate = hash.lastLoginDate
125 if (hash.account !== undefined) {
126 this.account = new Account(hash.account)
130 get accountAvatarUrl () {
131 if (!this.account) return ''
133 return this.account.avatarUrl
136 hasRight (right: UserRight) {
137 return hasUserRight(this.role, right)
140 patch (obj: UserServerModel) {
141 for (const key of Object.keys(obj)) {
145 if (obj.account !== undefined) {
146 this.account = new Account(obj.account)
150 updateAccountAvatar (newAccountAvatar: Avatar) {
151 this.account.updateAvatar(newAccountAvatar)
154 isUploadDisabled () {
155 return this.videoQuota === 0 || this.videoQuotaDaily === 0