]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Merge remote-tracking branch 'weblate/develop' 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'
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 20 ownerBy?: string
1ba471c5
C
21
22 videosCount?: number
23
3d527ba1 24 viewsPerDay?: ViewsPerDate[]
d3e91a5f 25
c418d483 26 static GET_ACTOR_AVATAR_URL (actor: object) {
746018f6 27 return Actor.GET_ACTOR_AVATAR_URL(actor)
c418d483 28 }
29
cdeddff1
C
30 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
31 if (channel?.banner?.url) return channel.banner.url
32
33 if (channel && channel.banner) {
34 const absoluteAPIUrl = getAbsoluteAPIUrl()
35
36 return absoluteAPIUrl + channel.banner.path
37 }
38
39 return ''
40 }
41
c418d483 42 static GET_DEFAULT_AVATAR_URL () {
43 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
44 }
45
27ec473f 46 constructor (hash: Partial<ServerVideoChannel>) {
d3e91a5f
C
47 super(hash)
48
49 this.displayName = hash.displayName
50 this.description = hash.description
51 this.support = hash.support
cdeddff1
C
52
53 this.banner = hash.banner
54
d3e91a5f 55 this.isLocal = hash.isLocal
cdeddff1 56
8a19bee1 57 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
288c78ea 58 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
a4f99a76 59
1ba471c5
C
60 this.videosCount = hash.videosCount
61
8165d00a 62 if (hash.viewsPerDay) {
747c5628 63 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
8165d00a
RK
64 }
65
a4f99a76
C
66 if (hash.ownerAccount) {
67 this.ownerAccount = hash.ownerAccount
68 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
a4f99a76 69 }
cdeddff1
C
70
71 this.updateComputedAttributes()
d3e91a5f 72 }
c418d483 73
f4796856 74 updateAvatar (newAvatar: ActorImage) {
c418d483 75 this.avatar = newAvatar
76
77 this.updateComputedAttributes()
78 }
79
1ea7da81 80 resetAvatar () {
cdeddff1
C
81 this.updateAvatar(null)
82 }
83
84 updateBanner (newBanner: ActorImage) {
85 this.banner = newBanner
86
87 this.updateComputedAttributes()
88 }
89
90 resetBanner () {
91 this.updateBanner(null)
1ea7da81
RK
92 }
93
27ec473f 94 updateComputedAttributes () {
cdeddff1 95 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
c418d483 96 }
d3e91a5f 97}