1 import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2 import { Account } from '../account/account.model'
3 import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
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[]
29 constructor (hash: UserConstructorHash) {
31 this.username = hash.username
32 this.email = hash.email
34 this.account = hash.account
36 if (hash.videoChannels !== undefined) {
37 this.videoChannels = hash.videoChannels
40 if (hash.videoQuota !== undefined) {
41 this.videoQuota = hash.videoQuota
44 if (hash.nsfwPolicy !== undefined) {
45 this.nsfwPolicy = hash.nsfwPolicy
48 if (hash.autoPlayVideo !== undefined) {
49 this.autoPlayVideo = hash.autoPlayVideo
52 if (hash.createdAt !== undefined) {
53 this.createdAt = hash.createdAt
57 hasRight (right: UserRight) {
58 return hasUserRight(this.role, right)
62 return Account.GET_ACCOUNT_AVATAR_URL(this.account)
65 patch (obj: UserServerModel) {
66 for (const key of Object.keys(obj)) {