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