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
12 emailVerified: boolean
13 nsfwPolicy: NSFWPolicyType
18 webTorrentEnabled: boolean
19 autoPlayVideo: boolean
20 videosHistoryEnabled: boolean
21 videoLanguages: string[]
24 videoQuotaDaily: number
26 videoChannels: VideoChannel[]
31 adminFlags?: UserAdminFlag
34 blockedReason?: string
36 notificationSettings?: UserNotificationSetting
38 constructor (hash: Partial<UserServerModel>) {
40 this.username = hash.username
41 this.email = hash.email
45 this.videoChannels = hash.videoChannels
46 this.videoQuota = hash.videoQuota
47 this.videoQuotaDaily = hash.videoQuotaDaily
48 this.nsfwPolicy = hash.nsfwPolicy
49 this.webTorrentEnabled = hash.webTorrentEnabled
50 this.videosHistoryEnabled = hash.videosHistoryEnabled
51 this.autoPlayVideo = hash.autoPlayVideo
52 this.createdAt = hash.createdAt
54 this.theme = hash.theme
56 this.adminFlags = hash.adminFlags
58 this.blocked = hash.blocked
59 this.blockedReason = hash.blockedReason
61 this.notificationSettings = hash.notificationSettings
63 if (hash.account !== undefined) {
64 this.account = new Account(hash.account)
68 get accountAvatarUrl () {
69 if (!this.account) return ''
71 return this.account.avatarUrl
74 hasRight (right: UserRight) {
75 return hasUserRight(this.role, right)
78 patch (obj: UserServerModel) {
79 for (const key of Object.keys(obj)) {
83 if (obj.account !== undefined) {
84 this.account = new Account(obj.account)
88 updateAccountAvatar (newAccountAvatar: Avatar) {
89 this.account.updateAvatar(newAccountAvatar)