]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
Fix gitlab ci postgresql service
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
CommitLineData
d3217560
RK
1import {
2 hasUserRight,
3 User as UserServerModel,
4 UserNotificationSetting,
5 UserRight,
6 UserRole
7} from '../../../../../shared/models/users'
8import { VideoChannel } from '../../../../../shared/models/videos'
0883b324 9import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
ad9e39fb 10import { Account } from '@app/shared/account/account.model'
0c237b19 11import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
1eddc9a7 12import { UserAdminFlag } from '@shared/models/users/user-flag.model'
69f616ab
C
13
14export 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
76314386
RK
54 videosCount?: number
55 videoAbusesCount?: number
56 videoAbusesAcceptedCount?: number
57 videoAbusesCreatedCount?: number
58 videoCommentsCount?: number
7da18e44 59
7cd4d2ba
C
60 theme: string
61
43d0ea7f
C
62 account: Account
63 notificationSettings?: UserNotificationSetting
64 videoChannels?: VideoChannel[]
1eddc9a7 65
eacb25c4
C
66 blocked: boolean
67 blockedReason?: string
68
43d0ea7f
C
69 noInstanceConfigWarningModal: boolean
70 noWelcomeModal: boolean
71
8bb71f2e
C
72 pluginAuth: string | null
73
43d0ea7f 74 createdAt: Date
2f1548fd 75
276d9652 76 constructor (hash: Partial<UserServerModel>) {
df98563e
C
77 this.id = hash.id
78 this.username = hash.username
79 this.email = hash.email
1eddc9a7 80
df98563e 81 this.role = hash.role
ad9e39fb 82
eacb25c4 83 this.videoChannels = hash.videoChannels
43d0ea7f 84
eacb25c4 85 this.videoQuota = hash.videoQuota
bee0abff 86 this.videoQuotaDaily = hash.videoQuotaDaily
43d0ea7f
C
87 this.videoQuotaUsed = hash.videoQuotaUsed
88 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
76314386
RK
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
43d0ea7f 94
eacb25c4 95 this.nsfwPolicy = hash.nsfwPolicy
ed638e53 96 this.webTorrentEnabled = hash.webTorrentEnabled
eacb25c4 97 this.autoPlayVideo = hash.autoPlayVideo
d3217560
RK
98 this.autoPlayNextVideo = hash.autoPlayNextVideo
99 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
100 this.videosHistoryEnabled = hash.videosHistoryEnabled
101 this.videoLanguages = hash.videoLanguages
1eddc9a7 102
7cd4d2ba
C
103 this.theme = hash.theme
104
1eddc9a7
C
105 this.adminFlags = hash.adminFlags
106
eacb25c4
C
107 this.blocked = hash.blocked
108 this.blockedReason = hash.blockedReason
109
43d0ea7f
C
110 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
111 this.noWelcomeModal = hash.noWelcomeModal
112
2f1548fd
C
113 this.notificationSettings = hash.notificationSettings
114
43d0ea7f
C
115 this.createdAt = hash.createdAt
116
8bb71f2e
C
117 this.pluginAuth = hash.pluginAuth
118
ad9e39fb
C
119 if (hash.account !== undefined) {
120 this.account = new Account(hash.account)
121 }
52d9f792
C
122 }
123
124 get accountAvatarUrl () {
125 if (!this.account) return ''
d3e91a5f 126
52d9f792 127 return this.account.avatarUrl
7da18e44
C
128 }
129
954605a8
C
130 hasRight (right: UserRight) {
131 return hasUserRight(this.role, right)
7da18e44 132 }
2295ce6c 133
ce5496d6
C
134 patch (obj: UserServerModel) {
135 for (const key of Object.keys(obj)) {
136 this[key] = obj[key]
137 }
d3e91a5f 138
ad9e39fb
C
139 if (obj.account !== undefined) {
140 this.account = new Account(obj.account)
141 }
d3e91a5f
C
142 }
143
0c237b19 144 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 145 this.account.updateAvatar(newAccountAvatar)
ce5496d6 146 }
7da18e44 147}