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