]>
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, | |
0883b324 | 19 | nsfwPolicy?: NSFWPolicyType, |
7efe153b | 20 | autoPlayVideo?: boolean, |
404b54e1 | 21 | createdAt?: Date, |
ad9e39fb | 22 | account?: AccountServerModel, |
404b54e1 | 23 | videoChannels?: VideoChannel[] |
eacb25c4 C |
24 | |
25 | blocked?: boolean | |
26 | blockedReason?: string | |
404b54e1 | 27 | } |
69f616ab | 28 | export class User implements UserServerModel { |
df98563e C |
29 | id: number |
30 | username: string | |
31 | email: string | |
32 | role: UserRole | |
0883b324 | 33 | nsfwPolicy: NSFWPolicyType |
7efe153b | 34 | autoPlayVideo: boolean |
b0f9f39e | 35 | videoQuota: number |
2295ce6c | 36 | account: Account |
404b54e1 | 37 | videoChannels: VideoChannel[] |
df98563e | 38 | createdAt: Date |
7da18e44 | 39 | |
eacb25c4 C |
40 | blocked: boolean |
41 | blockedReason?: string | |
42 | ||
404b54e1 | 43 | constructor (hash: UserConstructorHash) { |
df98563e C |
44 | this.id = hash.id |
45 | this.username = hash.username | |
46 | this.email = hash.email | |
47 | this.role = hash.role | |
ad9e39fb | 48 | |
eacb25c4 C |
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 | ||
ad9e39fb C |
57 | if (hash.account !== undefined) { |
58 | this.account = new Account(hash.account) | |
59 | } | |
52d9f792 C |
60 | } |
61 | ||
62 | get accountAvatarUrl () { | |
63 | if (!this.account) return '' | |
d3e91a5f | 64 | |
52d9f792 | 65 | return this.account.avatarUrl |
7da18e44 C |
66 | } |
67 | ||
954605a8 C |
68 | hasRight (right: UserRight) { |
69 | return hasUserRight(this.role, right) | |
7da18e44 | 70 | } |
2295ce6c | 71 | |
ce5496d6 C |
72 | patch (obj: UserServerModel) { |
73 | for (const key of Object.keys(obj)) { | |
74 | this[key] = obj[key] | |
75 | } | |
d3e91a5f | 76 | |
ad9e39fb C |
77 | if (obj.account !== undefined) { |
78 | this.account = new Account(obj.account) | |
79 | } | |
d3e91a5f C |
80 | } |
81 | ||
0c237b19 | 82 | updateAccountAvatar (newAccountAvatar: Avatar) { |
52d9f792 | 83 | this.account.updateAvatar(newAccountAvatar) |
ce5496d6 | 84 | } |
7da18e44 | 85 | } |