Skip to content

Commit 1afd581

Browse files
committed
Merge branch 'master' into theming-v2
2 parents 7c00596 + 00120df commit 1afd581

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

projects/stream-chat-angular/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"url": "https://github.com/GetStream/stream-chat-angular.git"
1010
},
1111
"peerDependencies": {
12-
"@angular/common": "^12.2.0 || ^13.0.0",
13-
"@angular/core": "^12.2.0 || ^13.0.0",
12+
"@angular/common": "^12.2.0 || ^13.0.0 || ^14.0.0",
13+
"@angular/core": "^12.2.0 || ^13.0.0 || ^14.0.0",
1414
"@ngx-translate/core": "^13.0.0 || ^14.0.0",
1515
"stream-chat": "^6.4.0"
1616
},

projects/stream-chat-angular/src/lib/chat-client.service.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { TestBed } from '@angular/core/testing';
22
import { Event, OwnUserResponse, StreamChat } from 'stream-chat';
33
import { version } from '../assets/version';
44
import { ChatClientService } from './chat-client.service';
5-
import { mockStreamChatClient, MockStreamChatClient } from './mocks';
5+
import {
6+
mockCurrentUser,
7+
mockStreamChatClient,
8+
MockStreamChatClient,
9+
} from './mocks';
610
import { NotificationService } from './notification.service';
711
import { DefaultStreamChatGenerics } from './types';
812

@@ -29,8 +33,11 @@ describe('ChatClientService', () => {
2933
expect(StreamChat.getInstance).toHaveBeenCalledWith(apiKey);
3034
const spy = jasmine.createSpy();
3135
service.appSettings$.subscribe(spy);
36+
const userSpy = jasmine.createSpy();
37+
service.user$.subscribe(userSpy);
3238

3339
expect(spy).toHaveBeenCalledWith(undefined);
40+
expect(userSpy).toHaveBeenCalledWith(mockCurrentUser());
3441
});
3542

3643
it(`should notify if connection wasn't successful`, async () => {
@@ -67,6 +74,9 @@ describe('ChatClientService', () => {
6774
service.pendingInvites$.subscribe(pendingInvitesSpy);
6875
pendingInvitesSpy.calls.reset();
6976
eventsSpy.calls.reset();
77+
const userSpy = jasmine.createSpy();
78+
service.user$.subscribe(userSpy);
79+
userSpy.calls.reset();
7080
await service.disconnectUser();
7181
const event = {
7282
id: 'mockevent',
@@ -77,6 +87,7 @@ describe('ChatClientService', () => {
7787
expect(mockChatClient.disconnectUser).toHaveBeenCalledWith();
7888
expect(pendingInvitesSpy).toHaveBeenCalledWith([]);
7989
expect(eventsSpy).not.toHaveBeenCalled();
90+
expect(userSpy).toHaveBeenCalledWith(undefined);
8091
});
8192

8293
it('should init with user meta data', async () => {

projects/stream-chat-angular/src/lib/chat-client.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class ChatClientService<
5353
* Emits the list of pending invites of the user. It emits every pending invitation during initialization and then extends the list when a new invite is received. More information can be found in the [channel invitations](../code-examples/channel-invites.mdx) guide.
5454
*/
5555
pendingInvites$: Observable<(ChannelResponse<T> | Channel<T>)[]>;
56+
/**
57+
* Emits the current chat user
58+
*/
59+
user$: Observable<UserResponse<T> | undefined>;
5660
private notificationSubject = new ReplaySubject<ClientEvent<T>>(1);
5761
private connectionStateSubject = new ReplaySubject<'offline' | 'online'>(1);
5862
private appSettingsSubject = new BehaviorSubject<AppSettings | undefined>(
@@ -61,6 +65,7 @@ export class ChatClientService<
6165
private pendingInvitesSubject = new BehaviorSubject<
6266
(ChannelResponse<T> | Channel<T>)[]
6367
>([]);
68+
private userSubject = new ReplaySubject<UserResponse<T> | undefined>(1);
6469
private subscriptions: { unsubscribe: () => void }[] = [];
6570

6671
constructor(
@@ -71,6 +76,7 @@ export class ChatClientService<
7176
this.connectionState$ = this.connectionStateSubject.asObservable();
7277
this.appSettings$ = this.appSettingsSubject.asObservable();
7378
this.pendingInvites$ = this.pendingInvitesSubject.asObservable();
79+
this.user$ = this.userSubject.asObservable();
7480
}
7581

7682
/**
@@ -101,6 +107,7 @@ export class ChatClientService<
101107
this.chatClient.setUserAgent(
102108
`stream-chat-angular-${version}-${this.chatClient.getUserAgent()}`
103109
);
110+
this.userSubject.next(this.chatClient.user);
104111
});
105112
const channels = await this.chatClient.queryChannels(
106113
{ invite: 'pending' } as any as ChannelFilters<T>, // TODO: find out why we need this typecast
@@ -146,6 +153,7 @@ export class ChatClientService<
146153
async disconnectUser() {
147154
this.pendingInvitesSubject.next([]);
148155
await this.chatClient.disconnectUser();
156+
this.userSubject.next(undefined);
149157
this.subscriptions.forEach((s) => s.unsubscribe());
150158
}
151159

0 commit comments

Comments
 (0)