]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/users/user.model.ts
Add ability to choose what policy we have for NSFW videos
[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 '../account/account.model'
3 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
4
5 export type UserConstructorHash = {
6 id: number,
7 username: string,
8 email: string,
9 role: UserRole,
10 videoQuota?: number,
11 nsfwPolicy?: NSFWPolicyType,
12 autoPlayVideo?: boolean,
13 createdAt?: Date,
14 account?: Account,
15 videoChannels?: VideoChannel[]
16 }
17 export class User implements UserServerModel {
18 id: number
19 username: string
20 email: string
21 role: UserRole
22 nsfwPolicy: NSFWPolicyType
23 autoPlayVideo: boolean
24 videoQuota: number
25 account: Account
26 videoChannels: VideoChannel[]
27 createdAt: Date
28
29 constructor (hash: UserConstructorHash) {
30 this.id = hash.id
31 this.username = hash.username
32 this.email = hash.email
33 this.role = hash.role
34 this.account = hash.account
35
36 if (hash.videoChannels !== undefined) {
37 this.videoChannels = hash.videoChannels
38 }
39
40 if (hash.videoQuota !== undefined) {
41 this.videoQuota = hash.videoQuota
42 }
43
44 if (hash.nsfwPolicy !== undefined) {
45 this.nsfwPolicy = hash.nsfwPolicy
46 }
47
48 if (hash.autoPlayVideo !== undefined) {
49 this.autoPlayVideo = hash.autoPlayVideo
50 }
51
52 if (hash.createdAt !== undefined) {
53 this.createdAt = hash.createdAt
54 }
55 }
56
57 hasRight (right: UserRight) {
58 return hasUserRight(this.role, right)
59 }
60
61 getAvatarUrl () {
62 return Account.GET_ACCOUNT_AVATAR_URL(this.account)
63 }
64
65 patch (obj: UserServerModel) {
66 for (const key of Object.keys(obj)) {
67 this[key] = obj[key]
68 }
69 }
70 }