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