]>
Commit | Line | Data |
---|---|---|
d3e91a5f | 1 | import { Account, hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared' |
0883b324 | 2 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' |
d3e91a5f | 3 | import { Actor } from '@app/shared/actor/actor.model' |
69f616ab | 4 | |
404b54e1 C |
5 | export type UserConstructorHash = { |
6 | id: number, | |
7 | username: string, | |
8 | email: string, | |
9 | role: UserRole, | |
10 | videoQuota?: number, | |
0883b324 | 11 | nsfwPolicy?: NSFWPolicyType, |
7efe153b | 12 | autoPlayVideo?: boolean, |
404b54e1 | 13 | createdAt?: Date, |
2295ce6c | 14 | account?: Account, |
404b54e1 C |
15 | videoChannels?: VideoChannel[] |
16 | } | |
69f616ab | 17 | export class User implements UserServerModel { |
df98563e C |
18 | id: number |
19 | username: string | |
20 | email: string | |
21 | role: UserRole | |
0883b324 | 22 | nsfwPolicy: NSFWPolicyType |
7efe153b | 23 | autoPlayVideo: boolean |
b0f9f39e | 24 | videoQuota: number |
2295ce6c | 25 | account: Account |
404b54e1 | 26 | videoChannels: VideoChannel[] |
df98563e | 27 | createdAt: Date |
d3e91a5f | 28 | accountAvatarUrl: string |
7da18e44 | 29 | |
404b54e1 | 30 | constructor (hash: UserConstructorHash) { |
df98563e C |
31 | this.id = hash.id |
32 | this.username = hash.username | |
33 | this.email = hash.email | |
34 | this.role = hash.role | |
1e1265b3 | 35 | this.account = hash.account |
404b54e1 C |
36 | |
37 | if (hash.videoChannels !== undefined) { | |
38 | this.videoChannels = hash.videoChannels | |
39 | } | |
44c5275e | 40 | |
b0f9f39e C |
41 | if (hash.videoQuota !== undefined) { |
42 | this.videoQuota = hash.videoQuota | |
43 | } | |
44 | ||
0883b324 C |
45 | if (hash.nsfwPolicy !== undefined) { |
46 | this.nsfwPolicy = hash.nsfwPolicy | |
b0f9f39e C |
47 | } |
48 | ||
7efe153b AL |
49 | if (hash.autoPlayVideo !== undefined) { |
50 | this.autoPlayVideo = hash.autoPlayVideo | |
51 | } | |
52 | ||
b0f9f39e | 53 | if (hash.createdAt !== undefined) { |
df98563e | 54 | this.createdAt = hash.createdAt |
44c5275e | 55 | } |
d3e91a5f C |
56 | |
57 | this.updateComputedAttributes() | |
7da18e44 C |
58 | } |
59 | ||
954605a8 C |
60 | hasRight (right: UserRight) { |
61 | return hasUserRight(this.role, right) | |
7da18e44 | 62 | } |
2295ce6c | 63 | |
ce5496d6 C |
64 | patch (obj: UserServerModel) { |
65 | for (const key of Object.keys(obj)) { | |
66 | this[key] = obj[key] | |
67 | } | |
d3e91a5f C |
68 | |
69 | this.updateComputedAttributes() | |
70 | } | |
71 | ||
72 | private updateComputedAttributes () { | |
73 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) | |
ce5496d6 | 74 | } |
7da18e44 | 75 | } |