]>
Commit | Line | Data |
---|---|---|
cdeddff1 | 1 | import { getAbsoluteAPIUrl } from '@app/helpers' |
f4796856 | 2 | import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models' |
733dbc53 | 3 | import { Account } from '../account/account.model' |
67ed6552 | 4 | import { Actor } from '../account/actor.model' |
d3e91a5f C |
5 | |
6 | export class VideoChannel extends Actor implements ServerVideoChannel { | |
7 | displayName: string | |
8 | description: string | |
9 | support: string | |
cdeddff1 | 10 | |
d3e91a5f | 11 | isLocal: boolean |
cdeddff1 | 12 | |
8a19bee1 | 13 | nameWithHost: string |
288c78ea | 14 | nameWithHostForced: string |
1ba471c5 | 15 | |
cdeddff1 C |
16 | banner: ActorImage |
17 | bannerUrl: string | |
18 | ||
dc2b2938 C |
19 | updatedAt: Date | string |
20 | ||
733dbc53 | 21 | ownerAccount?: ServerAccount |
a4f99a76 | 22 | ownerBy?: string |
1ba471c5 C |
23 | |
24 | videosCount?: number | |
25 | ||
3d527ba1 | 26 | viewsPerDay?: ViewsPerDate[] |
d3e91a5f | 27 | |
c418d483 | 28 | static GET_ACTOR_AVATAR_URL (actor: object) { |
746018f6 | 29 | return Actor.GET_ACTOR_AVATAR_URL(actor) |
c418d483 | 30 | } |
31 | ||
cdeddff1 C |
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 | ||
c418d483 | 44 | static GET_DEFAULT_AVATAR_URL () { |
45 | return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png` | |
46 | } | |
47 | ||
27ec473f | 48 | constructor (hash: Partial<ServerVideoChannel>) { |
d3e91a5f C |
49 | super(hash) |
50 | ||
51 | this.displayName = hash.displayName | |
52 | this.description = hash.description | |
53 | this.support = hash.support | |
cdeddff1 C |
54 | |
55 | this.banner = hash.banner | |
56 | ||
d3e91a5f | 57 | this.isLocal = hash.isLocal |
cdeddff1 | 58 | |
8a19bee1 | 59 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) |
288c78ea | 60 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) |
a4f99a76 | 61 | |
1ba471c5 C |
62 | this.videosCount = hash.videosCount |
63 | ||
dc2b2938 C |
64 | if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString()) |
65 | ||
8165d00a | 66 | if (hash.viewsPerDay) { |
747c5628 | 67 | this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) })) |
8165d00a RK |
68 | } |
69 | ||
a4f99a76 C |
70 | if (hash.ownerAccount) { |
71 | this.ownerAccount = hash.ownerAccount | |
72 | this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host) | |
a4f99a76 | 73 | } |
cdeddff1 C |
74 | |
75 | this.updateComputedAttributes() | |
d3e91a5f | 76 | } |
c418d483 | 77 | |
f4796856 | 78 | updateAvatar (newAvatar: ActorImage) { |
c418d483 | 79 | this.avatar = newAvatar |
80 | ||
81 | this.updateComputedAttributes() | |
82 | } | |
83 | ||
1ea7da81 | 84 | resetAvatar () { |
cdeddff1 C |
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) | |
1ea7da81 RK |
96 | } |
97 | ||
27ec473f | 98 | updateComputedAttributes () { |
cdeddff1 | 99 | this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this) |
c418d483 | 100 | } |
d3e91a5f | 101 | } |