]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Merge branch 'release/1.4.0' into develop
[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
0ba5f5ba 11 pendingEmail: string | null
43d0ea7f 12
fc2ec87a 13 emailVerified: boolean
0883b324 14 nsfwPolicy: NSFWPolicyType
276d9652 15
43d0ea7f 16 adminFlags?: UserAdminFlag
1eddc9a7 17
7efe153b 18 autoPlayVideo: boolean
43d0ea7f 19 webTorrentEnabled: boolean
276d9652 20 videosHistoryEnabled: boolean
3caf77d3 21 videoLanguages: string[]
276d9652 22
43d0ea7f
C
23 role: UserRole
24 roleLabel: string
25
b0f9f39e 26 videoQuota: number
bee0abff 27 videoQuotaDaily: number
43d0ea7f
C
28 videoQuotaUsed?: number
29 videoQuotaUsedDaily?: number
7da18e44 30
7cd4d2ba
C
31 theme: string
32
43d0ea7f
C
33 account: Account
34 notificationSettings?: UserNotificationSetting
35 videoChannels?: VideoChannel[]
1eddc9a7 36
eacb25c4
C
37 blocked: boolean
38 blockedReason?: string
39
43d0ea7f
C
40 noInstanceConfigWarningModal: boolean
41 noWelcomeModal: boolean
42
43 createdAt: Date
2f1548fd 44
276d9652 45 constructor (hash: Partial<UserServerModel>) {
df98563e
C
46 this.id = hash.id
47 this.username = hash.username
48 this.email = hash.email
1eddc9a7 49
df98563e 50 this.role = hash.role
ad9e39fb 51
eacb25c4 52 this.videoChannels = hash.videoChannels
43d0ea7f 53
eacb25c4 54 this.videoQuota = hash.videoQuota
bee0abff 55 this.videoQuotaDaily = hash.videoQuotaDaily
43d0ea7f
C
56 this.videoQuotaUsed = hash.videoQuotaUsed
57 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
58
eacb25c4 59 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 60 this.webTorrentEnabled = hash.webTorrentEnabled
276d9652 61 this.videosHistoryEnabled = hash.videosHistoryEnabled
eacb25c4 62 this.autoPlayVideo = hash.autoPlayVideo
1eddc9a7 63
7cd4d2ba
C
64 this.theme = hash.theme
65
1eddc9a7
C
66 this.adminFlags = hash.adminFlags
67
eacb25c4
C
68 this.blocked = hash.blocked
69 this.blockedReason = hash.blockedReason
70
43d0ea7f
C
71 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
72 this.noWelcomeModal = hash.noWelcomeModal
73
2f1548fd
C
74 this.notificationSettings = hash.notificationSettings
75
43d0ea7f
C
76 this.createdAt = hash.createdAt
77
ad9e39fb
C
78 if (hash.account !== undefined) {
79 this.account = new Account(hash.account)
80 }
52d9f792
C
81 }
82
83 get accountAvatarUrl () {
84 if (!this.account) return ''
d3e91a5f 85
52d9f792 86 return this.account.avatarUrl
7da18e44
C
87 }
88
954605a8
C
89 hasRight (right: UserRight) {
90 return hasUserRight(this.role, right)
7da18e44 91 }
2295ce6c 92
ce5496d6
C
93 patch (obj: UserServerModel) {
94 for (const key of Object.keys(obj)) {
95 this[key] = obj[key]
96 }
d3e91a5f 97
ad9e39fb
C
98 if (obj.account !== undefined) {
99 this.account = new Account(obj.account)
100 }
d3e91a5f
C
101 }
102
0c237b19 103 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 104 this.account.updateAvatar(newAccountAvatar)
ce5496d6 105 }
7da18e44 106}