]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Remove dashes from actor names
[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,
fc2ec87a 18 emailVerified?: boolean,
404b54e1 19 videoQuota?: number,
bee0abff 20 videoQuotaDaily?: number,
0883b324 21 nsfwPolicy?: NSFWPolicyType,
ed638e53 22 webTorrentEnabled?: boolean,
7efe153b 23 autoPlayVideo?: boolean,
404b54e1 24 createdAt?: Date,
ad9e39fb 25 account?: AccountServerModel,
404b54e1 26 videoChannels?: VideoChannel[]
eacb25c4
C
27
28 blocked?: boolean
29 blockedReason?: string
404b54e1 30}
69f616ab 31export class User implements UserServerModel {
df98563e
C
32 id: number
33 username: string
34 email: string
fc2ec87a 35 emailVerified: boolean
df98563e 36 role: UserRole
0883b324 37 nsfwPolicy: NSFWPolicyType
ed638e53 38 webTorrentEnabled: boolean
7efe153b 39 autoPlayVideo: boolean
b0f9f39e 40 videoQuota: number
bee0abff 41 videoQuotaDaily: number
2295ce6c 42 account: Account
404b54e1 43 videoChannels: VideoChannel[]
df98563e 44 createdAt: Date
7da18e44 45
eacb25c4
C
46 blocked: boolean
47 blockedReason?: string
48
404b54e1 49 constructor (hash: UserConstructorHash) {
df98563e
C
50 this.id = hash.id
51 this.username = hash.username
52 this.email = hash.email
53 this.role = hash.role
ad9e39fb 54
eacb25c4
C
55 this.videoChannels = hash.videoChannels
56 this.videoQuota = hash.videoQuota
bee0abff 57 this.videoQuotaDaily = hash.videoQuotaDaily
eacb25c4 58 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 59 this.webTorrentEnabled = hash.webTorrentEnabled
eacb25c4
C
60 this.autoPlayVideo = hash.autoPlayVideo
61 this.createdAt = hash.createdAt
62 this.blocked = hash.blocked
63 this.blockedReason = hash.blockedReason
64
ad9e39fb
C
65 if (hash.account !== undefined) {
66 this.account = new Account(hash.account)
67 }
52d9f792
C
68 }
69
70 get accountAvatarUrl () {
71 if (!this.account) return ''
d3e91a5f 72
52d9f792 73 return this.account.avatarUrl
7da18e44
C
74 }
75
954605a8
C
76 hasRight (right: UserRight) {
77 return hasUserRight(this.role, right)
7da18e44 78 }
2295ce6c 79
ce5496d6
C
80 patch (obj: UserServerModel) {
81 for (const key of Object.keys(obj)) {
82 this[key] = obj[key]
83 }
d3e91a5f 84
ad9e39fb
C
85 if (obj.account !== undefined) {
86 this.account = new Account(obj.account)
87 }
d3e91a5f
C
88 }
89
0c237b19 90 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 91 this.account.updateAvatar(newAccountAvatar)
ce5496d6 92 }
7da18e44 93}