-import { Account, hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
+import {
+ Account as AccountServerModel,
+ hasUserRight,
+ User as UserServerModel,
+ UserRight,
+ UserRole,
+ VideoChannel
+} from '../../../../../shared'
import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
import { Actor } from '@app/shared/actor/actor.model'
+import { Account } from '@app/shared/account/account.model'
+import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
export type UserConstructorHash = {
id: number,
nsfwPolicy?: NSFWPolicyType,
autoPlayVideo?: boolean,
createdAt?: Date,
- account?: Account,
+ account?: AccountServerModel,
videoChannels?: VideoChannel[]
}
export class User implements UserServerModel {
account: Account
videoChannels: VideoChannel[]
createdAt: Date
- accountAvatarUrl: string
constructor (hash: UserConstructorHash) {
this.id = hash.id
this.username = hash.username
this.email = hash.email
this.role = hash.role
- this.account = hash.account
+
+ if (hash.account !== undefined) {
+ this.account = new Account(hash.account)
+ }
if (hash.videoChannels !== undefined) {
this.videoChannels = hash.videoChannels
if (hash.createdAt !== undefined) {
this.createdAt = hash.createdAt
}
+ }
- this.updateComputedAttributes()
+ get accountAvatarUrl () {
+ if (!this.account) return ''
+
+ return this.account.avatarUrl
}
hasRight (right: UserRight) {
this[key] = obj[key]
}
- this.updateComputedAttributes()
+ if (obj.account !== undefined) {
+ this.account = new Account(obj.account)
+ }
}
- private updateComputedAttributes () {
- this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
+ updateAccountAvatar (newAccountAvatar: Avatar) {
+ this.account.updateAvatar(newAccountAvatar)
}
}