Skip to content

Commit 42f422d

Browse files
authored
Merge pull request #349 from GetStream/message-fix
fix: Message component throws error if chatClient is not defined
2 parents aa7cb8d + 468c02d commit 42f422d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

projects/stream-chat-angular/src/lib/message-list/message-list.component.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@angular/core/testing';
88
import { By } from '@angular/platform-browser';
99
import { TranslateModule } from '@ngx-translate/core';
10+
import { of } from 'rxjs';
1011
import { Channel } from 'stream-chat';
1112
import { AvatarPlaceholderComponent } from '../avatar-placeholder/avatar-placeholder.component';
1213
import { AvatarComponent } from '../avatar/avatar.component';
@@ -51,7 +52,10 @@ describe('MessageListComponent', () => {
5152
{ provide: ChannelService, useValue: channelServiceMock },
5253
{
5354
provide: ChatClientService,
54-
useValue: { chatClient: { user: mockCurrentUser() } },
55+
useValue: {
56+
chatClient: { user: mockCurrentUser() },
57+
user$: of(mockCurrentUser()),
58+
},
5559
},
5660
],
5761
});

projects/stream-chat-angular/src/lib/message/message.component.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { TranslateModule } from '@ngx-translate/core';
2020
import { ChannelService } from '../channel.service';
2121
import { SimpleChange } from '@angular/core';
2222
import { AvatarPlaceholderComponent } from '../avatar-placeholder/avatar-placeholder.component';
23+
import { of } from 'rxjs';
2324

2425
describe('MessageComponent', () => {
2526
let component: MessageComponent;
@@ -74,7 +75,10 @@ describe('MessageComponent', () => {
7475
providers: [
7576
{
7677
provide: ChatClientService,
77-
useValue: { chatClient: { user: currentUser } },
78+
useValue: {
79+
chatClient: { user: currentUser },
80+
user$: of(currentUser),
81+
},
7882
},
7983
{
8084
provide: ChannelService,

projects/stream-chat-angular/src/lib/message/message.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
8282
private channelService: ChannelService,
8383
private customTemplatesService: CustomTemplatesService,
8484
private cdRef: ChangeDetectorRef
85-
) {
86-
this.user = this.chatClientService.chatClient.user;
87-
}
85+
) {}
8886

8987
ngOnInit(): void {
88+
this.subscriptions.push(
89+
this.chatClientService.user$.subscribe((u) => (this.user = u))
90+
);
9091
this.subscriptions.push(
9192
this.customTemplatesService.mentionTemplate$.subscribe(
9293
(template) => (this.mentionTemplate = template)

0 commit comments

Comments
 (0)