]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/users/user.model.ts
Fix margin-content and miniature thumbnail width on mobile, fix media queries for...
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
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 createdAt: Date
73
74 constructor (hash: Partial<UserServerModel>) {
75 this.id = hash.id
76 this.username = hash.username
77 this.email = hash.email
78
79 this.role = hash.role
80
81 this.videoChannels = hash.videoChannels
82
83 this.videoQuota = hash.videoQuota
84 this.videoQuotaDaily = hash.videoQuotaDaily
85 this.videoQuotaUsed = hash.videoQuotaUsed
86 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
87 this.videosCount = hash.videosCount
88 this.videoAbusesCount = hash.videoAbusesCount
89 this.videoAbusesAcceptedCount = hash.videoAbusesAcceptedCount
90 this.videoAbusesCreatedCount = hash.videoAbusesCreatedCount
91 this.videoCommentsCount = hash.videoCommentsCount
92
93 this.nsfwPolicy = hash.nsfwPolicy
94 this.webTorrentEnabled = hash.webTorrentEnabled
95 this.autoPlayVideo = hash.autoPlayVideo
96 this.autoPlayNextVideo = hash.autoPlayNextVideo
97 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
98 this.videosHistoryEnabled = hash.videosHistoryEnabled
99 this.videoLanguages = hash.videoLanguages
100
101 this.theme = hash.theme
102
103 this.adminFlags = hash.adminFlags
104
105 this.blocked = hash.blocked
106 this.blockedReason = hash.blockedReason
107
108 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
109 this.noWelcomeModal = hash.noWelcomeModal
110
111 this.notificationSettings = hash.notificationSettings
112
113 this.createdAt = hash.createdAt
114
115 if (hash.account !== undefined) {
116 this.account = new Account(hash.account)
117 }
118 }
119
120 get accountAvatarUrl () {
121 if (!this.account) return ''
122
123 return this.account.avatarUrl
124 }
125
126 hasRight (right: UserRight) {
127 return hasUserRight(this.role, right)
128 }
129
130 patch (obj: UserServerModel) {
131 for (const key of Object.keys(obj)) {
132 this[key] = obj[key]
133 }
134
135 if (obj.account !== undefined) {
136 this.account = new Account(obj.account)
137 }
138 }
139
140 updateAccountAvatar (newAccountAvatar: Avatar) {
141 this.account.updateAvatar(newAccountAvatar)
142 }
143 }