Skip to content

Commit fbd1e86

Browse files
authored
Merge pull request #472 from GetStream/avatar-inputs
Avatar inputs
2 parents c14149a + 333808e commit fbd1e86

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

projects/customizations-example/src/app/app.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146
let-location="location"
147147
let-user="user"
148148
let-channel="channel"
149+
let-initialsType="initialsType"
150+
let-showOnlineIndicator="showOnlineIndicator"
149151
>
150152
<stream-avatar
151153
[name]="name"
@@ -155,6 +157,8 @@
155157
[location]="location"
156158
[user]="user"
157159
[channel]="channel"
160+
[initialsType]="initialsType"
161+
[showOnlineIndicator]="showOnlineIndicator"
158162
></stream-avatar>
159163
</ng-template>
160164

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
let-user="user"
99
let-location="location"
1010
let-initialsType="initialsType"
11+
let-showOnlineIndicator="showOnlineIndicator"
1112
>
1213
<stream-avatar
1314
[name]="name"
@@ -18,6 +19,7 @@
1819
[user]="user"
1920
[location]="location"
2021
[initialsType]="initialsType"
22+
[showOnlineIndicator]="showOnlineIndicator"
2123
></stream-avatar>
2224
</ng-template>
2325
<ng-container *ngIf="isVisible; else emptyPlaceholder">

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
AvatarType,
1616
DefaultStreamChatGenerics,
1717
} from '../types';
18+
import { ThemeService } from '../theme.service';
1819

1920
/**
2021
* 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.
@@ -61,6 +62,10 @@ export class AvatarPlaceholderComponent
6162
@Input() initialsType:
6263
| 'first-letter-of-first-word'
6364
| 'first-letter-of-each-word' = 'first-letter-of-first-word';
65+
/**
66+
* If a channel avatar is displayed, and if the channel has exactly two members a green dot is displayed if the other member is online. Set this flag to `false` to turn off this behavior.
67+
*/
68+
@Input() showOnlineIndicator = true;
6469
context: AvatarContext = {
6570
name: undefined,
6671
imageUrl: undefined,
@@ -70,28 +75,32 @@ export class AvatarPlaceholderComponent
7075
user: undefined,
7176
type: undefined,
7277
initialsType: undefined,
78+
showOnlineIndicator: undefined,
7379
};
7480
isVisible = true;
7581
private mutationObserver?: MutationObserver;
7682
constructor(
7783
public customTemplatesService: CustomTemplatesService,
7884
private hostElement: ElementRef<HTMLElement>,
79-
private cdRef: ChangeDetectorRef
85+
private cdRef: ChangeDetectorRef,
86+
private themeService: ThemeService
8087
) {}
8188

8289
ngAfterViewInit(): void {
83-
if (this.location !== 'message-sender') {
84-
this.isVisible = true;
85-
this.cdRef.detectChanges();
86-
return;
87-
}
88-
this.checkIfVisible();
8990
const elementToObserve =
9091
this.hostElement.nativeElement.parentElement?.parentElement
9192
?.parentElement;
92-
if (!elementToObserve) {
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();
93101
return;
94102
}
103+
this.checkIfVisible();
95104
this.mutationObserver = new MutationObserver(() => {
96105
this.checkIfVisible();
97106
});
@@ -110,6 +119,7 @@ export class AvatarPlaceholderComponent
110119
user: this.user,
111120
channel: this.channel,
112121
initialsType: this.initialsType,
122+
showOnlineIndicator: this.showOnlineIndicator,
113123
};
114124
}
115125

projects/stream-chat-angular/src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export type AvatarContext = {
192192
channel?: Channel<DefaultStreamChatGenerics>;
193193
user?: User<DefaultStreamChatGenerics>;
194194
initialsType?: 'first-letter-of-first-word' | 'first-letter-of-each-word';
195+
showOnlineIndicator?: boolean;
195196
};
196197

197198
export type AttachmentPreviewListContext = {

0 commit comments

Comments
 (0)