]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Merge branch 'release/v1.0.0' into develop
[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
46
404b54e1 47 constructor (hash: UserConstructorHash) {
df98563e
C
48 this.id = hash.id
49 this.username = hash.username
50 this.email = hash.email
51 this.role = hash.role
ad9e39fb 52
eacb25c4
C
53 this.videoChannels = hash.videoChannels
54 this.videoQuota = hash.videoQuota
bee0abff 55 this.videoQuotaDaily = hash.videoQuotaDaily
eacb25c4 56 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 57 this.webTorrentEnabled = hash.webTorrentEnabled
eacb25c4
C
58 this.autoPlayVideo = hash.autoPlayVideo
59 this.createdAt = hash.createdAt
60 this.blocked = hash.blocked
61 this.blockedReason = hash.blockedReason
62
ad9e39fb
C
63 if (hash.account !== undefined) {
64 this.account = new Account(hash.account)
65 }
52d9f792
C
66 }
67
68 get accountAvatarUrl () {
69 if (!this.account) return ''
d3e91a5f 70
52d9f792 71 return this.account.avatarUrl
7da18e44
C
72 }
73
954605a8
C
74 hasRight (right: UserRight) {
75 return hasUserRight(this.role, right)
7da18e44 76 }
2295ce6c 77
ce5496d6
C
78 patch (obj: UserServerModel) {
79 for (const key of Object.keys(obj)) {
80 this[key] = obj[key]
81 }
d3e91a5f 82
ad9e39fb
C
83 if (obj.account !== undefined) {
84 this.account = new Account(obj.account)
85 }
d3e91a5f
C
86 }
87
0c237b19 88 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 89 this.account.updateAvatar(newAccountAvatar)
ce5496d6 90 }
7da18e44 91}