]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/users/user.model.ts
Prevent player crash on safari
[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
d12b40fb
C
69 twoFactorEnabled: boolean
70
43d0ea7f 71 createdAt: Date
2f1548fd 72
276d9652 73 constructor (hash: Partial<UserServerModel>) {
df98563e
C
74 this.id = hash.id
75 this.username = hash.username
76 this.email = hash.email
1eddc9a7 77
df98563e 78 this.role = hash.role
ad9e39fb 79
eacb25c4 80 this.videoChannels = hash.videoChannels
43d0ea7f 81
eacb25c4 82 this.videoQuota = hash.videoQuota
bee0abff 83 this.videoQuotaDaily = hash.videoQuotaDaily
43d0ea7f
C
84 this.videoQuotaUsed = hash.videoQuotaUsed
85 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
76314386 86 this.videosCount = hash.videosCount
4f32032f
C
87 this.abusesCount = hash.abusesCount
88 this.abusesAcceptedCount = hash.abusesAcceptedCount
89 this.abusesCreatedCount = hash.abusesCreatedCount
76314386 90 this.videoCommentsCount = hash.videoCommentsCount
43d0ea7f 91
eacb25c4 92 this.nsfwPolicy = hash.nsfwPolicy
a9bfa85d 93 this.p2pEnabled = hash.p2pEnabled
eacb25c4 94 this.autoPlayVideo = hash.autoPlayVideo
d3217560
RK
95 this.autoPlayNextVideo = hash.autoPlayNextVideo
96 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
97 this.videosHistoryEnabled = hash.videosHistoryEnabled
98 this.videoLanguages = hash.videoLanguages
1eddc9a7 99
7cd4d2ba
C
100 this.theme = hash.theme
101
1eddc9a7
C
102 this.adminFlags = hash.adminFlags
103
eacb25c4
C
104 this.blocked = hash.blocked
105 this.blockedReason = hash.blockedReason
106
43d0ea7f
C
107 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
108 this.noWelcomeModal = hash.noWelcomeModal
8f581725 109 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
43d0ea7f 110
2f1548fd
C
111 this.notificationSettings = hash.notificationSettings
112
d12b40fb
C
113 this.twoFactorEnabled = hash.twoFactorEnabled
114
43d0ea7f
C
115 this.createdAt = hash.createdAt
116
8bb71f2e 117 this.pluginAuth = hash.pluginAuth
3cc665f4 118 this.lastLoginDate = hash.lastLoginDate
8bb71f2e 119
ad9e39fb
C
120 if (hash.account !== undefined) {
121 this.account = new Account(hash.account)
122 }
52d9f792
C
123 }
124
954605a8
C
125 hasRight (right: UserRight) {
126 return hasUserRight(this.role, right)
7da18e44 127 }
2295ce6c 128
ce5496d6
C
129 patch (obj: UserServerModel) {
130 for (const key of Object.keys(obj)) {
131 this[key] = obj[key]
132 }
d3e91a5f 133
ad9e39fb
C
134 if (obj.account !== undefined) {
135 this.account = new Account(obj.account)
136 }
d3e91a5f
C
137 }
138
d0800f76 139 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
140 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
1ea7da81 141 else this.account.resetAvatar()
ce5496d6 142 }
dfe3f7b7
K
143
144 isUploadDisabled () {
145 return this.videoQuota === 0 || this.videoQuotaDaily === 0
146 }
4e1592da 147
e0b1231b
C
148 isAutoBlocked (serverConfig: HTMLServerConfig) {
149 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
150
4e1592da
MK
151 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
152 }
7da18e44 153}