1 import { Component, Input } from '@angular/core'
2 import { SafeResourceUrl } from '@angular/platform-browser'
3 import { VideoChannel } from '../shared-main'
4 import { Account } from '../shared-main/account/account.model'
8 avatar?: { url?: string, path: string }
13 selector: 'my-actor-avatar',
14 styleUrls: [ './actor-avatar.component.scss' ],
15 templateUrl: './actor-avatar.component.html'
17 export class ActorAvatarComponent {
18 @Input() account: ActorInput
19 @Input() channel: ActorInput
21 @Input() previewImage: SafeResourceUrl
23 @Input() size: '18' | '25' | '32' | '34' | '36' | '40' | '100' | '120'
25 // Use an external link
28 @Input() internalHref: string | any[]
30 @Input() set title (value) {
34 private _title: string
37 if (this._title) return this._title
38 if (this.account) return $localize`${this.account.name} (account page)`
39 if (this.channel) return $localize`${this.channel.name} (channel page)`
45 if (this.account) return $localize`Account avatar`
46 if (this.channel) return $localize`Channel avatar`
52 const base = [ 'avatar' ]
54 if (this.size) base.push(`avatar-${this.size}`)
56 if (this.account) base.push('account')
57 else base.push('channel')
61 base.push(this.getColorTheme())
67 get defaultAvatarUrl () {
68 if (this.account) Account.GET_DEFAULT_AVATAR_URL()
69 if (this.channel) return VideoChannel.GET_DEFAULT_AVATAR_URL()
75 if (this.account) return Account.GET_ACTOR_AVATAR_URL(this.account)
76 if (this.channel) return VideoChannel.GET_ACTOR_AVATAR_URL(this.account)
82 const name = this.account?.name
85 return name.slice(0, 1)
89 return !!this.account || !!this.channel
92 private getColorTheme () {
93 // Keep consistency with CSS
105 const theme = Object.keys(themes)
106 .find(chars => chars.includes(this.initial))