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 emailVerified: boolean
12 nsfwPolicy: NSFWPolicyType
17 webTorrentEnabled: boolean
18 autoPlayVideo: boolean
19 videosHistoryEnabled: boolean
22 videoQuotaDaily: number
24 videoChannels: VideoChannel[]
27 adminFlags?: UserAdminFlag
30 blockedReason?: string
32 notificationSettings?: UserNotificationSetting
34 constructor (hash: Partial<UserServerModel>) {
36 this.username = hash.username
37 this.email = hash.email
41 this.videoChannels = hash.videoChannels
42 this.videoQuota = hash.videoQuota
43 this.videoQuotaDaily = hash.videoQuotaDaily
44 this.nsfwPolicy = hash.nsfwPolicy
45 this.webTorrentEnabled = hash.webTorrentEnabled
46 this.videosHistoryEnabled = hash.videosHistoryEnabled
47 this.autoPlayVideo = hash.autoPlayVideo
48 this.createdAt = hash.createdAt
50 this.adminFlags = hash.adminFlags
52 this.blocked = hash.blocked
53 this.blockedReason = hash.blockedReason
55 this.notificationSettings = hash.notificationSettings
57 if (hash.account !== undefined) {
58 this.account = new Account(hash.account)
62 get accountAvatarUrl () {
63 if (!this.account) return ''
65 return this.account.avatarUrl
68 hasRight (right: UserRight) {
69 return hasUserRight(this.role, right)
72 patch (obj: UserServerModel) {
73 for (const key of Object.keys(obj)) {
77 if (obj.account !== undefined) {
78 this.account = new Account(obj.account)
82 updateAccountAvatar (newAccountAvatar: Avatar) {
83 this.account.updateAvatar(newAccountAvatar)