]>
Commit | Line | Data |
---|---|---|
1 | import { | |
2 | Account as AccountServerModel, | |
3 | hasUserRight, | |
4 | User as UserServerModel, | |
5 | UserRight, | |
6 | UserRole, | |
7 | VideoChannel | |
8 | } from '../../../../../shared' | |
9 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' | |
10 | import { Account } from '@app/shared/account/account.model' | |
11 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' | |
12 | ||
13 | export type UserConstructorHash = { | |
14 | id: number, | |
15 | username: string, | |
16 | email: string, | |
17 | role: UserRole, | |
18 | emailVerified?: boolean, | |
19 | videoQuota?: number, | |
20 | videoQuotaDaily?: number, | |
21 | nsfwPolicy?: NSFWPolicyType, | |
22 | webTorrentEnabled?: boolean, | |
23 | autoPlayVideo?: boolean, | |
24 | createdAt?: Date, | |
25 | account?: AccountServerModel, | |
26 | videoChannels?: VideoChannel[] | |
27 | ||
28 | blocked?: boolean | |
29 | blockedReason?: string | |
30 | } | |
31 | export class User implements UserServerModel { | |
32 | id: number | |
33 | username: string | |
34 | email: string | |
35 | emailVerified: boolean | |
36 | role: UserRole | |
37 | nsfwPolicy: NSFWPolicyType | |
38 | webTorrentEnabled: boolean | |
39 | autoPlayVideo: boolean | |
40 | videoQuota: number | |
41 | videoQuotaDaily: number | |
42 | account: Account | |
43 | videoChannels: VideoChannel[] | |
44 | createdAt: Date | |
45 | ||
46 | blocked: boolean | |
47 | blockedReason?: string | |
48 | ||
49 | constructor (hash: UserConstructorHash) { | |
50 | this.id = hash.id | |
51 | this.username = hash.username | |
52 | this.email = hash.email | |
53 | this.role = hash.role | |
54 | ||
55 | this.videoChannels = hash.videoChannels | |
56 | this.videoQuota = hash.videoQuota | |
57 | this.videoQuotaDaily = hash.videoQuotaDaily | |
58 | this.nsfwPolicy = hash.nsfwPolicy | |
59 | this.webTorrentEnabled = hash.webTorrentEnabled | |
60 | this.autoPlayVideo = hash.autoPlayVideo | |
61 | this.createdAt = hash.createdAt | |
62 | this.blocked = hash.blocked | |
63 | this.blockedReason = hash.blockedReason | |
64 | ||
65 | if (hash.account !== undefined) { | |
66 | this.account = new Account(hash.account) | |
67 | } | |
68 | } | |
69 | ||
70 | get accountAvatarUrl () { | |
71 | if (!this.account) return '' | |
72 | ||
73 | return this.account.avatarUrl | |
74 | } | |
75 | ||
76 | hasRight (right: UserRight) { | |
77 | return hasUserRight(this.role, right) | |
78 | } | |
79 | ||
80 | patch (obj: UserServerModel) { | |
81 | for (const key of Object.keys(obj)) { | |
82 | this[key] = obj[key] | |
83 | } | |
84 | ||
85 | if (obj.account !== undefined) { | |
86 | this.account = new Account(obj.account) | |
87 | } | |
88 | } | |
89 | ||
90 | updateAccountAvatar (newAccountAvatar: Avatar) { | |
91 | this.account.updateAvatar(newAccountAvatar) | |
92 | } | |
93 | } |