2 Account as AccountServerModel,
4 User as UserServerModel,
8 } from '../../../../../shared'
9 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
10 import { Account } from '@app/shared/account/account.model'
11 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
13 export type UserConstructorHash = {
19 videoQuotaDaily?: number,
20 nsfwPolicy?: NSFWPolicyType,
21 webTorrentEnabled?: boolean,
22 autoPlayVideo?: boolean,
24 account?: AccountServerModel,
25 videoChannels?: VideoChannel[]
28 blockedReason?: string
30 export class User implements UserServerModel {
35 nsfwPolicy: NSFWPolicyType
36 webTorrentEnabled: boolean
37 autoPlayVideo: boolean
39 videoQuotaDaily: number
41 videoChannels: VideoChannel[]
45 blockedReason?: string
48 constructor (hash: UserConstructorHash) {
50 this.username = hash.username
51 this.email = hash.email
54 this.videoChannels = hash.videoChannels
55 this.videoQuota = hash.videoQuota
56 this.videoQuotaDaily = hash.videoQuotaDaily
57 this.nsfwPolicy = hash.nsfwPolicy
58 this.webTorrentEnabled = hash.webTorrentEnabled
59 this.autoPlayVideo = hash.autoPlayVideo
60 this.createdAt = hash.createdAt
61 this.blocked = hash.blocked
62 this.blockedReason = hash.blockedReason
64 if (hash.account !== undefined) {
65 this.account = new Account(hash.account)
69 get accountAvatarUrl () {
70 if (!this.account) return ''
72 return this.account.avatarUrl
75 hasRight (right: UserRight) {
76 return hasUserRight(this.role, right)
79 patch (obj: UserServerModel) {
80 for (const key of Object.keys(obj)) {
84 if (obj.account !== undefined) {
85 this.account = new Account(obj.account)
89 updateAccountAvatar (newAccountAvatar: Avatar) {
90 this.account.updateAvatar(newAccountAvatar)