1- import {
2- AfterViewInit ,
3- ChangeDetectorRef ,
4- Component ,
5- ElementRef ,
6- Input ,
7- OnChanges ,
8- OnDestroy ,
9- } from '@angular/core' ;
1+ import { Component , Input , OnChanges } from '@angular/core' ;
102import { Channel , User } from 'stream-chat' ;
113import { CustomTemplatesService } from '../custom-templates.service' ;
124import {
@@ -15,7 +7,6 @@ import {
157 AvatarType ,
168 DefaultStreamChatGenerics ,
179} from '../types' ;
18- import { ThemeService } from '../theme.service' ;
1910
2011/**
2112 * The `AvatarPlaceholder` component displays the [default avatar](./AvatarComponent.mdx) unless a [custom template](../services/CustomTemplatesService.mdx) is provided. This component is used by the SDK internally, you likely won't need to use it.
@@ -25,9 +16,7 @@ import { ThemeService } from '../theme.service';
2516 templateUrl : './avatar-placeholder.component.html' ,
2617 styles : [ ] ,
2718} )
28- export class AvatarPlaceholderComponent
29- implements OnChanges , AfterViewInit , OnDestroy
30- {
19+ export class AvatarPlaceholderComponent implements OnChanges {
3120 /**
3221 * An optional name of the image, used for fallback image or image title (if `imageUrl` is provided)
3322 */
@@ -77,37 +66,7 @@ export class AvatarPlaceholderComponent
7766 initialsType : undefined ,
7867 showOnlineIndicator : undefined ,
7968 } ;
80- isVisible = true ;
81- private mutationObserver ?: MutationObserver ;
82- constructor (
83- public customTemplatesService : CustomTemplatesService ,
84- private hostElement : ElementRef < HTMLElement > ,
85- private cdRef : ChangeDetectorRef ,
86- private themeService : ThemeService
87- ) { }
88-
89- ngAfterViewInit ( ) : void {
90- const elementToObserve =
91- this . hostElement . nativeElement . parentElement ?. parentElement
92- ?. parentElement ;
93- if (
94- this . location !== 'message-sender' ||
95- ! elementToObserve ||
96- ! elementToObserve . classList . contains ( 'str-chat__li' ) ||
97- this . themeService . themeVersion === '1'
98- ) {
99- this . isVisible = true ;
100- this . cdRef . detectChanges ( ) ;
101- return ;
102- }
103- this . checkIfVisible ( ) ;
104- this . mutationObserver = new MutationObserver ( ( ) => {
105- this . checkIfVisible ( ) ;
106- } ) ;
107- this . mutationObserver . observe ( elementToObserve , {
108- attributeFilter : [ 'class' ] ,
109- } ) ;
110- }
69+ constructor ( public customTemplatesService : CustomTemplatesService ) { }
11170
11271 ngOnChanges ( ) : void {
11372 this . context = {
@@ -122,19 +81,4 @@ export class AvatarPlaceholderComponent
12281 showOnlineIndicator : this . showOnlineIndicator ,
12382 } ;
12483 }
125-
126- ngOnDestroy ( ) : void {
127- this . mutationObserver ?. disconnect ( ) ;
128- }
129-
130- private checkIfVisible ( ) {
131- const isVisible =
132- getComputedStyle ( this . hostElement . nativeElement ) . getPropertyValue (
133- 'visibility'
134- ) === 'visible' ;
135- if ( isVisible !== this . isVisible ) {
136- this . isVisible = isVisible ;
137- this . cdRef . detectChanges ( ) ;
138- }
139- }
14084}
0 commit comments