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[]
29 adminFlags?: UserAdminFlag
32 blockedReason?: string
34 notificationSettings?: UserNotificationSetting
36 constructor (hash: Partial<UserServerModel>) {
38 this.username = hash.username
39 this.email = hash.email
43 this.videoChannels = hash.videoChannels
44 this.videoQuota = hash.videoQuota
45 this.videoQuotaDaily = hash.videoQuotaDaily
46 this.nsfwPolicy = hash.nsfwPolicy
47 this.webTorrentEnabled = hash.webTorrentEnabled
48 this.videosHistoryEnabled = hash.videosHistoryEnabled
49 this.autoPlayVideo = hash.autoPlayVideo
50 this.createdAt = hash.createdAt
52 this.adminFlags = hash.adminFlags
54 this.blocked = hash.blocked
55 this.blockedReason = hash.blockedReason
57 this.notificationSettings = hash.notificationSettings
59 if (hash.account !== undefined) {
60 this.account = new Account(hash.account)
64 get accountAvatarUrl () {
65 if (!this.account) return ''
67 return this.account.avatarUrl
70 hasRight (right: UserRight) {
71 return hasUserRight(this.role, right)
74 patch (obj: UserServerModel) {
75 for (const key of Object.keys(obj)) {
79 if (obj.account !== undefined) {
80 this.account = new Account(obj.account)
84 updateAccountAvatar (newAccountAvatar: Avatar) {
85 this.account.updateAvatar(newAccountAvatar)