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'
|
2021-03-31 08:59:52 +02:00
|
|
|
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
|
2020-03-05 23:49:12 +01:00
|
|
|
nameWithHostForced: string
|
2020-06-16 14:13:01 +02:00
|
|
|
|
2021-04-07 17:01:29 +02:00
|
|
|
banner: ActorImage
|
|
|
|
bannerUrl: string
|
|
|
|
|
2021-03-31 08:59:52 +02:00
|
|
|
ownerAccount?: ServerAccount
|
2018-05-23 11:38:00 +02:00
|
|
|
ownerBy?: string
|
|
|
|
ownerAvatarUrl?: string
|
2020-06-16 14:13:01 +02:00
|
|
|
|
|
|
|
videosCount?: number
|
|
|
|
|
2020-03-30 12:06:46 +02:00
|
|
|
viewsPerDay?: ViewsPerDate[]
|
2018-04-25 15:43:19 +02:00
|
|
|
|
2020-11-18 19:20:05 +01:00
|
|
|
static GET_ACTOR_AVATAR_URL (actor: object) {
|
|
|
|
return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
|
|
|
|
}
|
|
|
|
|
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 ''
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:20:05 +01:00
|
|
|
static GET_DEFAULT_AVATAR_URL () {
|
|
|
|
return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
|
|
|
|
}
|
|
|
|
|
2021-04-08 12:09:54 +02:00
|
|
|
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)
|
2020-03-05 23:49:12 +01:00
|
|
|
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) {
|
2020-03-24 01:12:30 +01:00
|
|
|
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-03-31 08:59:52 +02:00
|
|
|
this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount)
|
2018-05-23 11:38:00 +02:00
|
|
|
}
|
2021-04-07 17:01:29 +02:00
|
|
|
|
|
|
|
this.updateComputedAttributes()
|
2018-04-25 15:43:19 +02:00
|
|
|
}
|
2020-11-18 19:20:05 +01:00
|
|
|
|
2021-04-06 11:35:56 +02:00
|
|
|
updateAvatar (newAvatar: ActorImage) {
|
2020-11-18 19:20:05 +01:00
|
|
|
this.avatar = newAvatar
|
|
|
|
|
|
|
|
this.updateComputedAttributes()
|
|
|
|
}
|
|
|
|
|
2021-01-13 09:12:55 +01:00
|
|
|
resetAvatar () {
|
2021-04-07 17:01:29 +02:00
|
|
|
this.updateAvatar(null)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateBanner (newBanner: ActorImage) {
|
|
|
|
this.banner = newBanner
|
|
|
|
|
|
|
|
this.updateComputedAttributes()
|
|
|
|
}
|
|
|
|
|
|
|
|
resetBanner () {
|
|
|
|
this.updateBanner(null)
|
2021-01-13 09:12:55 +01:00
|
|
|
}
|
|
|
|
|
2021-04-08 12:09:54 +02:00
|
|
|
updateComputedAttributes () {
|
2020-11-18 19:20:05 +01:00
|
|
|
this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
|
2021-04-07 17:01:29 +02:00
|
|
|
this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
|
2020-11-18 19:20:05 +01:00
|
|
|
}
|
2018-04-25 15:43:19 +02:00
|
|
|
}
|