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