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
23 videoQuotaDaily: number
25 videoChannels: VideoChannel[]
28 adminFlags?: UserAdminFlag
31 blockedReason?: string
33 notificationSettings?: UserNotificationSetting
35 constructor (hash: Partial<UserServerModel>) {
37 this.username = hash.username
38 this.email = hash.email
42 this.videoChannels = hash.videoChannels
43 this.videoQuota = hash.videoQuota
44 this.videoQuotaDaily = hash.videoQuotaDaily
45 this.nsfwPolicy = hash.nsfwPolicy
46 this.webTorrentEnabled = hash.webTorrentEnabled
47 this.videosHistoryEnabled = hash.videosHistoryEnabled
48 this.autoPlayVideo = hash.autoPlayVideo
49 this.createdAt = hash.createdAt
51 this.adminFlags = hash.adminFlags
53 this.blocked = hash.blocked
54 this.blockedReason = hash.blockedReason
56 this.notificationSettings = hash.notificationSettings
58 if (hash.account !== undefined) {
59 this.account = new Account(hash.account)
63 get accountAvatarUrl () {
64 if (!this.account) return ''
66 return this.account.avatarUrl
69 hasRight (right: UserRight) {
70 return hasUserRight(this.role, right)
73 patch (obj: UserServerModel) {
74 for (const key of Object.keys(obj)) {
78 if (obj.account !== undefined) {
79 this.account = new Account(obj.account)
83 updateAccountAvatar (newAccountAvatar: Avatar) {
84 this.account.updateAvatar(newAccountAvatar)