X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-actor-image%2Factor-avatar.component.ts;h=f1c1aa03f388215b06a849776abb9ef414b4b1a0;hb=d0fbc9fd0a29c37f3ff9b99030351e90b276fe7d;hp=437de1d507c26a123452894924cce0e29b57e1b1;hpb=a2fb5fb8b1007e3ce82e707917f5d9a37374e99b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-actor-image/actor-avatar.component.ts b/client/src/app/shared/shared-actor-image/actor-avatar.component.ts index 437de1d50..f1c1aa03f 100644 --- a/client/src/app/shared/shared-actor-image/actor-avatar.component.ts +++ b/client/src/app/shared/shared-actor-image/actor-avatar.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnChanges } from '@angular/core' +import { Component, Input, OnChanges, OnInit } from '@angular/core' import { VideoChannel } from '../shared-main' import { Account } from '../shared-main/account/account.model' @@ -15,7 +15,7 @@ export type ActorAvatarSize = '18' | '25' | '28' | '32' | '34' | '35' | '36' | ' styleUrls: [ './actor-avatar.component.scss' ], templateUrl: './actor-avatar.component.html' }) -export class ActorAvatarComponent implements OnChanges { +export class ActorAvatarComponent implements OnInit, OnChanges { private _title: string @Input() actor: ActorInput @@ -43,31 +43,22 @@ export class ActorAvatarComponent implements OnChanges { } classes: string[] = [] + defaultAvatarUrl: string + avatarUrl: string - get alt () { - if (this.isAccount()) return $localize`Account avatar` - if (this.isChannel()) return $localize`Channel avatar` + ngOnInit () { + this.buildDefaultAvatarUrl() - return '' + this.buildAvatarUrl() + this.buildClasses() } - get defaultAvatarUrl () { - if (this.isChannel()) return VideoChannel.GET_DEFAULT_AVATAR_URL(this.getSizeNumber()) - - // account or unlogged - return Account.GET_DEFAULT_AVATAR_URL(this.getSizeNumber()) - } - - get avatarUrl () { - if (!this.actor) return '' - - if (this.isAccount()) return Account.GET_ACTOR_AVATAR_URL(this.actor, this.getSizeNumber()) - if (this.isChannel()) return VideoChannel.GET_ACTOR_AVATAR_URL(this.actor, this.getSizeNumber()) - - return '' + ngOnChanges () { + this.buildAvatarUrl() + this.buildClasses() } - ngOnChanges () { + private buildClasses () { this.classes = [ 'avatar' ] if (this.size) { @@ -87,14 +78,40 @@ export class ActorAvatarComponent implements OnChanges { } } + private buildDefaultAvatarUrl () { + this.defaultAvatarUrl = this.isChannel() + ? VideoChannel.GET_DEFAULT_AVATAR_URL(this.getSizeNumber()) + : Account.GET_DEFAULT_AVATAR_URL(this.getSizeNumber()) + } + + private buildAvatarUrl () { + if (!this.actor) { + this.avatarUrl = '' + return + } + + if (this.isAccount()) { + this.avatarUrl = Account.GET_ACTOR_AVATAR_URL(this.actor, this.getSizeNumber()) + return + } + + if (this.isChannel()) { + this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this.actor, this.getSizeNumber()) + return + } + + this.avatarUrl = '' + } + displayImage () { if (this.actorType === 'unlogged') return true + if (this.previewImage) return true return !!(this.actor && this.avatarUrl) } displayActorInitial () { - return this.actor && !this.avatarUrl + return !this.displayImage() && this.actor && !this.avatarUrl } displayPlaceholder () { @@ -128,18 +145,18 @@ export class ActorAvatarComponent implements OnChanges { // Keep consistency with CSS const themes = { '0123456789abc': 'blue', - def: 'green', - ghi: 'purple', - jkl: 'gray', - mno: 'yellow', - pqr: 'orange', - stvu: 'red', - wxyz: 'dark-blue' + 'def': 'green', + 'ghi': 'purple', + 'jkl': 'gray', + 'mno': 'yellow', + 'pqr': 'orange', + 'stvu': 'red', + 'wxyz': 'dark-blue' } const theme = Object.keys(themes) .find(chars => chars.includes(initialLowercase)) - return themes[theme] + return themes[theme] || 'blue' } }