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