]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Handle email update on server
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
CommitLineData
2f1548fd 1import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRight, UserRole, VideoChannel } from '../../../../../shared'
0883b324 2import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
ad9e39fb 3import { Account } from '@app/shared/account/account.model'
0c237b19 4import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
1eddc9a7 5import { UserAdminFlag } from '@shared/models/users/user-flag.model'
69f616ab
C
6
7export class User implements UserServerModel {
df98563e
C
8 id: number
9 username: string
10 email: string
fc2ec87a 11 emailVerified: boolean
0883b324 12 nsfwPolicy: NSFWPolicyType
276d9652 13
1eddc9a7
C
14 role: UserRole
15 roleLabel: string
16
ed638e53 17 webTorrentEnabled: boolean
7efe153b 18 autoPlayVideo: boolean
276d9652
C
19 videosHistoryEnabled: boolean
20
b0f9f39e 21 videoQuota: number
bee0abff 22 videoQuotaDaily: number
2295ce6c 23 account: Account
404b54e1 24 videoChannels: VideoChannel[]
df98563e 25 createdAt: Date
7da18e44 26
1eddc9a7
C
27 adminFlags?: UserAdminFlag
28
eacb25c4
C
29 blocked: boolean
30 blockedReason?: string
31
2f1548fd
C
32 notificationSettings?: UserNotificationSetting
33
276d9652 34 constructor (hash: Partial<UserServerModel>) {
df98563e
C
35 this.id = hash.id
36 this.username = hash.username
37 this.email = hash.email
1eddc9a7 38
df98563e 39 this.role = hash.role
ad9e39fb 40
eacb25c4
C
41 this.videoChannels = hash.videoChannels
42 this.videoQuota = hash.videoQuota
bee0abff 43 this.videoQuotaDaily = hash.videoQuotaDaily
eacb25c4 44 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 45 this.webTorrentEnabled = hash.webTorrentEnabled
276d9652 46 this.videosHistoryEnabled = hash.videosHistoryEnabled
eacb25c4
C
47 this.autoPlayVideo = hash.autoPlayVideo
48 this.createdAt = hash.createdAt
1eddc9a7
C
49
50 this.adminFlags = hash.adminFlags
51
eacb25c4
C
52 this.blocked = hash.blocked
53 this.blockedReason = hash.blockedReason
54
2f1548fd
C
55 this.notificationSettings = hash.notificationSettings
56
ad9e39fb
C
57 if (hash.account !== undefined) {
58 this.account = new Account(hash.account)
59 }
52d9f792
C
60 }
61
62 get accountAvatarUrl () {
63 if (!this.account) return ''
d3e91a5f 64
52d9f792 65 return this.account.avatarUrl
7da18e44
C
66 }
67
954605a8
C
68 hasRight (right: UserRight) {
69 return hasUserRight(this.role, right)
7da18e44 70 }
2295ce6c 71
ce5496d6
C
72 patch (obj: UserServerModel) {
73 for (const key of Object.keys(obj)) {
74 this[key] = obj[key]
75 }
d3e91a5f 76
ad9e39fb
C
77 if (obj.account !== undefined) {
78 this.account = new Account(obj.account)
79 }
d3e91a5f
C
80 }
81
0c237b19 82 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 83 this.account.updateAvatar(newAccountAvatar)
ce5496d6 84 }
7da18e44 85}