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