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