]>
Commit | Line | Data |
---|---|---|
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' | |
9 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' | |
10 | import { Account } from '@app/shared/account/account.model' | |
11 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' | |
12 | import { UserAdminFlag } from '@shared/models/users/user-flag.model' | |
13 | ||
14 | export class User implements UserServerModel { | |
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 | ||
30 | id: number | |
31 | username: string | |
32 | email: string | |
33 | pendingEmail: string | null | |
34 | ||
35 | emailVerified: boolean | |
36 | nsfwPolicy: NSFWPolicyType | |
37 | ||
38 | adminFlags?: UserAdminFlag | |
39 | ||
40 | autoPlayVideo: boolean | |
41 | autoPlayNextVideo: boolean | |
42 | autoPlayNextVideoPlaylist: boolean | |
43 | webTorrentEnabled: boolean | |
44 | videosHistoryEnabled: boolean | |
45 | videoLanguages: string[] | |
46 | ||
47 | role: UserRole | |
48 | roleLabel: string | |
49 | ||
50 | videoQuota: number | |
51 | videoQuotaDaily: number | |
52 | videoQuotaUsed?: number | |
53 | videoQuotaUsedDaily?: number | |
54 | videosCount?: number | |
55 | videoAbusesCount?: number | |
56 | videoAbusesAcceptedCount?: number | |
57 | videoAbusesCreatedCount?: number | |
58 | videoCommentsCount?: number | |
59 | ||
60 | theme: string | |
61 | ||
62 | account: Account | |
63 | notificationSettings?: UserNotificationSetting | |
64 | videoChannels?: VideoChannel[] | |
65 | ||
66 | blocked: boolean | |
67 | blockedReason?: string | |
68 | ||
69 | noInstanceConfigWarningModal: boolean | |
70 | noWelcomeModal: boolean | |
71 | ||
72 | pluginAuth: string | null | |
73 | ||
74 | createdAt: Date | |
75 | ||
76 | constructor (hash: Partial<UserServerModel>) { | |
77 | this.id = hash.id | |
78 | this.username = hash.username | |
79 | this.email = hash.email | |
80 | ||
81 | this.role = hash.role | |
82 | ||
83 | this.videoChannels = hash.videoChannels | |
84 | ||
85 | this.videoQuota = hash.videoQuota | |
86 | this.videoQuotaDaily = hash.videoQuotaDaily | |
87 | this.videoQuotaUsed = hash.videoQuotaUsed | |
88 | this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily | |
89 | this.videosCount = hash.videosCount | |
90 | this.videoAbusesCount = hash.videoAbusesCount | |
91 | this.videoAbusesAcceptedCount = hash.videoAbusesAcceptedCount | |
92 | this.videoAbusesCreatedCount = hash.videoAbusesCreatedCount | |
93 | this.videoCommentsCount = hash.videoCommentsCount | |
94 | ||
95 | this.nsfwPolicy = hash.nsfwPolicy | |
96 | this.webTorrentEnabled = hash.webTorrentEnabled | |
97 | this.autoPlayVideo = hash.autoPlayVideo | |
98 | this.autoPlayNextVideo = hash.autoPlayNextVideo | |
99 | this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist | |
100 | this.videosHistoryEnabled = hash.videosHistoryEnabled | |
101 | this.videoLanguages = hash.videoLanguages | |
102 | ||
103 | this.theme = hash.theme | |
104 | ||
105 | this.adminFlags = hash.adminFlags | |
106 | ||
107 | this.blocked = hash.blocked | |
108 | this.blockedReason = hash.blockedReason | |
109 | ||
110 | this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal | |
111 | this.noWelcomeModal = hash.noWelcomeModal | |
112 | ||
113 | this.notificationSettings = hash.notificationSettings | |
114 | ||
115 | this.createdAt = hash.createdAt | |
116 | ||
117 | this.pluginAuth = hash.pluginAuth | |
118 | ||
119 | if (hash.account !== undefined) { | |
120 | this.account = new Account(hash.account) | |
121 | } | |
122 | } | |
123 | ||
124 | get accountAvatarUrl () { | |
125 | if (!this.account) return '' | |
126 | ||
127 | return this.account.avatarUrl | |
128 | } | |
129 | ||
130 | hasRight (right: UserRight) { | |
131 | return hasUserRight(this.role, right) | |
132 | } | |
133 | ||
134 | patch (obj: UserServerModel) { | |
135 | for (const key of Object.keys(obj)) { | |
136 | this[key] = obj[key] | |
137 | } | |
138 | ||
139 | if (obj.account !== undefined) { | |
140 | this.account = new Account(obj.account) | |
141 | } | |
142 | } | |
143 | ||
144 | updateAccountAvatar (newAccountAvatar: Avatar) { | |
145 | this.account.updateAvatar(newAccountAvatar) | |
146 | } | |
147 | } |