]>
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 | ||
13 | emailVerified: boolean | |
14 | nsfwPolicy: NSFWPolicyType | |
15 | ||
16 | adminFlags?: UserAdminFlag | |
17 | ||
18 | autoPlayVideo: boolean | |
19 | autoPlayNextVideo: boolean | |
20 | webTorrentEnabled: boolean | |
21 | videosHistoryEnabled: boolean | |
22 | videoLanguages: string[] | |
23 | ||
24 | role: UserRole | |
25 | roleLabel: string | |
26 | ||
27 | videoQuota: number | |
28 | videoQuotaDaily: number | |
29 | videoQuotaUsed?: number | |
30 | videoQuotaUsedDaily?: number | |
31 | ||
32 | theme: string | |
33 | ||
34 | account: Account | |
35 | notificationSettings?: UserNotificationSetting | |
36 | videoChannels?: VideoChannel[] | |
37 | ||
38 | blocked: boolean | |
39 | blockedReason?: string | |
40 | ||
41 | noInstanceConfigWarningModal: boolean | |
42 | noWelcomeModal: boolean | |
43 | ||
44 | createdAt: Date | |
45 | ||
46 | constructor (hash: Partial<UserServerModel>) { | |
47 | this.id = hash.id | |
48 | this.username = hash.username | |
49 | this.email = hash.email | |
50 | ||
51 | this.role = hash.role | |
52 | ||
53 | this.videoChannels = hash.videoChannels | |
54 | ||
55 | this.videoQuota = hash.videoQuota | |
56 | this.videoQuotaDaily = hash.videoQuotaDaily | |
57 | this.videoQuotaUsed = hash.videoQuotaUsed | |
58 | this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily | |
59 | ||
60 | this.nsfwPolicy = hash.nsfwPolicy | |
61 | this.webTorrentEnabled = hash.webTorrentEnabled | |
62 | this.videosHistoryEnabled = hash.videosHistoryEnabled | |
63 | this.autoPlayVideo = hash.autoPlayVideo | |
64 | ||
65 | this.theme = hash.theme | |
66 | ||
67 | this.adminFlags = hash.adminFlags | |
68 | ||
69 | this.blocked = hash.blocked | |
70 | this.blockedReason = hash.blockedReason | |
71 | ||
72 | this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal | |
73 | this.noWelcomeModal = hash.noWelcomeModal | |
74 | ||
75 | this.notificationSettings = hash.notificationSettings | |
76 | ||
77 | this.createdAt = hash.createdAt | |
78 | ||
79 | if (hash.account !== undefined) { | |
80 | this.account = new Account(hash.account) | |
81 | } | |
82 | } | |
83 | ||
84 | get accountAvatarUrl () { | |
85 | if (!this.account) return '' | |
86 | ||
87 | return this.account.avatarUrl | |
88 | } | |
89 | ||
90 | hasRight (right: UserRight) { | |
91 | return hasUserRight(this.role, right) | |
92 | } | |
93 | ||
94 | patch (obj: UserServerModel) { | |
95 | for (const key of Object.keys(obj)) { | |
96 | this[key] = obj[key] | |
97 | } | |
98 | ||
99 | if (obj.account !== undefined) { | |
100 | this.account = new Account(obj.account) | |
101 | } | |
102 | } | |
103 | ||
104 | updateAccountAvatar (newAccountAvatar: Avatar) { | |
105 | this.account.updateAvatar(newAccountAvatar) | |
106 | } | |
107 | } |