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