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
74 constructor (hash: Partial<UserServerModel>) {
76 this.username = hash.username
77 this.email = hash.email
81 this.videoChannels = hash.videoChannels
83 this.videoQuota = hash.videoQuota
84 this.videoQuotaDaily = hash.videoQuotaDaily
85 this.videoQuotaUsed = hash.videoQuotaUsed
86 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
87 this.videosCount = hash.videosCount
88 this.videoAbusesCount = hash.videoAbusesCount
89 this.videoAbusesAcceptedCount = hash.videoAbusesAcceptedCount
90 this.videoAbusesCreatedCount = hash.videoAbusesCreatedCount
91 this.videoCommentsCount = hash.videoCommentsCount
93 this.nsfwPolicy = hash.nsfwPolicy
94 this.webTorrentEnabled = hash.webTorrentEnabled
95 this.autoPlayVideo = hash.autoPlayVideo
96 this.autoPlayNextVideo = hash.autoPlayNextVideo
97 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
98 this.videosHistoryEnabled = hash.videosHistoryEnabled
99 this.videoLanguages = hash.videoLanguages
101 this.theme = hash.theme
103 this.adminFlags = hash.adminFlags
105 this.blocked = hash.blocked
106 this.blockedReason = hash.blockedReason
108 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
109 this.noWelcomeModal = hash.noWelcomeModal
111 this.notificationSettings = hash.notificationSettings
113 this.createdAt = hash.createdAt
115 if (hash.account !== undefined) {
116 this.account = new Account(hash.account)
120 get accountAvatarUrl () {
121 if (!this.account) return ''
123 return this.account.avatarUrl
126 hasRight (right: UserRight) {
127 return hasUserRight(this.role, right)
130 patch (obj: UserServerModel) {
131 for (const key of Object.keys(obj)) {
135 if (obj.account !== undefined) {
136 this.account = new Account(obj.account)
140 updateAccountAvatar (newAccountAvatar: Avatar) {
141 this.account.updateAvatar(newAccountAvatar)