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