]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Merge branch 'release/3.4.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video-channel / video-channel.model.ts
CommitLineData
cdeddff1 1import { getAbsoluteAPIUrl } from '@app/helpers'
f4796856 2import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
67ed6552 3import { Actor } from '../account/actor.model'
d3e91a5f
C
4
5export class VideoChannel extends Actor implements ServerVideoChannel {
6 displayName: string
7 description: string
8 support: string
cdeddff1 9
d3e91a5f 10 isLocal: boolean
cdeddff1 11
8a19bee1 12 nameWithHost: string
288c78ea 13 nameWithHostForced: string
1ba471c5 14
cdeddff1
C
15 banner: ActorImage
16 bannerUrl: string
17
dc2b2938
C
18 updatedAt: Date | string
19
733dbc53 20 ownerAccount?: ServerAccount
a4f99a76 21 ownerBy?: string
1ba471c5
C
22
23 videosCount?: number
24
3d527ba1 25 viewsPerDay?: ViewsPerDate[]
d3e91a5f 26
9df52d66 27 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
746018f6 28 return Actor.GET_ACTOR_AVATAR_URL(actor)
c418d483 29 }
30
cdeddff1
C
31 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
32 if (channel?.banner?.url) return channel.banner.url
33
9df52d66 34 if (channel?.banner) {
cdeddff1
C
35 const absoluteAPIUrl = getAbsoluteAPIUrl()
36
37 return absoluteAPIUrl + channel.banner.path
38 }
39
40 return ''
41 }
42
c418d483 43 static GET_DEFAULT_AVATAR_URL () {
c80e458a 44 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
c418d483 45 }
46
27ec473f 47 constructor (hash: Partial<ServerVideoChannel>) {
d3e91a5f
C
48 super(hash)
49
50 this.displayName = hash.displayName
51 this.description = hash.description
52 this.support = hash.support
cdeddff1
C
53
54 this.banner = hash.banner
55
d3e91a5f 56 this.isLocal = hash.isLocal
cdeddff1 57
8a19bee1 58 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
288c78ea 59 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
a4f99a76 60
1ba471c5
C
61 this.videosCount = hash.videosCount
62
dc2b2938
C
63 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
64
8165d00a 65 if (hash.viewsPerDay) {
747c5628 66 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
8165d00a
RK
67 }
68
a4f99a76
C
69 if (hash.ownerAccount) {
70 this.ownerAccount = hash.ownerAccount
71 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
a4f99a76 72 }
cdeddff1
C
73
74 this.updateComputedAttributes()
d3e91a5f 75 }
c418d483 76
f4796856 77 updateAvatar (newAvatar: ActorImage) {
c418d483 78 this.avatar = newAvatar
79
80 this.updateComputedAttributes()
81 }
82
1ea7da81 83 resetAvatar () {
cdeddff1
C
84 this.updateAvatar(null)
85 }
86
87 updateBanner (newBanner: ActorImage) {
88 this.banner = newBanner
89
90 this.updateComputedAttributes()
91 }
92
93 resetBanner () {
94 this.updateBanner(null)
1ea7da81
RK
95 }
96
27ec473f 97 updateComputedAttributes () {
cdeddff1 98 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
c418d483 99 }
d3e91a5f 100}