]>
Commit | Line | Data |
---|---|---|
1 | import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account, Avatar } from '@shared/models' | |
2 | import { Actor } from '../account/actor.model' | |
3 | ||
4 | export class VideoChannel extends Actor implements ServerVideoChannel { | |
5 | displayName: string | |
6 | description: string | |
7 | support: string | |
8 | isLocal: boolean | |
9 | nameWithHost: string | |
10 | nameWithHostForced: string | |
11 | ||
12 | ownerAccount?: Account | |
13 | ownerBy?: string | |
14 | ownerAvatarUrl?: string | |
15 | ||
16 | videosCount?: number | |
17 | ||
18 | viewsPerDay?: ViewsPerDate[] | |
19 | ||
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 | ||
28 | constructor (hash: ServerVideoChannel) { | |
29 | super(hash) | |
30 | ||
31 | this.updateComputedAttributes() | |
32 | ||
33 | this.displayName = hash.displayName | |
34 | this.description = hash.description | |
35 | this.support = hash.support | |
36 | this.isLocal = hash.isLocal | |
37 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) | |
38 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) | |
39 | ||
40 | this.videosCount = hash.videosCount | |
41 | ||
42 | if (hash.viewsPerDay) { | |
43 | this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) })) | |
44 | } | |
45 | ||
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 | } | |
51 | } | |
52 | ||
53 | updateAvatar (newAvatar: Avatar) { | |
54 | this.avatar = newAvatar | |
55 | ||
56 | this.updateComputedAttributes() | |
57 | } | |
58 | ||
59 | resetAvatar () { | |
60 | this.avatar = null | |
61 | this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL() | |
62 | } | |
63 | ||
64 | private updateComputedAttributes () { | |
65 | this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this) | |
66 | } | |
67 | } |