]>
Commit | Line | Data |
---|---|---|
c418d483 | 1 | import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account, Avatar } from '@shared/models' |
67ed6552 | 2 | import { Actor } from '../account/actor.model' |
d3e91a5f C |
3 | |
4 | export class VideoChannel extends Actor implements ServerVideoChannel { | |
5 | displayName: string | |
6 | description: string | |
7 | support: string | |
8 | isLocal: boolean | |
8a19bee1 | 9 | nameWithHost: string |
288c78ea | 10 | nameWithHostForced: string |
1ba471c5 | 11 | |
a4f99a76 C |
12 | ownerAccount?: Account |
13 | ownerBy?: string | |
14 | ownerAvatarUrl?: string | |
1ba471c5 C |
15 | |
16 | videosCount?: number | |
17 | ||
3d527ba1 | 18 | viewsPerDay?: ViewsPerDate[] |
d3e91a5f | 19 | |
c418d483 | 20 | static GET_ACTOR_AVATAR_URL (actor: object) { |
21 | return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL() | |
22 | } | |
23 | ||
24 | static GET_DEFAULT_AVATAR_URL () { | |
25 | return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png` | |
26 | } | |
27 | ||
d3e91a5f C |
28 | constructor (hash: ServerVideoChannel) { |
29 | super(hash) | |
30 | ||
c418d483 | 31 | this.updateComputedAttributes() |
32 | ||
d3e91a5f C |
33 | this.displayName = hash.displayName |
34 | this.description = hash.description | |
35 | this.support = hash.support | |
36 | this.isLocal = hash.isLocal | |
8a19bee1 | 37 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) |
288c78ea | 38 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) |
a4f99a76 | 39 | |
1ba471c5 C |
40 | this.videosCount = hash.videosCount |
41 | ||
8165d00a | 42 | if (hash.viewsPerDay) { |
747c5628 | 43 | this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) })) |
8165d00a RK |
44 | } |
45 | ||
a4f99a76 C |
46 | if (hash.ownerAccount) { |
47 | this.ownerAccount = hash.ownerAccount | |
48 | this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host) | |
49 | this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount) | |
50 | } | |
d3e91a5f | 51 | } |
c418d483 | 52 | |
53 | updateAvatar (newAvatar: Avatar) { | |
54 | this.avatar = newAvatar | |
55 | ||
56 | this.updateComputedAttributes() | |
57 | } | |
58 | ||
1ea7da81 RK |
59 | resetAvatar () { |
60 | this.avatar = null | |
61 | this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL() | |
62 | } | |
63 | ||
c418d483 | 64 | private updateComputedAttributes () { |
65 | this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this) | |
66 | } | |
d3e91a5f | 67 | } |