]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/users/user.model.ts
4256f370b9eff73c5edcfada15b05f4bfd4d1721
[github/Chocobozzz/PeerTube.git] / client / src / app / core / users / user.model.ts
1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import {
3 Avatar,
4 hasUserRight,
5 NSFWPolicyType,
6 User as UserServerModel,
7 UserAdminFlag,
8 UserNotificationSetting,
9 UserRight,
10 UserRole,
11 VideoChannel
12 } from '@shared/models'
13
14 export class User implements UserServerModel {
15 static KEYS = {
16 ID: 'id',
17 ROLE: 'role',
18 EMAIL: 'email',
19 VIDEOS_HISTORY_ENABLED: 'videos-history-enabled',
20 USERNAME: 'username',
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: 'theme',
27 LAST_ACTIVE_THEME: 'last_active_theme',
28 VIDEO_LANGUAGES: 'video_languages'
29 }
30
31 id: number
32 username: string
33 email: string
34 pendingEmail: string | null
35
36 emailVerified: boolean
37 nsfwPolicy: NSFWPolicyType
38
39 adminFlags?: UserAdminFlag
40
41 autoPlayVideo: boolean
42 autoPlayNextVideo: boolean
43 autoPlayNextVideoPlaylist: boolean
44 webTorrentEnabled: boolean
45 videosHistoryEnabled: boolean
46 videoLanguages: string[]
47
48 role: UserRole
49 roleLabel: string
50
51 videoQuota: number
52 videoQuotaDaily: number
53 videoQuotaUsed?: number
54 videoQuotaUsedDaily?: number
55
56 videosCount?: number
57 videoCommentsCount?: number
58
59 abusesCount?: number
60 abusesAcceptedCount?: number
61 abusesCreatedCount?: number
62
63 theme: string
64
65 account: Account
66 notificationSettings?: UserNotificationSetting
67 videoChannels?: VideoChannel[]
68
69 blocked: boolean
70 blockedReason?: string
71
72 noInstanceConfigWarningModal: boolean
73 noWelcomeModal: boolean
74
75 pluginAuth: string | null
76
77 lastLoginDate: Date | null
78
79 createdAt: Date
80
81 constructor (hash: Partial<UserServerModel>) {
82 this.id = hash.id
83 this.username = hash.username
84 this.email = hash.email
85
86 this.role = hash.role
87
88 this.videoChannels = hash.videoChannels
89
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
99
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
107
108 this.theme = hash.theme
109
110 this.adminFlags = hash.adminFlags
111
112 this.blocked = hash.blocked
113 this.blockedReason = hash.blockedReason
114
115 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
116 this.noWelcomeModal = hash.noWelcomeModal
117
118 this.notificationSettings = hash.notificationSettings
119
120 this.createdAt = hash.createdAt
121
122 this.pluginAuth = hash.pluginAuth
123 this.lastLoginDate = hash.lastLoginDate
124
125 if (hash.account !== undefined) {
126 this.account = new Account(hash.account)
127 }
128 }
129
130 get accountAvatarUrl () {
131 if (!this.account) return ''
132
133 return this.account.avatarUrl
134 }
135
136 hasRight (right: UserRight) {
137 return hasUserRight(this.role, right)
138 }
139
140 patch (obj: UserServerModel) {
141 for (const key of Object.keys(obj)) {
142 this[key] = obj[key]
143 }
144
145 if (obj.account !== undefined) {
146 this.account = new Account(obj.account)
147 }
148 }
149
150 updateAccountAvatar (newAccountAvatar: Avatar) {
151 this.account.updateAvatar(newAccountAvatar)
152 }
153
154 isUploadDisabled () {
155 return this.videoQuota === 0 || this.videoQuotaDaily === 0
156 }
157 }