]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/users/user.model.ts
Add account avatar
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
1 import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2 import { Account } from '../../../../../shared/models/accounts'
3
4 export type UserConstructorHash = {
5 id: number,
6 username: string,
7 email: string,
8 role: UserRole,
9 videoQuota?: number,
10 displayNSFW?: boolean,
11 createdAt?: Date,
12 account?: Account,
13 videoChannels?: VideoChannel[]
14 }
15 export class User implements UserServerModel {
16 id: number
17 username: string
18 email: string
19 role: UserRole
20 displayNSFW: boolean
21 videoQuota: number
22 account: Account
23 videoChannels: VideoChannel[]
24 createdAt: Date
25
26 constructor (hash: UserConstructorHash) {
27 this.id = hash.id
28 this.username = hash.username
29 this.email = hash.email
30 this.role = hash.role
31 this.account = hash.account
32
33 if (hash.videoChannels !== undefined) {
34 this.videoChannels = hash.videoChannels
35 }
36
37 if (hash.videoQuota !== undefined) {
38 this.videoQuota = hash.videoQuota
39 }
40
41 if (hash.displayNSFW !== undefined) {
42 this.displayNSFW = hash.displayNSFW
43 }
44
45 if (hash.createdAt !== undefined) {
46 this.createdAt = hash.createdAt
47 }
48 }
49
50 hasRight (right: UserRight) {
51 return hasUserRight(this.role, right)
52 }
53
54 getAvatarPath () {
55 if (this.account && this.account.avatar) return this.account.avatar.path
56
57 return '/assets/default-avatar.png'
58 }
59 }