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