]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/users/user.model.ts
Add ability to change email in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
index d4551de894b699fa7f358cbeda1bdae01fb17888..14d13959af129b7ac9716c8535e6ff580a7c601c 100644 (file)
@@ -1,60 +1,69 @@
-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
+  pendingEmail: string | null
+  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) {
@@ -66,10 +75,12 @@ export class User implements UserServerModel {
       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)
   }
 }