]>
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 | import { UserAdminFlag } from '@shared/models/users/user-flag.model' | |
6 | ||
7 | export class User implements UserServerModel { | |
8 | id: number | |
9 | username: string | |
10 | email: string | |
11 | pendingEmail: string | null | |
12 | emailVerified: boolean | |
13 | nsfwPolicy: NSFWPolicyType | |
14 | ||
15 | role: UserRole | |
16 | roleLabel: string | |
17 | ||
18 | webTorrentEnabled: boolean | |
19 | autoPlayVideo: boolean | |
20 | videosHistoryEnabled: boolean | |
21 | videoLanguages: string[] | |
22 | ||
23 | videoQuota: number | |
24 | videoQuotaDaily: number | |
25 | account: Account | |
26 | videoChannels: VideoChannel[] | |
27 | createdAt: Date | |
28 | ||
29 | adminFlags?: UserAdminFlag | |
30 | ||
31 | blocked: boolean | |
32 | blockedReason?: string | |
33 | ||
34 | notificationSettings?: UserNotificationSetting | |
35 | ||
36 | constructor (hash: Partial<UserServerModel>) { | |
37 | this.id = hash.id | |
38 | this.username = hash.username | |
39 | this.email = hash.email | |
40 | ||
41 | this.role = hash.role | |
42 | ||
43 | this.videoChannels = hash.videoChannels | |
44 | this.videoQuota = hash.videoQuota | |
45 | this.videoQuotaDaily = hash.videoQuotaDaily | |
46 | this.nsfwPolicy = hash.nsfwPolicy | |
47 | this.webTorrentEnabled = hash.webTorrentEnabled | |
48 | this.videosHistoryEnabled = hash.videosHistoryEnabled | |
49 | this.autoPlayVideo = hash.autoPlayVideo | |
50 | this.createdAt = hash.createdAt | |
51 | ||
52 | this.adminFlags = hash.adminFlags | |
53 | ||
54 | this.blocked = hash.blocked | |
55 | this.blockedReason = hash.blockedReason | |
56 | ||
57 | this.notificationSettings = hash.notificationSettings | |
58 | ||
59 | if (hash.account !== undefined) { | |
60 | this.account = new Account(hash.account) | |
61 | } | |
62 | } | |
63 | ||
64 | get accountAvatarUrl () { | |
65 | if (!this.account) return '' | |
66 | ||
67 | return this.account.avatarUrl | |
68 | } | |
69 | ||
70 | hasRight (right: UserRight) { | |
71 | return hasUserRight(this.role, right) | |
72 | } | |
73 | ||
74 | patch (obj: UserServerModel) { | |
75 | for (const key of Object.keys(obj)) { | |
76 | this[key] = obj[key] | |
77 | } | |
78 | ||
79 | if (obj.account !== undefined) { | |
80 | this.account = new Account(obj.account) | |
81 | } | |
82 | } | |
83 | ||
84 | updateAccountAvatar (newAccountAvatar: Avatar) { | |
85 | this.account.updateAvatar(newAccountAvatar) | |
86 | } | |
87 | } |