]> 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 ownerAccount?: ServerAccount
20 ownerBy?: string
21
22 videosCount?: number
23
24 viewsPerDay?: ViewsPerDate[]
25
26 static GET_ACTOR_AVATAR_URL (actor: object) {
27 return Actor.GET_ACTOR_AVATAR_URL(actor)
28 }
29
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
42 static GET_DEFAULT_AVATAR_URL () {
43 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
44 }
45
46 constructor (hash: Partial<ServerVideoChannel>) {
47 super(hash)
48
49 this.displayName = hash.displayName
50 this.description = hash.description
51 this.support = hash.support
52
53 this.banner = hash.banner
54
55 this.isLocal = hash.isLocal
56
57 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
58 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
59
60 this.videosCount = hash.videosCount
61
62 if (hash.viewsPerDay) {
63 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
64 }
65
66 if (hash.ownerAccount) {
67 this.ownerAccount = hash.ownerAccount
68 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
69 }
70
71 this.updateComputedAttributes()
72 }
73
74 updateAvatar (newAvatar: ActorImage) {
75 this.avatar = newAvatar
76
77 this.updateComputedAttributes()
78 }
79
80 resetAvatar () {
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)
92 }
93
94 updateComputedAttributes () {
95 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
96 }
97 }