]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Add ability for uploaders to schedule video update
[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'
d3e91a5f 10import { Actor } from '@app/shared/actor/actor.model'
ad9e39fb 11import { Account } from '@app/shared/account/account.model'
69f616ab 12
404b54e1
C
13export type UserConstructorHash = {
14 id: number,
15 username: string,
16 email: string,
17 role: UserRole,
18 videoQuota?: number,
0883b324 19 nsfwPolicy?: NSFWPolicyType,
7efe153b 20 autoPlayVideo?: boolean,
404b54e1 21 createdAt?: Date,
ad9e39fb 22 account?: AccountServerModel,
404b54e1
C
23 videoChannels?: VideoChannel[]
24}
69f616ab 25export class User implements UserServerModel {
df98563e
C
26 id: number
27 username: string
28 email: string
29 role: UserRole
0883b324 30 nsfwPolicy: NSFWPolicyType
7efe153b 31 autoPlayVideo: boolean
b0f9f39e 32 videoQuota: number
2295ce6c 33 account: Account
404b54e1 34 videoChannels: VideoChannel[]
df98563e 35 createdAt: Date
d3e91a5f 36 accountAvatarUrl: string
7da18e44 37
404b54e1 38 constructor (hash: UserConstructorHash) {
df98563e
C
39 this.id = hash.id
40 this.username = hash.username
41 this.email = hash.email
42 this.role = hash.role
ad9e39fb
C
43
44 if (hash.account !== undefined) {
45 this.account = new Account(hash.account)
46 }
404b54e1
C
47
48 if (hash.videoChannels !== undefined) {
49 this.videoChannels = hash.videoChannels
50 }
44c5275e 51
b0f9f39e
C
52 if (hash.videoQuota !== undefined) {
53 this.videoQuota = hash.videoQuota
54 }
55
0883b324
C
56 if (hash.nsfwPolicy !== undefined) {
57 this.nsfwPolicy = hash.nsfwPolicy
b0f9f39e
C
58 }
59
7efe153b
AL
60 if (hash.autoPlayVideo !== undefined) {
61 this.autoPlayVideo = hash.autoPlayVideo
62 }
63
b0f9f39e 64 if (hash.createdAt !== undefined) {
df98563e 65 this.createdAt = hash.createdAt
44c5275e 66 }
d3e91a5f
C
67
68 this.updateComputedAttributes()
7da18e44
C
69 }
70
954605a8
C
71 hasRight (right: UserRight) {
72 return hasUserRight(this.role, right)
7da18e44 73 }
2295ce6c 74
ce5496d6
C
75 patch (obj: UserServerModel) {
76 for (const key of Object.keys(obj)) {
77 this[key] = obj[key]
78 }
d3e91a5f 79
ad9e39fb
C
80 if (obj.account !== undefined) {
81 this.account = new Account(obj.account)
82 }
83
d3e91a5f
C
84 this.updateComputedAttributes()
85 }
86
87 private updateComputedAttributes () {
88 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
ce5496d6 89 }
7da18e44 90}