]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/shared/users/user.model.ts
Add ability to disable and clear history
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
... / ...
CommitLineData
1import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
3import { Account } from '@app/shared/account/account.model'
4import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5
6export class User implements UserServerModel {
7 id: number
8 username: string
9 email: string
10 emailVerified: boolean
11 role: UserRole
12 nsfwPolicy: NSFWPolicyType
13
14 webTorrentEnabled: boolean
15 autoPlayVideo: boolean
16 videosHistoryEnabled: boolean
17
18 videoQuota: number
19 videoQuotaDaily: number
20 account: Account
21 videoChannels: VideoChannel[]
22 createdAt: Date
23
24 blocked: boolean
25 blockedReason?: string
26
27 constructor (hash: Partial<UserServerModel>) {
28 this.id = hash.id
29 this.username = hash.username
30 this.email = hash.email
31 this.role = hash.role
32
33 this.videoChannels = hash.videoChannels
34 this.videoQuota = hash.videoQuota
35 this.videoQuotaDaily = hash.videoQuotaDaily
36 this.nsfwPolicy = hash.nsfwPolicy
37 this.webTorrentEnabled = hash.webTorrentEnabled
38 this.videosHistoryEnabled = hash.videosHistoryEnabled
39 this.autoPlayVideo = hash.autoPlayVideo
40 this.createdAt = hash.createdAt
41 this.blocked = hash.blocked
42 this.blockedReason = hash.blockedReason
43
44 if (hash.account !== undefined) {
45 this.account = new Account(hash.account)
46 }
47 }
48
49 get accountAvatarUrl () {
50 if (!this.account) return ''
51
52 return this.account.avatarUrl
53 }
54
55 hasRight (right: UserRight) {
56 return hasUserRight(this.role, right)
57 }
58
59 patch (obj: UserServerModel) {
60 for (const key of Object.keys(obj)) {
61 this[key] = obj[key]
62 }
63
64 if (obj.account !== undefined) {
65 this.account = new Account(obj.account)
66 }
67 }
68
69 updateAccountAvatar (newAccountAvatar: Avatar) {
70 this.account.updateAvatar(newAccountAvatar)
71 }
72}