]>
Commit | Line | Data |
---|---|---|
1 | import { Account } from '@app/shared/shared-main/account/account.model' | |
2 | import { hasUserRight } from '@shared/core-utils/users' | |
3 | import { | |
4 | Avatar, | |
5 | NSFWPolicyType, | |
6 | User as UserServerModel, | |
7 | UserAdminFlag, | |
8 | UserNotificationSetting, | |
9 | UserRight, | |
10 | UserRole, | |
11 | VideoChannel | |
12 | } from '@shared/models' | |
13 | import { UserKeys } from '@root-helpers/user-keys' | |
14 | ||
15 | export class User implements UserServerModel { | |
16 | static KEYS = UserKeys | |
17 | ||
18 | id: number | |
19 | username: string | |
20 | email: string | |
21 | pendingEmail: string | null | |
22 | ||
23 | emailVerified: boolean | |
24 | nsfwPolicy: NSFWPolicyType | |
25 | ||
26 | adminFlags?: UserAdminFlag | |
27 | ||
28 | autoPlayVideo: boolean | |
29 | autoPlayNextVideo: boolean | |
30 | autoPlayNextVideoPlaylist: boolean | |
31 | webTorrentEnabled: boolean | |
32 | videosHistoryEnabled: boolean | |
33 | videoLanguages: string[] | |
34 | ||
35 | role: UserRole | |
36 | roleLabel: string | |
37 | ||
38 | videoQuota: number | |
39 | videoQuotaDaily: number | |
40 | videoQuotaUsed?: number | |
41 | videoQuotaUsedDaily?: number | |
42 | ||
43 | videosCount?: number | |
44 | videoCommentsCount?: number | |
45 | ||
46 | abusesCount?: number | |
47 | abusesAcceptedCount?: number | |
48 | abusesCreatedCount?: number | |
49 | ||
50 | theme: string | |
51 | ||
52 | account: Account | |
53 | notificationSettings?: UserNotificationSetting | |
54 | videoChannels?: VideoChannel[] | |
55 | ||
56 | blocked: boolean | |
57 | blockedReason?: string | |
58 | ||
59 | noInstanceConfigWarningModal: boolean | |
60 | noWelcomeModal: boolean | |
61 | ||
62 | pluginAuth: string | null | |
63 | ||
64 | lastLoginDate: Date | null | |
65 | ||
66 | createdAt: Date | |
67 | ||
68 | constructor (hash: Partial<UserServerModel>) { | |
69 | this.id = hash.id | |
70 | this.username = hash.username | |
71 | this.email = hash.email | |
72 | ||
73 | this.role = hash.role | |
74 | ||
75 | this.videoChannels = hash.videoChannels | |
76 | ||
77 | this.videoQuota = hash.videoQuota | |
78 | this.videoQuotaDaily = hash.videoQuotaDaily | |
79 | this.videoQuotaUsed = hash.videoQuotaUsed | |
80 | this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily | |
81 | this.videosCount = hash.videosCount | |
82 | this.abusesCount = hash.abusesCount | |
83 | this.abusesAcceptedCount = hash.abusesAcceptedCount | |
84 | this.abusesCreatedCount = hash.abusesCreatedCount | |
85 | this.videoCommentsCount = hash.videoCommentsCount | |
86 | ||
87 | this.nsfwPolicy = hash.nsfwPolicy | |
88 | this.webTorrentEnabled = hash.webTorrentEnabled | |
89 | this.autoPlayVideo = hash.autoPlayVideo | |
90 | this.autoPlayNextVideo = hash.autoPlayNextVideo | |
91 | this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist | |
92 | this.videosHistoryEnabled = hash.videosHistoryEnabled | |
93 | this.videoLanguages = hash.videoLanguages | |
94 | ||
95 | this.theme = hash.theme | |
96 | ||
97 | this.adminFlags = hash.adminFlags | |
98 | ||
99 | this.blocked = hash.blocked | |
100 | this.blockedReason = hash.blockedReason | |
101 | ||
102 | this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal | |
103 | this.noWelcomeModal = hash.noWelcomeModal | |
104 | ||
105 | this.notificationSettings = hash.notificationSettings | |
106 | ||
107 | this.createdAt = hash.createdAt | |
108 | ||
109 | this.pluginAuth = hash.pluginAuth | |
110 | this.lastLoginDate = hash.lastLoginDate | |
111 | ||
112 | if (hash.account !== undefined) { | |
113 | this.account = new Account(hash.account) | |
114 | } | |
115 | } | |
116 | ||
117 | get accountAvatarUrl () { | |
118 | if (!this.account) return '' | |
119 | ||
120 | return this.account.avatarUrl | |
121 | } | |
122 | ||
123 | hasRight (right: UserRight) { | |
124 | return hasUserRight(this.role, right) | |
125 | } | |
126 | ||
127 | patch (obj: UserServerModel) { | |
128 | for (const key of Object.keys(obj)) { | |
129 | this[key] = obj[key] | |
130 | } | |
131 | ||
132 | if (obj.account !== undefined) { | |
133 | this.account = new Account(obj.account) | |
134 | } | |
135 | } | |
136 | ||
137 | updateAccountAvatar (newAccountAvatar: Avatar) { | |
138 | this.account.updateAvatar(newAccountAvatar) | |
139 | } | |
140 | ||
141 | isUploadDisabled () { | |
142 | return this.videoQuota === 0 || this.videoQuotaDaily === 0 | |
143 | } | |
144 | } |