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'
|
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
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
// TODO: remove, deprecated in 4.2
|
|
|
|
banner: never
|
|
|
|
|
|
|
|
banners: ActorImage[]
|
|
|
|
|
2021-04-07 17:01:29 +02:00
|
|
|
bannerUrl: string
|
|
|
|
|
2021-05-10 09:31:33 +02:00
|
|
|
updatedAt: Date | string
|
|
|
|
|
2021-03-31 08:59:52 +02:00
|
|
|
ownerAccount?: ServerAccount
|
2018-05-23 11:38:00 +02:00
|
|
|
ownerBy?: 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
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size: number) {
|
|
|
|
return Actor.GET_ACTOR_AVATAR_URL(actor, size)
|
2020-11-18 19:20:05 +01:00
|
|
|
}
|
|
|
|
|
2021-04-07 17:01:29 +02:00
|
|
|
static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
|
2022-02-28 08:34:43 +01:00
|
|
|
if (!channel) return ''
|
2021-04-07 17:01:29 +02:00
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
const banner = channel.banners[0]
|
|
|
|
if (!banner) return ''
|
2021-04-07 17:01:29 +02:00
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
if (banner.url) return banner.url
|
|
|
|
return getAbsoluteAPIUrl() + banner.path
|
2021-04-07 17:01:29 +02:00
|
|
|
}
|
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
static GET_DEFAULT_AVATAR_URL (size: number) {
|
|
|
|
if (size <= 48) {
|
|
|
|
return `${window.location.origin}/client/assets/images/default-avatar-video-channel-48x48.png`
|
|
|
|
}
|
|
|
|
|
2021-10-12 13:50:40 +02:00
|
|
|
return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
|
2020-11-18 19:20:05 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
this.banners = hash.banners
|
2021-04-07 17:01:29 +02:00
|
|
|
|
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
|
|
|
|
|
2021-05-10 09:31:33 +02:00
|
|
|
if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
|
|
|
|
|
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-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
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
updateAvatar (newAvatars: ActorImage[]) {
|
|
|
|
this.avatars = newAvatars
|
2020-11-18 19:20:05 +01:00
|
|
|
|
|
|
|
this.updateComputedAttributes()
|
|
|
|
}
|
|
|
|
|
2021-01-13 09:12:55 +01:00
|
|
|
resetAvatar () {
|
2022-02-28 08:34:43 +01:00
|
|
|
this.updateAvatar([])
|
2021-04-07 17:01:29 +02:00
|
|
|
}
|
|
|
|
|
2022-02-28 08:34:43 +01:00
|
|
|
updateBanner (newBanners: ActorImage[]) {
|
|
|
|
this.banners = newBanners
|
2021-04-07 17:01:29 +02:00
|
|
|
|
|
|
|
this.updateComputedAttributes()
|
|
|
|
}
|
|
|
|
|
|
|
|
resetBanner () {
|
2022-02-28 08:34:43 +01:00
|
|
|
this.updateBanner([])
|
2021-01-13 09:12:55 +01:00
|
|
|
}
|
|
|
|
|
2021-04-08 12:09:54 +02:00
|
|
|
updateComputedAttributes () {
|
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
|
|
|
}
|