]>
Commit | Line | Data |
---|---|---|
2f1548fd | 1 | import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRight, UserRole, VideoChannel } from '../../../../../shared' |
0883b324 | 2 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' |
ad9e39fb | 3 | import { Account } from '@app/shared/account/account.model' |
0c237b19 | 4 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
1eddc9a7 | 5 | import { UserAdminFlag } from '@shared/models/users/user-flag.model' |
69f616ab C |
6 | |
7 | export class User implements UserServerModel { | |
df98563e C |
8 | id: number |
9 | username: string | |
10 | email: string | |
0ba5f5ba | 11 | pendingEmail: string | null |
43d0ea7f | 12 | |
fc2ec87a | 13 | emailVerified: boolean |
0883b324 | 14 | nsfwPolicy: NSFWPolicyType |
276d9652 | 15 | |
43d0ea7f | 16 | adminFlags?: UserAdminFlag |
1eddc9a7 | 17 | |
7efe153b | 18 | autoPlayVideo: boolean |
6aa54148 | 19 | autoPlayNextVideo: boolean |
43d0ea7f | 20 | webTorrentEnabled: boolean |
276d9652 | 21 | videosHistoryEnabled: boolean |
3caf77d3 | 22 | videoLanguages: string[] |
276d9652 | 23 | |
43d0ea7f C |
24 | role: UserRole |
25 | roleLabel: string | |
26 | ||
b0f9f39e | 27 | videoQuota: number |
bee0abff | 28 | videoQuotaDaily: number |
43d0ea7f C |
29 | videoQuotaUsed?: number |
30 | videoQuotaUsedDaily?: number | |
7da18e44 | 31 | |
7cd4d2ba C |
32 | theme: string |
33 | ||
43d0ea7f C |
34 | account: Account |
35 | notificationSettings?: UserNotificationSetting | |
36 | videoChannels?: VideoChannel[] | |
1eddc9a7 | 37 | |
eacb25c4 C |
38 | blocked: boolean |
39 | blockedReason?: string | |
40 | ||
43d0ea7f C |
41 | noInstanceConfigWarningModal: boolean |
42 | noWelcomeModal: boolean | |
43 | ||
44 | createdAt: Date | |
2f1548fd | 45 | |
276d9652 | 46 | constructor (hash: Partial<UserServerModel>) { |
df98563e C |
47 | this.id = hash.id |
48 | this.username = hash.username | |
49 | this.email = hash.email | |
1eddc9a7 | 50 | |
df98563e | 51 | this.role = hash.role |
ad9e39fb | 52 | |
eacb25c4 | 53 | this.videoChannels = hash.videoChannels |
43d0ea7f | 54 | |
eacb25c4 | 55 | this.videoQuota = hash.videoQuota |
bee0abff | 56 | this.videoQuotaDaily = hash.videoQuotaDaily |
43d0ea7f C |
57 | this.videoQuotaUsed = hash.videoQuotaUsed |
58 | this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily | |
59 | ||
eacb25c4 | 60 | this.nsfwPolicy = hash.nsfwPolicy |
ed638e53 | 61 | this.webTorrentEnabled = hash.webTorrentEnabled |
276d9652 | 62 | this.videosHistoryEnabled = hash.videosHistoryEnabled |
eacb25c4 | 63 | this.autoPlayVideo = hash.autoPlayVideo |
1eddc9a7 | 64 | |
7cd4d2ba C |
65 | this.theme = hash.theme |
66 | ||
1eddc9a7 C |
67 | this.adminFlags = hash.adminFlags |
68 | ||
eacb25c4 C |
69 | this.blocked = hash.blocked |
70 | this.blockedReason = hash.blockedReason | |
71 | ||
43d0ea7f C |
72 | this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal |
73 | this.noWelcomeModal = hash.noWelcomeModal | |
74 | ||
2f1548fd C |
75 | this.notificationSettings = hash.notificationSettings |
76 | ||
43d0ea7f C |
77 | this.createdAt = hash.createdAt |
78 | ||
ad9e39fb C |
79 | if (hash.account !== undefined) { |
80 | this.account = new Account(hash.account) | |
81 | } | |
52d9f792 C |
82 | } |
83 | ||
84 | get accountAvatarUrl () { | |
85 | if (!this.account) return '' | |
d3e91a5f | 86 | |
52d9f792 | 87 | return this.account.avatarUrl |
7da18e44 C |
88 | } |
89 | ||
954605a8 C |
90 | hasRight (right: UserRight) { |
91 | return hasUserRight(this.role, right) | |
7da18e44 | 92 | } |
2295ce6c | 93 | |
ce5496d6 C |
94 | patch (obj: UserServerModel) { |
95 | for (const key of Object.keys(obj)) { | |
96 | this[key] = obj[key] | |
97 | } | |
d3e91a5f | 98 | |
ad9e39fb C |
99 | if (obj.account !== undefined) { |
100 | this.account = new Account(obj.account) | |
101 | } | |
d3e91a5f C |
102 | } |
103 | ||
0c237b19 | 104 | updateAccountAvatar (newAccountAvatar: Avatar) { |
52d9f792 | 105 | this.account.updateAvatar(newAccountAvatar) |
ce5496d6 | 106 | } |
7da18e44 | 107 | } |