Skip to content

Commit dbcee1a

Browse files
authored
Merge pull request #498 from GetStream/update-user-on-ws-events
feat: update unread counts on WS events
2 parents 5d5dec0 + 765a010 commit dbcee1a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,30 @@ export class ChatClientService<
250250
});
251251
}
252252
}
253+
if (typeof e.unread_channels !== 'undefined') {
254+
let user: OwnUserResponse<T> | UserResponse<T> | undefined;
255+
this.userSubject.pipe(take(1)).subscribe((u) => {
256+
user = u;
257+
});
258+
if (user && user.unread_channels !== e.unread_channels) {
259+
this.userSubject.next({
260+
...user,
261+
unread_channels: e.unread_channels,
262+
});
263+
}
264+
}
265+
if (typeof e.unread_count !== 'undefined') {
266+
let user: OwnUserResponse<T> | UserResponse<T> | undefined;
267+
this.userSubject.pipe(take(1)).subscribe((u) => {
268+
user = u;
269+
});
270+
if (user && user.unread_count !== e.unread_count) {
271+
this.userSubject.next({
272+
...user,
273+
unread_count: e.unread_count,
274+
});
275+
}
276+
}
253277
if (
254278
e.type === 'user.updated' &&
255279
this.chatClient.user &&

0 commit comments

Comments
 (0)