]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/users/user.model.ts
Add migrations
[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: 'last_active_theme',
27 VIDEO_LANGUAGES: 'video_languages'
28 }
29
30 id: number
31 username: string
32 email: string
33 pendingEmail: string | null
34
35 emailVerified: boolean
36 nsfwPolicy: NSFWPolicyType
37
38 adminFlags?: UserAdminFlag
39
40 autoPlayVideo: boolean
41 autoPlayNextVideo: boolean
42 autoPlayNextVideoPlaylist: boolean
43 webTorrentEnabled: boolean
44 videosHistoryEnabled: boolean
45 videoLanguages: string[]
46
47 role: UserRole
48 roleLabel: string
49
50 videoQuota: number
51 videoQuotaDaily: number
52 videoQuotaUsed?: number
53 videoQuotaUsedDaily?: number
54
55 videosCount?: number
56 videoCommentsCount?: number
57
58 abusesCount?: number
59 abusesAcceptedCount?: number
60 abusesCreatedCount?: number
61
62 theme: string
63
64 account: Account
65 notificationSettings?: UserNotificationSetting
66 videoChannels?: VideoChannel[]
67
68 blocked: boolean
69 blockedReason?: string
70
71 noInstanceConfigWarningModal: boolean
72 noWelcomeModal: boolean
73
74 pluginAuth: string | null
75
76 lastLoginDate: Date | null
77
78 createdAt: Date
79
80 constructor (hash: Partial<UserServerModel>) {
81 this.id = hash.id
82 this.username = hash.username
83 this.email = hash.email
84
85 this.role = hash.role
86
87 this.videoChannels = hash.videoChannels
88
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
98
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
106
107 this.theme = hash.theme
108
109 this.adminFlags = hash.adminFlags
110
111 this.blocked = hash.blocked
112 this.blockedReason = hash.blockedReason
113
114 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
115 this.noWelcomeModal = hash.noWelcomeModal
116
117 this.notificationSettings = hash.notificationSettings
118
119 this.createdAt = hash.createdAt
120
121 this.pluginAuth = hash.pluginAuth
122 this.lastLoginDate = hash.lastLoginDate
123
124 if (hash.account !== undefined) {
125 this.account = new Account(hash.account)
126 }
127 }
128
129 get accountAvatarUrl () {
130 if (!this.account) return ''
131
132 return this.account.avatarUrl
133 }
134
135 hasRight (right: UserRight) {
136 return hasUserRight(this.role, right)
137 }
138
139 patch (obj: UserServerModel) {
140 for (const key of Object.keys(obj)) {
141 this[key] = obj[key]
142 }
143
144 if (obj.account !== undefined) {
145 this.account = new Account(obj.account)
146 }
147 }
148
149 updateAccountAvatar (newAccountAvatar: Avatar) {
150 this.account.updateAvatar(newAccountAvatar)
151 }
152 }