3 User as UserServerModel,
4 UserNotificationSetting,
7 } from '../../../../../shared/models/users'
8 import { VideoChannel } from '../../../../../shared/models/videos'
9 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
10 import { Account } from '@app/shared/account/account.model'
11 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
12 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
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
55 videoAbusesCount?: number
56 videoAbusesAcceptedCount?: number
57 videoAbusesCreatedCount?: number
58 videoCommentsCount?: number
63 notificationSettings?: UserNotificationSetting
64 videoChannels?: VideoChannel[]
67 blockedReason?: string
69 noInstanceConfigWarningModal: boolean
70 noWelcomeModal: boolean
72 pluginAuth: string | null
74 lastLoginDate: Date | null
78 constructor (hash: Partial<UserServerModel>) {
80 this.username = hash.username
81 this.email = hash.email
85 this.videoChannels = hash.videoChannels
87 this.videoQuota = hash.videoQuota
88 this.videoQuotaDaily = hash.videoQuotaDaily
89 this.videoQuotaUsed = hash.videoQuotaUsed
90 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
91 this.videosCount = hash.videosCount
92 this.videoAbusesCount = hash.videoAbusesCount
93 this.videoAbusesAcceptedCount = hash.videoAbusesAcceptedCount
94 this.videoAbusesCreatedCount = hash.videoAbusesCreatedCount
95 this.videoCommentsCount = hash.videoCommentsCount
97 this.nsfwPolicy = hash.nsfwPolicy
98 this.webTorrentEnabled = hash.webTorrentEnabled
99 this.autoPlayVideo = hash.autoPlayVideo
100 this.autoPlayNextVideo = hash.autoPlayNextVideo
101 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
102 this.videosHistoryEnabled = hash.videosHistoryEnabled
103 this.videoLanguages = hash.videoLanguages
105 this.theme = hash.theme
107 this.adminFlags = hash.adminFlags
109 this.blocked = hash.blocked
110 this.blockedReason = hash.blockedReason
112 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
113 this.noWelcomeModal = hash.noWelcomeModal
115 this.notificationSettings = hash.notificationSettings
117 this.createdAt = hash.createdAt
119 this.pluginAuth = hash.pluginAuth
120 this.lastLoginDate = hash.lastLoginDate
122 if (hash.account !== undefined) {
123 this.account = new Account(hash.account)
127 get accountAvatarUrl () {
128 if (!this.account) return ''
130 return this.account.avatarUrl
133 hasRight (right: UserRight) {
134 return hasUserRight(this.role, right)
137 patch (obj: UserServerModel) {
138 for (const key of Object.keys(obj)) {
142 if (obj.account !== undefined) {
143 this.account = new Account(obj.account)
147 updateAccountAvatar (newAccountAvatar: Avatar) {
148 this.account.updateAvatar(newAccountAvatar)