1 import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account, Avatar } from '@shared/models'
2 import { Actor } from '../account/actor.model'
4 export class VideoChannel extends Actor implements ServerVideoChannel {
10 nameWithHostForced: string
12 ownerAccount?: Account
14 ownerAvatarUrl?: string
18 viewsPerDay?: ViewsPerDate[]
20 static GET_ACTOR_AVATAR_URL (actor: object) {
21 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
24 static GET_DEFAULT_AVATAR_URL () {
25 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
28 constructor (hash: ServerVideoChannel) {
31 this.updateComputedAttributes()
33 this.displayName = hash.displayName
34 this.description = hash.description
35 this.support = hash.support
36 this.isLocal = hash.isLocal
37 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
38 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
40 this.videosCount = hash.videosCount
42 if (hash.viewsPerDay) {
43 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
46 if (hash.ownerAccount) {
47 this.ownerAccount = hash.ownerAccount
48 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
49 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
53 updateAvatar (newAvatar: Avatar) {
54 this.avatar = newAvatar
56 this.updateComputedAttributes()
59 private updateComputedAttributes () {
60 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)