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',
26 THEME: 'last_active_theme',
27 VIDEO_LANGUAGES: 'video_languages'
33 pendingEmail: string | null
35 emailVerified: boolean
36 nsfwPolicy: NSFWPolicyType
38 adminFlags?: UserAdminFlag
40 autoPlayVideo: boolean
41 autoPlayNextVideo: boolean
42 autoPlayNextVideoPlaylist: boolean
43 webTorrentEnabled: boolean
44 videosHistoryEnabled: boolean
45 videoLanguages: string[]
51 videoQuotaDaily: number
52 videoQuotaUsed?: number
53 videoQuotaUsedDaily?: number
56 videoCommentsCount?: number
59 abusesAcceptedCount?: number
60 abusesCreatedCount?: number
65 notificationSettings?: UserNotificationSetting
66 videoChannels?: VideoChannel[]
69 blockedReason?: string
71 noInstanceConfigWarningModal: boolean
72 noWelcomeModal: boolean
74 pluginAuth: string | null
76 lastLoginDate: Date | null
80 constructor (hash: Partial<UserServerModel>) {
82 this.username = hash.username
83 this.email = hash.email
87 this.videoChannels = hash.videoChannels
89 this.videoQuota = hash.videoQuota
90 this.videoQuotaDaily = hash.videoQuotaDaily
91 this.videoQuotaUsed = hash.videoQuotaUsed
92 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
93 this.videosCount = hash.videosCount
94 this.abusesCount = hash.abusesCount
95 this.abusesAcceptedCount = hash.abusesAcceptedCount
96 this.abusesCreatedCount = hash.abusesCreatedCount
97 this.videoCommentsCount = hash.videoCommentsCount
99 this.nsfwPolicy = hash.nsfwPolicy
100 this.webTorrentEnabled = hash.webTorrentEnabled
101 this.autoPlayVideo = hash.autoPlayVideo
102 this.autoPlayNextVideo = hash.autoPlayNextVideo
103 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
104 this.videosHistoryEnabled = hash.videosHistoryEnabled
105 this.videoLanguages = hash.videoLanguages
107 this.theme = hash.theme
109 this.adminFlags = hash.adminFlags
111 this.blocked = hash.blocked
112 this.blockedReason = hash.blockedReason
114 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
115 this.noWelcomeModal = hash.noWelcomeModal
117 this.notificationSettings = hash.notificationSettings
119 this.createdAt = hash.createdAt
121 this.pluginAuth = hash.pluginAuth
122 this.lastLoginDate = hash.lastLoginDate
124 if (hash.account !== undefined) {
125 this.account = new Account(hash.account)
129 get accountAvatarUrl () {
130 if (!this.account) return ''
132 return this.account.avatarUrl
135 hasRight (right: UserRight) {
136 return hasUserRight(this.role, right)
139 patch (obj: UserServerModel) {
140 for (const key of Object.keys(obj)) {
144 if (obj.account !== undefined) {
145 this.account = new Account(obj.account)
149 updateAccountAvatar (newAccountAvatar: Avatar) {
150 this.account.updateAvatar(newAccountAvatar)