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 webTorrentEnabled: boolean
21 videosHistoryEnabled: boolean
22 videoLanguages: string[]
28 videoQuotaDaily: number
29 videoQuotaUsed?: number
30 videoQuotaUsedDaily?: number
35 notificationSettings?: UserNotificationSetting
36 videoChannels?: VideoChannel[]
39 blockedReason?: string
41 noInstanceConfigWarningModal: boolean
42 noWelcomeModal: boolean
46 constructor (hash: Partial<UserServerModel>) {
48 this.username = hash.username
49 this.email = hash.email
53 this.videoChannels = hash.videoChannels
55 this.videoQuota = hash.videoQuota
56 this.videoQuotaDaily = hash.videoQuotaDaily
57 this.videoQuotaUsed = hash.videoQuotaUsed
58 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
60 this.nsfwPolicy = hash.nsfwPolicy
61 this.webTorrentEnabled = hash.webTorrentEnabled
62 this.videosHistoryEnabled = hash.videosHistoryEnabled
63 this.autoPlayVideo = hash.autoPlayVideo
65 this.theme = hash.theme
67 this.adminFlags = hash.adminFlags
69 this.blocked = hash.blocked
70 this.blockedReason = hash.blockedReason
72 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
73 this.noWelcomeModal = hash.noWelcomeModal
75 this.notificationSettings = hash.notificationSettings
77 this.createdAt = hash.createdAt
79 if (hash.account !== undefined) {
80 this.account = new Account(hash.account)
84 get accountAvatarUrl () {
85 if (!this.account) return ''
87 return this.account.avatarUrl
90 hasRight (right: UserRight) {
91 return hasUserRight(this.role, right)
94 patch (obj: UserServerModel) {
95 for (const key of Object.keys(obj)) {
99 if (obj.account !== undefined) {
100 this.account = new Account(obj.account)
104 updateAccountAvatar (newAccountAvatar: Avatar) {
105 this.account.updateAvatar(newAccountAvatar)