1 import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
2 import { Account } from '../account/account.model'
3 import { Actor } from '../account/actor.model'
5 export class VideoChannel extends Actor implements ServerVideoChannel {
11 nameWithHostForced: string
13 ownerAccount?: ServerAccount
15 ownerAvatarUrl?: string
19 viewsPerDay?: ViewsPerDate[]
21 static GET_ACTOR_AVATAR_URL (actor: object) {
22 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
25 static GET_DEFAULT_AVATAR_URL () {
26 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
29 constructor (hash: ServerVideoChannel) {
32 this.updateComputedAttributes()
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)
41 this.videosCount = hash.videosCount
43 if (hash.viewsPerDay) {
44 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
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)
54 updateAvatar (newAvatar: ActorImage) {
55 this.avatar = newAvatar
57 this.updateComputedAttributes()
62 this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL()
65 private updateComputedAttributes () {
66 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)