1 import { Account, hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
3 import { Actor } from '@app/shared/actor/actor.model'
5 export type UserConstructorHash = {
11 nsfwPolicy?: NSFWPolicyType,
12 autoPlayVideo?: boolean,
15 videoChannels?: VideoChannel[]
17 export class User implements UserServerModel {
22 nsfwPolicy: NSFWPolicyType
23 autoPlayVideo: boolean
26 videoChannels: VideoChannel[]
28 accountAvatarUrl: string
30 constructor (hash: UserConstructorHash) {
32 this.username = hash.username
33 this.email = hash.email
35 this.account = hash.account
37 if (hash.videoChannels !== undefined) {
38 this.videoChannels = hash.videoChannels
41 if (hash.videoQuota !== undefined) {
42 this.videoQuota = hash.videoQuota
45 if (hash.nsfwPolicy !== undefined) {
46 this.nsfwPolicy = hash.nsfwPolicy
49 if (hash.autoPlayVideo !== undefined) {
50 this.autoPlayVideo = hash.autoPlayVideo
53 if (hash.createdAt !== undefined) {
54 this.createdAt = hash.createdAt
57 this.updateComputedAttributes()
60 hasRight (right: UserRight) {
61 return hasUserRight(this.role, right)
64 patch (obj: UserServerModel) {
65 for (const key of Object.keys(obj)) {
69 this.updateComputedAttributes()
72 private updateComputedAttributes () {
73 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)