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