]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/users/user.model.ts
Merge branch 'next' 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 webTorrentEnabled: boolean
30 videosHistoryEnabled: boolean
31 videoLanguages: string[]
32
33 role: UserRole
34 roleLabel: string
35
36 videoQuota: number
37 videoQuotaDaily: number
38 videoQuotaUsed?: number
39 videoQuotaUsedDaily?: number
40
41 videosCount?: number
42 videoCommentsCount?: number
43
44 abusesCount?: number
45 abusesAcceptedCount?: number
46 abusesCreatedCount?: number
47
48 theme: string
49
50 account: Account
51 notificationSettings?: UserNotificationSetting
52 videoChannels?: VideoChannel[]
53
54 blocked: boolean
55 blockedReason?: string
56
57 noInstanceConfigWarningModal: boolean
58 noWelcomeModal: boolean
59 noAccountSetupWarningModal: boolean
60
61 pluginAuth: string | null
62
63 lastLoginDate: Date | null
64
65 createdAt: Date
66
67 constructor (hash: Partial<UserServerModel>) {
68 this.id = hash.id
69 this.username = hash.username
70 this.email = hash.email
71
72 this.role = hash.role
73
74 this.videoChannels = hash.videoChannels
75
76 this.videoQuota = hash.videoQuota
77 this.videoQuotaDaily = hash.videoQuotaDaily
78 this.videoQuotaUsed = hash.videoQuotaUsed
79 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
80 this.videosCount = hash.videosCount
81 this.abusesCount = hash.abusesCount
82 this.abusesAcceptedCount = hash.abusesAcceptedCount
83 this.abusesCreatedCount = hash.abusesCreatedCount
84 this.videoCommentsCount = hash.videoCommentsCount
85
86 this.nsfwPolicy = hash.nsfwPolicy
87 this.webTorrentEnabled = hash.webTorrentEnabled
88 this.autoPlayVideo = hash.autoPlayVideo
89 this.autoPlayNextVideo = hash.autoPlayNextVideo
90 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
91 this.videosHistoryEnabled = hash.videosHistoryEnabled
92 this.videoLanguages = hash.videoLanguages
93
94 this.theme = hash.theme
95
96 this.adminFlags = hash.adminFlags
97
98 this.blocked = hash.blocked
99 this.blockedReason = hash.blockedReason
100
101 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
102 this.noWelcomeModal = hash.noWelcomeModal
103 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
104
105 this.notificationSettings = hash.notificationSettings
106
107 this.createdAt = hash.createdAt
108
109 this.pluginAuth = hash.pluginAuth
110 this.lastLoginDate = hash.lastLoginDate
111
112 if (hash.account !== undefined) {
113 this.account = new Account(hash.account)
114 }
115 }
116
117 hasRight (right: UserRight) {
118 return hasUserRight(this.role, right)
119 }
120
121 patch (obj: UserServerModel) {
122 for (const key of Object.keys(obj)) {
123 this[key] = obj[key]
124 }
125
126 if (obj.account !== undefined) {
127 this.account = new Account(obj.account)
128 }
129 }
130
131 updateAccountAvatar (newAccountAvatar?: ActorImage) {
132 if (newAccountAvatar) this.account.updateAvatar(newAccountAvatar)
133 else this.account.resetAvatar()
134 }
135
136 isUploadDisabled () {
137 return this.videoQuota === 0 || this.videoQuotaDaily === 0
138 }
139
140 isAutoBlocked (serverConfig: HTMLServerConfig) {
141 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
142
143 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
144 }
145 }