-import { Account, hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
+import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRight, UserRole, VideoChannel } from '../../../../../shared'
import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
-import { Actor } from '@app/shared/actor/actor.model'
-
-export type UserConstructorHash = {
- id: number,
- username: string,
- email: string,
- role: UserRole,
- videoQuota?: number,
- nsfwPolicy?: NSFWPolicyType,
- autoPlayVideo?: boolean,
- createdAt?: Date,
- account?: Account,
- videoChannels?: VideoChannel[]
-}
+import { Account } from '@app/shared/account/account.model'
+import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
+import { UserAdminFlag } from '@shared/models/users/user-flag.model'
+
export class User implements UserServerModel {
id: number
username: string
email: string
- role: UserRole
+ emailVerified: boolean
nsfwPolicy: NSFWPolicyType
+
+ role: UserRole
+ roleLabel: string
+
+ webTorrentEnabled: boolean
autoPlayVideo: boolean
+ videosHistoryEnabled: boolean
+
videoQuota: number
+ videoQuotaDaily: number
account: Account
videoChannels: VideoChannel[]
createdAt: Date
- accountAvatarUrl: string
- constructor (hash: UserConstructorHash) {
+ adminFlags?: UserAdminFlag
+
+ blocked: boolean
+ blockedReason?: string
+
+ notificationSettings?: UserNotificationSetting
+
+ constructor (hash: Partial<UserServerModel>) {
this.id = hash.id
this.username = hash.username
this.email = hash.email
+
this.role = hash.role
- this.account = hash.account
- if (hash.videoChannels !== undefined) {
- this.videoChannels = hash.videoChannels
- }
+ this.videoChannels = hash.videoChannels
+ this.videoQuota = hash.videoQuota
+ this.videoQuotaDaily = hash.videoQuotaDaily
+ this.nsfwPolicy = hash.nsfwPolicy
+ this.webTorrentEnabled = hash.webTorrentEnabled
+ this.videosHistoryEnabled = hash.videosHistoryEnabled
+ this.autoPlayVideo = hash.autoPlayVideo
+ this.createdAt = hash.createdAt
- if (hash.videoQuota !== undefined) {
- this.videoQuota = hash.videoQuota
- }
+ this.adminFlags = hash.adminFlags
- if (hash.nsfwPolicy !== undefined) {
- this.nsfwPolicy = hash.nsfwPolicy
- }
+ this.blocked = hash.blocked
+ this.blockedReason = hash.blockedReason
- if (hash.autoPlayVideo !== undefined) {
- this.autoPlayVideo = hash.autoPlayVideo
- }
+ this.notificationSettings = hash.notificationSettings
- if (hash.createdAt !== undefined) {
- this.createdAt = hash.createdAt
+ if (hash.account !== undefined) {
+ this.account = new Account(hash.account)
}
+ }
- 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)
}
}