2020-11-18 19:20:05 +01:00
|
|
|
import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account, Avatar } 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
|
|
|
|
isLocal: boolean
|
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
|
|
|
|
2018-05-23 11:38:00 +02:00
|
|
|
ownerAccount?: Account
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
static GET_DEFAULT_AVATAR_URL () {
|
|
|
|
return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:43:19 +02:00
|
|
|
constructor (hash: ServerVideoChannel) {
|
|
|
|
super(hash)
|
|
|
|
|
2020-11-18 19:20:05 +01:00
|
|
|
this.updateComputedAttributes()
|
|
|
|
|
2018-04-25 15:43:19 +02:00
|
|
|
this.displayName = hash.displayName
|
|
|
|
this.description = hash.description
|
|
|
|
this.support = hash.support
|
|
|
|
this.isLocal = hash.isLocal
|
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-29 15:56:01 +02:00
|
|
|
this.ownerAvatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this.ownerAccount)
|
2018-05-23 11:38:00 +02:00
|
|
|
}
|
2018-04-25 15:43:19 +02:00
|
|
|
}
|
2020-11-18 19:20:05 +01:00
|
|
|
|
|
|
|
updateAvatar (newAvatar: Avatar) {
|
|
|
|
this.avatar = newAvatar
|
|
|
|
|
|
|
|
this.updateComputedAttributes()
|
|
|
|
}
|
|
|
|
|
2021-01-13 09:12:55 +01:00
|
|
|
resetAvatar () {
|
|
|
|
this.avatar = null
|
|
|
|
this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL()
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:20:05 +01:00
|
|
|
private updateComputedAttributes () {
|
|
|
|
this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
|
|
|
|
}
|
2018-04-25 15:43:19 +02:00
|
|
|
}
|