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