]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Merge branch 'release/4.2.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
d0800f76 15 // TODO: remove, deprecated in 4.2
16 banner: never
17
18 banners: ActorImage[]
19
cdeddff1
C
20 bannerUrl: string
21
dc2b2938
C
22 updatedAt: Date | string
23
733dbc53 24 ownerAccount?: ServerAccount
a4f99a76 25 ownerBy?: string
1ba471c5
C
26
27 videosCount?: number
28
3d527ba1 29 viewsPerDay?: ViewsPerDate[]
c6f8ca4d 30 totalViews?: number
d3e91a5f 31
d0800f76 32 static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size: number) {
33 return Actor.GET_ACTOR_AVATAR_URL(actor, size)
c418d483 34 }
35
cdeddff1 36 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
9ca5728b
C
37 if (!channel || channel.banners.length === 0) {
38 return ''
39 }
cdeddff1 40
d0800f76 41 const banner = channel.banners[0]
42 if (!banner) return ''
cdeddff1 43
d0800f76 44 if (banner.url) return banner.url
45 return getAbsoluteAPIUrl() + banner.path
cdeddff1
C
46 }
47
d0800f76 48 static GET_DEFAULT_AVATAR_URL (size: number) {
49 if (size <= 48) {
50 return `${window.location.origin}/client/assets/images/default-avatar-video-channel-48x48.png`
51 }
52
c80e458a 53 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
c418d483 54 }
55
27ec473f 56 constructor (hash: Partial<ServerVideoChannel>) {
d3e91a5f
C
57 super(hash)
58
59 this.displayName = hash.displayName
60 this.description = hash.description
61 this.support = hash.support
cdeddff1 62
9ca5728b 63 this.banners = hash.banners || []
cdeddff1 64
d3e91a5f 65 this.isLocal = hash.isLocal
cdeddff1 66
8a19bee1 67 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
288c78ea 68 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
a4f99a76 69
1ba471c5
C
70 this.videosCount = hash.videosCount
71
dc2b2938
C
72 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
73
8165d00a 74 if (hash.viewsPerDay) {
747c5628 75 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
8165d00a
RK
76 }
77
c6f8ca4d
FC
78 if (hash.totalViews !== null && hash.totalViews !== undefined) {
79 this.totalViews = hash.totalViews
80 }
81
a4f99a76
C
82 if (hash.ownerAccount) {
83 this.ownerAccount = hash.ownerAccount
84 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
a4f99a76 85 }
cdeddff1
C
86
87 this.updateComputedAttributes()
d3e91a5f 88 }
c418d483 89
d0800f76 90 updateAvatar (newAvatars: ActorImage[]) {
91 this.avatars = newAvatars
c418d483 92
93 this.updateComputedAttributes()
94 }
95
1ea7da81 96 resetAvatar () {
d0800f76 97 this.updateAvatar([])
cdeddff1
C
98 }
99
d0800f76 100 updateBanner (newBanners: ActorImage[]) {
101 this.banners = newBanners
cdeddff1
C
102
103 this.updateComputedAttributes()
104 }
105
106 resetBanner () {
d0800f76 107 this.updateBanner([])
1ea7da81
RK
108 }
109
27ec473f 110 updateComputedAttributes () {
cdeddff1 111 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
c418d483 112 }
d3e91a5f 113}