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