]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Agnostic actor image storage
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video-channel / video-channel.model.ts
CommitLineData
f4796856 1import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
733dbc53 2import { Account } from '../account/account.model'
67ed6552 3import { Actor } from '../account/actor.model'
d3e91a5f
C
4
5export class VideoChannel extends Actor implements ServerVideoChannel {
6 displayName: string
7 description: string
8 support: string
9 isLocal: boolean
8a19bee1 10 nameWithHost: string
288c78ea 11 nameWithHostForced: string
1ba471c5 12
733dbc53 13 ownerAccount?: ServerAccount
a4f99a76
C
14 ownerBy?: string
15 ownerAvatarUrl?: string
1ba471c5
C
16
17 videosCount?: number
18
3d527ba1 19 viewsPerDay?: ViewsPerDate[]
d3e91a5f 20
c418d483 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
d3e91a5f
C
29 constructor (hash: ServerVideoChannel) {
30 super(hash)
31
c418d483 32 this.updateComputedAttributes()
33
d3e91a5f
C
34 this.displayName = hash.displayName
35 this.description = hash.description
36 this.support = hash.support
37 this.isLocal = hash.isLocal
8a19bee1 38 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
288c78ea 39 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
a4f99a76 40
1ba471c5
C
41 this.videosCount = hash.videosCount
42
8165d00a 43 if (hash.viewsPerDay) {
747c5628 44 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
8165d00a
RK
45 }
46
a4f99a76
C
47 if (hash.ownerAccount) {
48 this.ownerAccount = hash.ownerAccount
49 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
733dbc53 50 this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount)
a4f99a76 51 }
d3e91a5f 52 }
c418d483 53
f4796856 54 updateAvatar (newAvatar: ActorImage) {
c418d483 55 this.avatar = newAvatar
56
57 this.updateComputedAttributes()
58 }
59
1ea7da81
RK
60 resetAvatar () {
61 this.avatar = null
62 this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL()
63 }
64
c418d483 65 private updateComputedAttributes () {
66 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
67 }
d3e91a5f 68}