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