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
58 notificationSettings?: UserNotificationSetting
59 videoChannels?: VideoChannel[]
62 blockedReason?: string
64 noInstanceConfigWarningModal: boolean
65 noWelcomeModal: boolean
69 constructor (hash: Partial<UserServerModel>) {
71 this.username = hash.username
72 this.email = hash.email
76 this.videoChannels = hash.videoChannels
78 this.videoQuota = hash.videoQuota
79 this.videoQuotaDaily = hash.videoQuotaDaily
80 this.videoQuotaUsed = hash.videoQuotaUsed
81 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
83 this.nsfwPolicy = hash.nsfwPolicy
84 this.webTorrentEnabled = hash.webTorrentEnabled
85 this.autoPlayVideo = hash.autoPlayVideo
86 this.autoPlayNextVideo = hash.autoPlayNextVideo
87 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
88 this.videosHistoryEnabled = hash.videosHistoryEnabled
89 this.videoLanguages = hash.videoLanguages
91 this.theme = hash.theme
93 this.adminFlags = hash.adminFlags
95 this.blocked = hash.blocked
96 this.blockedReason = hash.blockedReason
98 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
99 this.noWelcomeModal = hash.noWelcomeModal
101 this.notificationSettings = hash.notificationSettings
103 this.createdAt = hash.createdAt
105 if (hash.account !== undefined) {
106 this.account = new Account(hash.account)
110 get accountAvatarUrl () {
111 if (!this.account) return ''
113 return this.account.avatarUrl
116 hasRight (right: UserRight) {
117 return hasUserRight(this.role, right)
120 patch (obj: UserServerModel) {
121 for (const key of Object.keys(obj)) {
125 if (obj.account !== undefined) {
126 this.account = new Account(obj.account)
130 updateAccountAvatar (newAccountAvatar: Avatar) {
131 this.account.updateAvatar(newAccountAvatar)