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'
6 export class User implements UserServerModel {
10 emailVerified: boolean
12 nsfwPolicy: NSFWPolicyType
14 webTorrentEnabled: boolean
15 autoPlayVideo: boolean
16 videosHistoryEnabled: boolean
19 videoQuotaDaily: number
21 videoChannels: VideoChannel[]
25 blockedReason?: string
27 notificationSettings?: UserNotificationSetting
29 constructor (hash: Partial<UserServerModel>) {
31 this.username = hash.username
32 this.email = hash.email
35 this.videoChannels = hash.videoChannels
36 this.videoQuota = hash.videoQuota
37 this.videoQuotaDaily = hash.videoQuotaDaily
38 this.nsfwPolicy = hash.nsfwPolicy
39 this.webTorrentEnabled = hash.webTorrentEnabled
40 this.videosHistoryEnabled = hash.videosHistoryEnabled
41 this.autoPlayVideo = hash.autoPlayVideo
42 this.createdAt = hash.createdAt
43 this.blocked = hash.blocked
44 this.blockedReason = hash.blockedReason
46 this.notificationSettings = hash.notificationSettings
48 if (hash.account !== undefined) {
49 this.account = new Account(hash.account)
53 get accountAvatarUrl () {
54 if (!this.account) return ''
56 return this.account.avatarUrl
59 hasRight (right: UserRight) {
60 return hasUserRight(this.role, right)
63 patch (obj: UserServerModel) {
64 for (const key of Object.keys(obj)) {
68 if (obj.account !== undefined) {
69 this.account = new Account(obj.account)
73 updateAccountAvatar (newAccountAvatar: Avatar) {
74 this.account.updateAvatar(newAccountAvatar)