]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/users/user.model.ts
chore: add manifest in light build
[github/Chocobozzz/PeerTube.git] / client / src / app / core / users / user.model.ts
CommitLineData
67ed6552 1import { Account } from '@app/shared/shared-main/account/account.model'
bd45d503 2import { hasUserRight } from '@shared/core-utils/users'
d3217560 3import {
67ed6552 4 Avatar,
67ed6552 5 NSFWPolicyType,
d3217560 6 User as UserServerModel,
67ed6552 7 UserAdminFlag,
d3217560
RK
8 UserNotificationSetting,
9 UserRight,
67ed6552
C
10 UserRole,
11 VideoChannel
12} from '@shared/models'
69f616ab
C
13
14export class User implements UserServerModel {
df98563e
C
15 id: number
16 username: string
17 email: string
0ba5f5ba 18 pendingEmail: string | null
43d0ea7f 19
fc2ec87a 20 emailVerified: boolean
0883b324 21 nsfwPolicy: NSFWPolicyType
276d9652 22
43d0ea7f 23 adminFlags?: UserAdminFlag
1eddc9a7 24
7efe153b 25 autoPlayVideo: boolean
6aa54148 26 autoPlayNextVideo: boolean
bee29df8 27 autoPlayNextVideoPlaylist: boolean
43d0ea7f 28 webTorrentEnabled: boolean
276d9652 29 videosHistoryEnabled: boolean
3caf77d3 30 videoLanguages: string[]
276d9652 31
43d0ea7f
C
32 role: UserRole
33 roleLabel: string
34
b0f9f39e 35 videoQuota: number
bee0abff 36 videoQuotaDaily: number
43d0ea7f
C
37 videoQuotaUsed?: number
38 videoQuotaUsedDaily?: number
4f32032f 39
76314386 40 videosCount?: number
76314386 41 videoCommentsCount?: number
7da18e44 42
4f32032f
C
43 abusesCount?: number
44 abusesAcceptedCount?: number
45 abusesCreatedCount?: number
46
7cd4d2ba
C
47 theme: string
48
43d0ea7f
C
49 account: Account
50 notificationSettings?: UserNotificationSetting
51 videoChannels?: VideoChannel[]
1eddc9a7 52
eacb25c4
C
53 blocked: boolean
54 blockedReason?: string
55
43d0ea7f
C
56 noInstanceConfigWarningModal: boolean
57 noWelcomeModal: boolean
58
8bb71f2e
C
59 pluginAuth: string | null
60
3cc665f4
C
61 lastLoginDate: Date | null
62
43d0ea7f 63 createdAt: Date
2f1548fd 64
276d9652 65 constructor (hash: Partial<UserServerModel>) {
df98563e
C
66 this.id = hash.id
67 this.username = hash.username
68 this.email = hash.email
1eddc9a7 69
df98563e 70 this.role = hash.role
ad9e39fb 71
eacb25c4 72 this.videoChannels = hash.videoChannels
43d0ea7f 73
eacb25c4 74 this.videoQuota = hash.videoQuota
bee0abff 75 this.videoQuotaDaily = hash.videoQuotaDaily
43d0ea7f
C
76 this.videoQuotaUsed = hash.videoQuotaUsed
77 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
76314386 78 this.videosCount = hash.videosCount
4f32032f
C
79 this.abusesCount = hash.abusesCount
80 this.abusesAcceptedCount = hash.abusesAcceptedCount
81 this.abusesCreatedCount = hash.abusesCreatedCount
76314386 82 this.videoCommentsCount = hash.videoCommentsCount
43d0ea7f 83
eacb25c4 84 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 85 this.webTorrentEnabled = hash.webTorrentEnabled
eacb25c4 86 this.autoPlayVideo = hash.autoPlayVideo
d3217560
RK
87 this.autoPlayNextVideo = hash.autoPlayNextVideo
88 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
89 this.videosHistoryEnabled = hash.videosHistoryEnabled
90 this.videoLanguages = hash.videoLanguages
1eddc9a7 91
7cd4d2ba
C
92 this.theme = hash.theme
93
1eddc9a7
C
94 this.adminFlags = hash.adminFlags
95
eacb25c4
C
96 this.blocked = hash.blocked
97 this.blockedReason = hash.blockedReason
98
43d0ea7f
C
99 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
100 this.noWelcomeModal = hash.noWelcomeModal
101
2f1548fd
C
102 this.notificationSettings = hash.notificationSettings
103
43d0ea7f
C
104 this.createdAt = hash.createdAt
105
8bb71f2e 106 this.pluginAuth = hash.pluginAuth
3cc665f4 107 this.lastLoginDate = hash.lastLoginDate
8bb71f2e 108
ad9e39fb
C
109 if (hash.account !== undefined) {
110 this.account = new Account(hash.account)
111 }
52d9f792
C
112 }
113
114 get accountAvatarUrl () {
115 if (!this.account) return ''
d3e91a5f 116
52d9f792 117 return this.account.avatarUrl
7da18e44
C
118 }
119
954605a8
C
120 hasRight (right: UserRight) {
121 return hasUserRight(this.role, right)
7da18e44 122 }
2295ce6c 123
ce5496d6
C
124 patch (obj: UserServerModel) {
125 for (const key of Object.keys(obj)) {
126 this[key] = obj[key]
127 }
d3e91a5f 128
ad9e39fb
C
129 if (obj.account !== undefined) {
130 this.account = new Account(obj.account)
131 }
d3e91a5f
C
132 }
133
0c237b19 134 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 135 this.account.updateAvatar(newAccountAvatar)
ce5496d6 136 }
dfe3f7b7
K
137
138 isUploadDisabled () {
139 return this.videoQuota === 0 || this.videoQuotaDaily === 0
140 }
7da18e44 141}