]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/users/user.model.ts
Fix forgot password message regarding email
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
index d4551de894b699fa7f358cbeda1bdae01fb17888..581ea785964d2dee22ac251d5f2571f0adb7ca91 100644 (file)
@@ -1,6 +1,15 @@
-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,
@@ -11,7 +20,7 @@ export type UserConstructorHash = {
   nsfwPolicy?: NSFWPolicyType,
   autoPlayVideo?: boolean,
   createdAt?: Date,
-  account?: Account,
+  account?: AccountServerModel,
   videoChannels?: VideoChannel[]
 }
 export class User implements UserServerModel {
@@ -25,14 +34,16 @@ 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
@@ -53,8 +64,12 @@ export class User implements UserServerModel {
     if (hash.createdAt !== undefined) {
       this.createdAt = hash.createdAt
     }
+  }
 
-    this.updateComputedAttributes()
+  get accountAvatarUrl () {
+    if (!this.account) return ''
+
+    return this.account.avatarUrl
   }
 
   hasRight (right: UserRight) {
@@ -66,10 +81,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)
   }
 }