Show default avatar on network error for comments

This commit is contained in:
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 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' 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 { Directive, ElementRef, HostListener, Output, EventEmitter } from '@angular/core'
import { Router } from '@angular/router' import { Router } from '@angular/router'
import { ElementEvent } from '@app/shared/misc/utils'
type ElementEvent = Omit<Event, 'target'> & {
target: HTMLInputElement
}
@Directive({ @Directive({
selector: '[timestampRouteTransformer]' selector: '[timestampRouteTransformer]'

View File

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

View File

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

View File

@ -9,6 +9,7 @@ import { MarkdownService } from '@app/shared/renderer'
import { Account } from '@app/shared/account/account.model' import { Account } from '@app/shared/account/account.model'
import { Notifier } from '@app/core' import { Notifier } from '@app/core'
import { UserService } from '@app/shared' import { UserService } from '@app/shared'
import { Actor } from '@app/shared/actor/actor.model'
@Component({ @Component({
selector: 'my-video-comment', 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) { private getUserIfNeeded (account: Account) {
if (!account.userId) return if (!account.userId) return
if (!this.authService.isLoggedIn()) return if (!this.authService.isLoggedIn()) return