1 import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
3 import { Account } from '@app/shared/account/account.model'
4 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
7 export class User implements UserServerModel {
11 pendingEmail: string | null
13 emailVerified: boolean
14 nsfwPolicy: NSFWPolicyType
16 adminFlags?: UserAdminFlag
18 autoPlayVideo: boolean
19 autoPlayNextVideo: boolean
20 autoPlayNextVideoPlaylist: boolean
21 webTorrentEnabled: boolean
22 videosHistoryEnabled: boolean
23 videoLanguages: string[]
29 videoQuotaDaily: number
30 videoQuotaUsed?: number
31 videoQuotaUsedDaily?: number
36 notificationSettings?: UserNotificationSetting
37 videoChannels?: VideoChannel[]
40 blockedReason?: string
42 noInstanceConfigWarningModal: boolean
43 noWelcomeModal: boolean
47 constructor (hash: Partial<UserServerModel>) {
49 this.username = hash.username
50 this.email = hash.email
54 this.videoChannels = hash.videoChannels
56 this.videoQuota = hash.videoQuota
57 this.videoQuotaDaily = hash.videoQuotaDaily
58 this.videoQuotaUsed = hash.videoQuotaUsed
59 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
61 this.nsfwPolicy = hash.nsfwPolicy
62 this.webTorrentEnabled = hash.webTorrentEnabled
63 this.videosHistoryEnabled = hash.videosHistoryEnabled
64 this.autoPlayVideo = hash.autoPlayVideo
66 this.theme = hash.theme
68 this.adminFlags = hash.adminFlags
70 this.blocked = hash.blocked
71 this.blockedReason = hash.blockedReason
73 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
74 this.noWelcomeModal = hash.noWelcomeModal
76 this.notificationSettings = hash.notificationSettings
78 this.createdAt = hash.createdAt
80 if (hash.account !== undefined) {
81 this.account = new Account(hash.account)
85 get accountAvatarUrl () {
86 if (!this.account) return ''
88 return this.account.avatarUrl
91 hasRight (right: UserRight) {
92 return hasUserRight(this.role, right)
95 patch (obj: UserServerModel) {
96 for (const key of Object.keys(obj)) {
100 if (obj.account !== undefined) {
101 this.account = new Account(obj.account)
105 updateAccountAvatar (newAccountAvatar: Avatar) {
106 this.account.updateAvatar(newAccountAvatar)