PeerTube/client/src/app/shared/shared-main/video-channel/video-channel.model.ts

98 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-04-07 17:01:29 +02:00
import { getAbsoluteAPIUrl } from '@app/helpers'
2021-04-06 11:35:56 +02:00
import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
import { Account } from '../account/account.model'
2020-06-23 14:10:17 +02:00
import { Actor } from '../account/actor.model'
2018-04-25 15:43:19 +02:00
export class VideoChannel extends Actor implements ServerVideoChannel {
displayName: string
description: string
support: string
2021-04-07 17:01:29 +02:00
2018-04-25 15:43:19 +02:00
isLocal: boolean
2021-04-07 17:01:29 +02:00
2018-08-17 15:45:42 +02:00
nameWithHost: string
nameWithHostForced: string
2020-06-16 14:13:01 +02:00
2021-04-07 17:01:29 +02:00
banner: ActorImage
bannerUrl: string
ownerAccount?: ServerAccount
2018-05-23 11:38:00 +02:00
ownerBy?: string
2020-06-16 14:13:01 +02:00
videosCount?: number
viewsPerDay?: ViewsPerDate[]
2018-04-25 15:43:19 +02:00
static GET_ACTOR_AVATAR_URL (actor: object) {
2021-04-28 11:49:34 +02:00
return Actor.GET_ACTOR_AVATAR_URL(actor)
}
2021-04-07 17:01:29 +02:00
static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
if (channel?.banner?.url) return channel.banner.url
if (channel && channel.banner) {
const absoluteAPIUrl = getAbsoluteAPIUrl()
return absoluteAPIUrl + channel.banner.path
}
return ''
}
static GET_DEFAULT_AVATAR_URL () {
return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
}
constructor (hash: Partial<ServerVideoChannel>) {
2018-04-25 15:43:19 +02:00
super(hash)
this.displayName = hash.displayName
this.description = hash.description
this.support = hash.support
2021-04-07 17:01:29 +02:00
this.banner = hash.banner
2018-04-25 15:43:19 +02:00
this.isLocal = hash.isLocal
2021-04-07 17:01:29 +02:00
2018-08-17 15:45:42 +02:00
this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
2018-05-23 11:38:00 +02:00
2020-06-16 14:13:01 +02:00
this.videosCount = hash.videosCount
2020-03-23 10:14:05 +01:00
if (hash.viewsPerDay) {
this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
2020-03-23 10:14:05 +01:00
}
2018-05-23 11:38:00 +02:00
if (hash.ownerAccount) {
this.ownerAccount = hash.ownerAccount
this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
}
2021-04-07 17:01:29 +02:00
this.updateComputedAttributes()
2018-04-25 15:43:19 +02:00
}
2021-04-06 11:35:56 +02:00
updateAvatar (newAvatar: ActorImage) {
this.avatar = newAvatar
this.updateComputedAttributes()
}
resetAvatar () {
2021-04-07 17:01:29 +02:00
this.updateAvatar(null)
}
updateBanner (newBanner: ActorImage) {
this.banner = newBanner
this.updateComputedAttributes()
}
resetBanner () {
this.updateBanner(null)
}
updateComputedAttributes () {
2021-04-07 17:01:29 +02:00
this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
}
2018-04-25 15:43:19 +02:00
}