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