]>
Commit | Line | Data |
---|---|---|
d3217560 RK |
1 | import { |
2 | hasUserRight, | |
3 | User as UserServerModel, | |
4 | UserNotificationSetting, | |
5 | UserRight, | |
6 | UserRole | |
7 | } from '../../../../../shared/models/users' | |
8 | import { VideoChannel } from '../../../../../shared/models/videos' | |
0883b324 | 9 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' |
ad9e39fb | 10 | import { Account } from '@app/shared/account/account.model' |
0c237b19 | 11 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
1eddc9a7 | 12 | import { UserAdminFlag } from '@shared/models/users/user-flag.model' |
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 | |
7da18e44 | 54 | |
7cd4d2ba C |
55 | theme: string |
56 | ||
43d0ea7f C |
57 | account: Account |
58 | notificationSettings?: UserNotificationSetting | |
59 | videoChannels?: VideoChannel[] | |
1eddc9a7 | 60 | |
eacb25c4 C |
61 | blocked: boolean |
62 | blockedReason?: string | |
63 | ||
43d0ea7f C |
64 | noInstanceConfigWarningModal: boolean |
65 | noWelcomeModal: boolean | |
66 | ||
67 | createdAt: Date | |
2f1548fd | 68 | |
276d9652 | 69 | constructor (hash: Partial<UserServerModel>) { |
df98563e C |
70 | this.id = hash.id |
71 | this.username = hash.username | |
72 | this.email = hash.email | |
1eddc9a7 | 73 | |
df98563e | 74 | this.role = hash.role |
ad9e39fb | 75 | |
eacb25c4 | 76 | this.videoChannels = hash.videoChannels |
43d0ea7f | 77 | |
eacb25c4 | 78 | this.videoQuota = hash.videoQuota |
bee0abff | 79 | this.videoQuotaDaily = hash.videoQuotaDaily |
43d0ea7f C |
80 | this.videoQuotaUsed = hash.videoQuotaUsed |
81 | this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily | |
82 | ||
eacb25c4 | 83 | this.nsfwPolicy = hash.nsfwPolicy |
ed638e53 | 84 | this.webTorrentEnabled = hash.webTorrentEnabled |
eacb25c4 | 85 | this.autoPlayVideo = hash.autoPlayVideo |
d3217560 RK |
86 | this.autoPlayNextVideo = hash.autoPlayNextVideo |
87 | this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist | |
88 | this.videosHistoryEnabled = hash.videosHistoryEnabled | |
89 | this.videoLanguages = hash.videoLanguages | |
1eddc9a7 | 90 | |
7cd4d2ba C |
91 | this.theme = hash.theme |
92 | ||
1eddc9a7 C |
93 | this.adminFlags = hash.adminFlags |
94 | ||
eacb25c4 C |
95 | this.blocked = hash.blocked |
96 | this.blockedReason = hash.blockedReason | |
97 | ||
43d0ea7f C |
98 | this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal |
99 | this.noWelcomeModal = hash.noWelcomeModal | |
100 | ||
2f1548fd C |
101 | this.notificationSettings = hash.notificationSettings |
102 | ||
43d0ea7f C |
103 | this.createdAt = hash.createdAt |
104 | ||
ad9e39fb C |
105 | if (hash.account !== undefined) { |
106 | this.account = new Account(hash.account) | |
107 | } | |
52d9f792 C |
108 | } |
109 | ||
110 | get accountAvatarUrl () { | |
111 | if (!this.account) return '' | |
d3e91a5f | 112 | |
52d9f792 | 113 | return this.account.avatarUrl |
7da18e44 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 | ||
0c237b19 | 130 | updateAccountAvatar (newAccountAvatar: Avatar) { |
52d9f792 | 131 | this.account.updateAvatar(newAccountAvatar) |
ce5496d6 | 132 | } |
7da18e44 | 133 | } |