]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Fix transcoding
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
CommitLineData
ad9e39fb
C
1import {
2 Account as AccountServerModel,
3 hasUserRight,
4 User as UserServerModel,
5 UserRight,
6 UserRole,
7 VideoChannel
8} from '../../../../../shared'
0883b324 9import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
ad9e39fb 10import { Account } from '@app/shared/account/account.model'
0c237b19 11import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
69f616ab 12
404b54e1
C
13export type UserConstructorHash = {
14 id: number,
15 username: string,
16 email: string,
17 role: UserRole,
18 videoQuota?: number,
bee0abff 19 videoQuotaDaily?: number,
0883b324 20 nsfwPolicy?: NSFWPolicyType,
ed638e53 21 webTorrentEnabled?: boolean,
7efe153b 22 autoPlayVideo?: boolean,
404b54e1 23 createdAt?: Date,
ad9e39fb 24 account?: AccountServerModel,
404b54e1 25 videoChannels?: VideoChannel[]
eacb25c4
C
26
27 blocked?: boolean
28 blockedReason?: string
404b54e1 29}
69f616ab 30export class User implements UserServerModel {
df98563e
C
31 id: number
32 username: string
33 email: string
34 role: UserRole
0883b324 35 nsfwPolicy: NSFWPolicyType
ed638e53 36 webTorrentEnabled: boolean
7efe153b 37 autoPlayVideo: boolean
b0f9f39e 38 videoQuota: number
bee0abff 39 videoQuotaDaily: number
2295ce6c 40 account: Account
404b54e1 41 videoChannels: VideoChannel[]
df98563e 42 createdAt: Date
7da18e44 43
eacb25c4
C
44 blocked: boolean
45 blockedReason?: string
244b4ae3 46 [key: string]: any
eacb25c4 47
404b54e1 48 constructor (hash: UserConstructorHash) {
df98563e
C
49 this.id = hash.id
50 this.username = hash.username
51 this.email = hash.email
52 this.role = hash.role
ad9e39fb 53
eacb25c4
C
54 this.videoChannels = hash.videoChannels
55 this.videoQuota = hash.videoQuota
bee0abff 56 this.videoQuotaDaily = hash.videoQuotaDaily
eacb25c4 57 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 58 this.webTorrentEnabled = hash.webTorrentEnabled
eacb25c4
C
59 this.autoPlayVideo = hash.autoPlayVideo
60 this.createdAt = hash.createdAt
61 this.blocked = hash.blocked
62 this.blockedReason = hash.blockedReason
63
ad9e39fb
C
64 if (hash.account !== undefined) {
65 this.account = new Account(hash.account)
66 }
52d9f792
C
67 }
68
69 get accountAvatarUrl () {
70 if (!this.account) return ''
d3e91a5f 71
52d9f792 72 return this.account.avatarUrl
7da18e44
C
73 }
74
954605a8
C
75 hasRight (right: UserRight) {
76 return hasUserRight(this.role, right)
7da18e44 77 }
2295ce6c 78
ce5496d6
C
79 patch (obj: UserServerModel) {
80 for (const key of Object.keys(obj)) {
81 this[key] = obj[key]
82 }
d3e91a5f 83
ad9e39fb
C
84 if (obj.account !== undefined) {
85 this.account = new Account(obj.account)
86 }
d3e91a5f
C
87 }
88
0c237b19 89 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 90 this.account.updateAvatar(newAccountAvatar)
ce5496d6 91 }
7da18e44 92}