]>
Commit | Line | Data |
---|---|---|
ad9e39fb C |
1 | import { |
2 | Account as AccountServerModel, | |
3 | hasUserRight, | |
4 | User as UserServerModel, | |
5 | UserRight, | |
6 | UserRole, | |
7 | VideoChannel | |
8 | } from '../../../../../shared' | |
0883b324 | 9 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' |
ad9e39fb | 10 | import { Account } from '@app/shared/account/account.model' |
0c237b19 | 11 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
69f616ab | 12 | |
404b54e1 C |
13 | export type UserConstructorHash = { |
14 | id: number, | |
15 | username: string, | |
16 | email: string, | |
17 | role: UserRole, | |
18 | videoQuota?: number, | |
bee0abff | 19 | videoQuotaDaily?: number, |
0883b324 | 20 | nsfwPolicy?: NSFWPolicyType, |
7efe153b | 21 | autoPlayVideo?: boolean, |
404b54e1 | 22 | createdAt?: Date, |
ad9e39fb | 23 | account?: AccountServerModel, |
404b54e1 | 24 | videoChannels?: VideoChannel[] |
eacb25c4 C |
25 | |
26 | blocked?: boolean | |
27 | blockedReason?: string | |
404b54e1 | 28 | } |
69f616ab | 29 | export class User implements UserServerModel { |
df98563e C |
30 | id: number |
31 | username: string | |
32 | email: string | |
33 | role: UserRole | |
0883b324 | 34 | nsfwPolicy: NSFWPolicyType |
7efe153b | 35 | autoPlayVideo: boolean |
b0f9f39e | 36 | videoQuota: number |
bee0abff | 37 | videoQuotaDaily: number |
2295ce6c | 38 | account: Account |
404b54e1 | 39 | videoChannels: VideoChannel[] |
df98563e | 40 | createdAt: Date |
7da18e44 | 41 | |
eacb25c4 C |
42 | blocked: boolean |
43 | blockedReason?: string | |
44 | ||
404b54e1 | 45 | constructor (hash: UserConstructorHash) { |
df98563e C |
46 | this.id = hash.id |
47 | this.username = hash.username | |
48 | this.email = hash.email | |
49 | this.role = hash.role | |
ad9e39fb | 50 | |
eacb25c4 C |
51 | this.videoChannels = hash.videoChannels |
52 | this.videoQuota = hash.videoQuota | |
bee0abff | 53 | this.videoQuotaDaily = hash.videoQuotaDaily |
eacb25c4 C |
54 | this.nsfwPolicy = hash.nsfwPolicy |
55 | this.autoPlayVideo = hash.autoPlayVideo | |
56 | this.createdAt = hash.createdAt | |
57 | this.blocked = hash.blocked | |
58 | this.blockedReason = hash.blockedReason | |
59 | ||
ad9e39fb C |
60 | if (hash.account !== undefined) { |
61 | this.account = new Account(hash.account) | |
62 | } | |
52d9f792 C |
63 | } |
64 | ||
65 | get accountAvatarUrl () { | |
66 | if (!this.account) return '' | |
d3e91a5f | 67 | |
52d9f792 | 68 | return this.account.avatarUrl |
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 | } | |
d3e91a5f C |
83 | } |
84 | ||
0c237b19 | 85 | updateAccountAvatar (newAccountAvatar: Avatar) { |
52d9f792 | 86 | this.account.updateAvatar(newAccountAvatar) |
ce5496d6 | 87 | } |
7da18e44 | 88 | } |