Show default avatar on network error for comments

pull/2396/head
Rigel Kent 2020-01-07 15:42:14 +01:00 committed by Chocobozzz
parent fbc77eb648
commit c511c3f010
5 changed files with 16 additions and 4 deletions

View File

@ -20,6 +20,10 @@ export abstract class Actor implements ActorServer {
if (actor && actor.avatar) return absoluteAPIUrl + actor.avatar.path
this.GET_DEFAULT_AVATAR_URL()
}
static GET_DEFAULT_AVATAR_URL () {
return window.location.origin + '/client/assets/images/default-avatar.png'
}

View File

@ -1,9 +1,6 @@
import { Directive, ElementRef, HostListener, Output, EventEmitter } from '@angular/core'
import { Router } from '@angular/router'
type ElementEvent = Omit<Event, 'target'> & {
target: HTMLInputElement
}
import { ElementEvent } from '@app/shared/misc/utils'
@Directive({
selector: '[timestampRouteTransformer]'

View File

@ -4,6 +4,10 @@ import { DatePipe } from '@angular/common'
import { environment } from '../../../environments/environment'
import { AuthService } from '../../core/auth'
type ElementEvent = Omit<Event, 'target'> & {
target: HTMLElement
}
function getParameterByName (name: string, url: string) {
if (!url) url = window.location.href
name = name.replace(/[\[\]]/g, '\\$&')
@ -190,6 +194,7 @@ function isXPercentInViewport (el: HTMLElement, percentVisible: number) {
}
export {
ElementEvent,
sortBy,
durationToString,
lineFeedToHtml,

View File

@ -4,6 +4,7 @@
<img
class="comment-avatar"
[src]="comment.accountAvatarUrl"
(error)="switchToDefaultAvatar($event)"
alt="Avatar"
/>
</a>

View File

@ -9,6 +9,7 @@ import { MarkdownService } from '@app/shared/renderer'
import { Account } from '@app/shared/account/account.model'
import { Notifier } from '@app/core'
import { UserService } from '@app/shared'
import { Actor } from '@app/shared/actor/actor.model'
@Component({
selector: 'my-video-comment',
@ -101,6 +102,10 @@ export class VideoCommentComponent implements OnInit, OnChanges {
)
}
switchToDefaultAvatar ($event: Event) {
($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
}
private getUserIfNeeded (account: Account) {
if (!account.userId) return
if (!this.authService.isLoggedIn()) return