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