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