1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
3 import { Account } from '../account/account.model'
4 import { Actor } from '../account/actor.model'
6 export class VideoChannel extends Actor implements ServerVideoChannel {
14 nameWithHostForced: string
19 ownerAccount?: ServerAccount
21 ownerAvatarUrl?: string
25 viewsPerDay?: ViewsPerDate[]
27 static GET_ACTOR_AVATAR_URL (actor: object) {
28 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
31 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
32 if (channel?.banner?.url) return channel.banner.url
34 if (channel && channel.banner) {
35 const absoluteAPIUrl = getAbsoluteAPIUrl()
37 return absoluteAPIUrl + channel.banner.path
43 static GET_DEFAULT_AVATAR_URL () {
44 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
47 constructor (hash: Partial<ServerVideoChannel>) {
50 this.displayName = hash.displayName
51 this.description = hash.description
52 this.support = hash.support
54 this.banner = hash.banner
56 this.isLocal = hash.isLocal
58 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
59 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
61 this.videosCount = hash.videosCount
63 if (hash.viewsPerDay) {
64 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
67 if (hash.ownerAccount) {
68 this.ownerAccount = hash.ownerAccount
69 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
70 this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount)
73 this.updateComputedAttributes()
76 updateAvatar (newAvatar: ActorImage) {
77 this.avatar = newAvatar
79 this.updateComputedAttributes()
83 this.updateAvatar(null)
86 updateBanner (newBanner: ActorImage) {
87 this.banner = newBanner
89 this.updateComputedAttributes()
93 this.updateBanner(null)
96 updateComputedAttributes () {
97 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
98 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)