]> 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.1.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[]
d3e91a5f 30
d0800f76 31 static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size: number) {
32 return Actor.GET_ACTOR_AVATAR_URL(actor, size)
c418d483 33 }
34
cdeddff1 35 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
d0800f76 36 if (!channel) return ''
cdeddff1 37
d0800f76 38 const banner = channel.banners[0]
39 if (!banner) return ''
cdeddff1 40
d0800f76 41 if (banner.url) return banner.url
42 return getAbsoluteAPIUrl() + banner.path
cdeddff1
C
43 }
44
d0800f76 45 static GET_DEFAULT_AVATAR_URL (size: number) {
46 if (size <= 48) {
47 return `${window.location.origin}/client/assets/images/default-avatar-video-channel-48x48.png`
48 }
49
c80e458a 50 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
c418d483 51 }
52
27ec473f 53 constructor (hash: Partial<ServerVideoChannel>) {
d3e91a5f
C
54 super(hash)
55
56 this.displayName = hash.displayName
57 this.description = hash.description
58 this.support = hash.support
cdeddff1 59
d0800f76 60 this.banners = hash.banners
cdeddff1 61
d3e91a5f 62 this.isLocal = hash.isLocal
cdeddff1 63
8a19bee1 64 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
288c78ea 65 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
a4f99a76 66
1ba471c5
C
67 this.videosCount = hash.videosCount
68
dc2b2938
C
69 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
70
8165d00a 71 if (hash.viewsPerDay) {
747c5628 72 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
8165d00a
RK
73 }
74
a4f99a76
C
75 if (hash.ownerAccount) {
76 this.ownerAccount = hash.ownerAccount
77 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
a4f99a76 78 }
cdeddff1
C
79
80 this.updateComputedAttributes()
d3e91a5f 81 }
c418d483 82
d0800f76 83 updateAvatar (newAvatars: ActorImage[]) {
84 this.avatars = newAvatars
c418d483 85
86 this.updateComputedAttributes()
87 }
88
1ea7da81 89 resetAvatar () {
d0800f76 90 this.updateAvatar([])
cdeddff1
C
91 }
92
d0800f76 93 updateBanner (newBanners: ActorImage[]) {
94 this.banners = newBanners
cdeddff1
C
95
96 this.updateComputedAttributes()
97 }
98
99 resetBanner () {
d0800f76 100 this.updateBanner([])
1ea7da81
RK
101 }
102
27ec473f 103 updateComputedAttributes () {
cdeddff1 104 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
c418d483 105 }
d3e91a5f 106}