]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Channel/account page redesign feedbacks
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video-channel / video-channel.model.ts
1 import { Account as ServerAccount, Avatar, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
2 import { Account } from '../account/account.model'
3 import { Actor } from '../account/actor.model'
4
5 export class VideoChannel extends Actor implements ServerVideoChannel {
6 displayName: string
7 description: string
8 support: string
9 isLocal: boolean
10 nameWithHost: string
11 nameWithHostForced: string
12
13 ownerAccount?: ServerAccount
14 ownerBy?: string
15 ownerAvatarUrl?: string
16
17 videosCount?: number
18
19 viewsPerDay?: ViewsPerDate[]
20
21 static GET_ACTOR_AVATAR_URL (actor: object) {
22 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
23 }
24
25 static GET_DEFAULT_AVATAR_URL () {
26 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
27 }
28
29 constructor (hash: ServerVideoChannel) {
30 super(hash)
31
32 this.updateComputedAttributes()
33
34 this.displayName = hash.displayName
35 this.description = hash.description
36 this.support = hash.support
37 this.isLocal = hash.isLocal
38 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
39 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
40
41 this.videosCount = hash.videosCount
42
43 if (hash.viewsPerDay) {
44 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
45 }
46
47 if (hash.ownerAccount) {
48 this.ownerAccount = hash.ownerAccount
49 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
50 this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount)
51 }
52 }
53
54 updateAvatar (newAvatar: Avatar) {
55 this.avatar = newAvatar
56
57 this.updateComputedAttributes()
58 }
59
60 resetAvatar () {
61 this.avatar = null
62 this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL()
63 }
64
65 private updateComputedAttributes () {
66 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
67 }
68 }