]>
Commit | Line | Data |
---|---|---|
2295ce6c | 1 | import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared' |
b1fa3eba | 2 | import { Account } from '../account/account.model' |
0883b324 | 3 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' |
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 |
7da18e44 | 28 | |
404b54e1 | 29 | constructor (hash: UserConstructorHash) { |
df98563e C |
30 | this.id = hash.id |
31 | this.username = hash.username | |
32 | this.email = hash.email | |
33 | this.role = hash.role | |
1e1265b3 | 34 | this.account = hash.account |
404b54e1 C |
35 | |
36 | if (hash.videoChannels !== undefined) { | |
37 | this.videoChannels = hash.videoChannels | |
38 | } | |
44c5275e | 39 | |
b0f9f39e C |
40 | if (hash.videoQuota !== undefined) { |
41 | this.videoQuota = hash.videoQuota | |
42 | } | |
43 | ||
0883b324 C |
44 | if (hash.nsfwPolicy !== undefined) { |
45 | this.nsfwPolicy = hash.nsfwPolicy | |
b0f9f39e C |
46 | } |
47 | ||
7efe153b AL |
48 | if (hash.autoPlayVideo !== undefined) { |
49 | this.autoPlayVideo = hash.autoPlayVideo | |
50 | } | |
51 | ||
b0f9f39e | 52 | if (hash.createdAt !== undefined) { |
df98563e | 53 | this.createdAt = hash.createdAt |
44c5275e | 54 | } |
7da18e44 C |
55 | } |
56 | ||
954605a8 C |
57 | hasRight (right: UserRight) { |
58 | return hasUserRight(this.role, right) | |
7da18e44 | 59 | } |
2295ce6c | 60 | |
c5911fd3 C |
61 | getAvatarUrl () { |
62 | return Account.GET_ACCOUNT_AVATAR_URL(this.account) | |
2295ce6c | 63 | } |
ce5496d6 C |
64 | |
65 | patch (obj: UserServerModel) { | |
66 | for (const key of Object.keys(obj)) { | |
67 | this[key] = obj[key] | |
68 | } | |
69 | } | |
7da18e44 | 70 | } |