Skip to content

Commit be38cbd

Browse files
committed
feat: Rename ChatClient.notification$ to events$
**BREAKING CHANGE** `ChatClient.notification$` renamed to `events$`
1 parent 4b75828 commit be38cbd

File tree

8 files changed

+59
-57
lines changed

8 files changed

+59
-57
lines changed

docusaurus/docs/Angular/basics/upgrade-v2.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ The following inputs are removed:
5555
| The autocomplete list item template for mentioning users | `MessageInputConfigService.mentionAutocompleteItemTemplate` | [`CustomTemplatesService.mentionAutocompleteItemTemplate$`](../services/CustomTemplatesService.mdx) |
5656
| The template for emoji picker | `MessageInputConfigService.emojiPickerTemplate` | [`CustomTemplatesService.emojiPickerTemplate$`](../services/CustomTemplatesService.mdx) |
5757
| The template for channel actions | `ChannelHeaderComponent.channelActionsTemplate` | [`CustomTemplatesService.channelActionsTemplate$`](../services/CustomTemplatesService.mdx) |
58+
59+
## `ChatClient.notification$` renamed to `events$`
60+
61+
The `notification$` stream on the [`ChatClientService`](../services/ChatClientService.mdx) was renamed to `events$` as it better represents what this Observable does.
62+
63+
The `events$` stream emits the received [client, notification and user presence events](https://getstream.io/chat/docs/javascript/event_object/?language=javascript).
64+
65+
The payload of this Observable was renamed from `Notification` to `ClientEvent`.

docusaurus/docs/Angular/code-examples/channel-invites.mdx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,26 +441,20 @@ To override the default behavior create a custom event handler in `app.component
441441

442442
```typescript
443443
private customAddedToChannelNotificationHandler(
444-
notification: Notification,
444+
clientEvent: ClientEvent,
445445
channelListSetter: (channels: (Channel | ChannelResponse)[]) => void
446446
): void {
447447
let channels!: Channel[];
448448
this.channelService.channels$
449449
.pipe(take(1))
450450
.subscribe((c) => (channels = c || []));
451-
if (notification.event.member?.invited) {
451+
if (clientEvent.event.member?.invited) {
452452
return;
453453
}
454-
channelListSetter([notification!.event!.channel!, ...channels]);
454+
channelListSetter([clientEvent!.event!.channel!, ...channels]);
455455
}
456456
```
457457

458-
:::important
459-
Make sure to add the following import to your code (your IDE might not be able to add this automatically):
460-
461-
`import { Notification } from 'stream-chat-angular';`
462-
:::
463-
464458
Now register the handler to the [channel service](../services/ChannelService.mdx) in the constructor of `app.component.ts`:
465459

466460
```
@@ -475,7 +469,7 @@ The `notification.invite_accepted` event emitted by the [`ChatClientService`](..
475469
Add this to the constructor of your `app.component.ts`:
476470

477471
```typescript
478-
this.chatService.notification$
472+
this.chatService.events$
479473
.pipe(filter((n) => n.eventType === "notification.invite_accepted"))
480474
.subscribe(() => {
481475
this.channelService.reset();

docusaurus/docs/Angular/concepts/change-detection.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class AppComponent implements OnInit {
2828
) {}
2929

3030
ngOnInit(): void {
31-
this.chatService.notification$
31+
this.chatService.events$
3232
.pipe(filter((n) => n.eventType === "notification.added_to_channel"))
3333
.subscribe((notification) => {
3434
// reenter Angular's change detection zone
@@ -49,7 +49,7 @@ If you were to display the notification without reentering Angular's zone, the `
4949

5050
You need to reenter Angular's change detection zone when
5151

52-
- you subscribe to events using the [`notification$`](../services/ChatClientService.mdx/#notification) Observable of the `ChatClientService`
52+
- you subscribe to events using the [`events$`](../services/ChatClientService.mdx/#notification) Observable of the `ChatClientService`
5353
- you subscribe to channel events
5454

5555
For example the [`ChannelPreview`](../components/ChannelPreviewComponent.mdx) component needs to subscribe to the `message.read` channel events to know if the channel has unread messages and reenter Angular's zone when an event is received:

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
UserResponse,
1212
} from 'stream-chat';
1313
import { ChannelService } from './channel.service';
14-
import { ChatClientService, Notification } from './chat-client.service';
14+
import { ChatClientService, ClientEvent } from './chat-client.service';
1515
import {
1616
generateMockChannels,
1717
MockChannel,
@@ -29,7 +29,7 @@ describe('ChannelService', () => {
2929
deleteMessage: jasmine.Spy;
3030
userID: string;
3131
};
32-
let notification$: Subject<Notification>;
32+
let events$: Subject<ClientEvent>;
3333
let connectionState$: Subject<'online' | 'offline'>;
3434
let init: (
3535
c?: Channel[],
@@ -51,14 +51,14 @@ describe('ChannelService', () => {
5151
deleteMessage: jasmine.createSpy(),
5252
userID: user.id,
5353
};
54-
notification$ = new Subject();
54+
events$ = new Subject();
5555
TestBed.configureTestingModule({
5656
providers: [
5757
{
5858
provide: ChatClientService,
5959
useValue: {
6060
chatClient: { ...mockChatClient, user },
61-
notification$,
61+
events$,
6262
connectionState$,
6363
},
6464
},
@@ -625,7 +625,7 @@ describe('ChannelService', () => {
625625
spyOn(newChannel, 'on').and.callThrough();
626626
const spy = jasmine.createSpy();
627627
service.channels$.subscribe(spy);
628-
notification$.next({
628+
events$.next({
629629
eventType: 'notification.added_to_channel',
630630
event: { channel: newChannel } as any as Event,
631631
});
@@ -650,7 +650,7 @@ describe('ChannelService', () => {
650650
spyOn(channel, 'on').and.callThrough();
651651
const spy = jasmine.createSpy();
652652
service.channels$.subscribe(spy);
653-
notification$.next({
653+
events$.next({
654654
eventType: 'notification.message_new',
655655
event: { channel: channel } as any as Event,
656656
});
@@ -673,7 +673,7 @@ describe('ChannelService', () => {
673673
const spy = jasmine.createSpy();
674674
service.channels$.subscribe(spy);
675675
spyOn(service, 'setAsActiveChannel');
676-
notification$.next({
676+
events$.next({
677677
eventType: 'notification.removed_from_channel',
678678
event: { channel: channel } as any as Event,
679679
});
@@ -695,7 +695,7 @@ describe('ChannelService', () => {
695695
const spy = jasmine.createSpy();
696696
service.channels$.subscribe(spy);
697697
spyOn(service, 'setAsActiveChannel');
698-
notification$.next({
698+
events$.next({
699699
eventType: 'notification.removed_from_channel',
700700
event: { channel: channel } as any as Event,
701701
});
@@ -718,7 +718,7 @@ describe('ChannelService', () => {
718718
const channelsSpy = jasmine.createSpy();
719719
service.channels$.subscribe(channelsSpy);
720720
channelsSpy.calls.reset();
721-
notification$.next({
721+
events$.next({
722722
eventType: 'notification.message_new',
723723
event: event,
724724
});
@@ -735,7 +735,7 @@ describe('ChannelService', () => {
735735
await init();
736736
const spy = jasmine
737737
.createSpy()
738-
.and.callFake((_: Notification, setter: (channels: Channel[]) => []) =>
738+
.and.callFake((_: ClientEvent, setter: (channels: Channel[]) => []) =>
739739
setter([])
740740
);
741741
service.customAddedToChannelNotificationHandler = spy;
@@ -747,7 +747,7 @@ describe('ChannelService', () => {
747747
const channelsSpy = jasmine.createSpy();
748748
service.channels$.subscribe(channelsSpy);
749749
channelsSpy.calls.reset();
750-
notification$.next({
750+
events$.next({
751751
eventType: 'notification.added_to_channel',
752752
event: event,
753753
});
@@ -772,7 +772,7 @@ describe('ChannelService', () => {
772772
const channelsSpy = jasmine.createSpy();
773773
service.channels$.subscribe(channelsSpy);
774774
channelsSpy.calls.reset();
775-
notification$.next({
775+
events$.next({
776776
eventType: 'notification.removed_from_channel',
777777
event: event,
778778
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
UserResponse,
1212
} from 'stream-chat';
1313
import { ChannelService } from './channel.service';
14-
import { ChatClientService, Notification } from './chat-client.service';
14+
import { ChatClientService, ClientEvent } from './chat-client.service';
1515
import {
1616
generateMockChannels,
1717
MockChannel,
@@ -29,7 +29,7 @@ describe('ChannelService - threads', () => {
2929
deleteMessage: jasmine.Spy;
3030
userID: string;
3131
};
32-
let notification$: Subject<Notification>;
32+
let events$: Subject<ClientEvent>;
3333
let connectionState$: Subject<'online' | 'offline'>;
3434
let init: (
3535
c?: Channel[],
@@ -51,14 +51,14 @@ describe('ChannelService - threads', () => {
5151
deleteMessage: jasmine.createSpy(),
5252
userID: user.id,
5353
};
54-
notification$ = new Subject();
54+
events$ = new Subject();
5555
TestBed.configureTestingModule({
5656
providers: [
5757
{
5858
provide: ChatClientService,
5959
useValue: {
6060
chatClient: { ...mockChatClient, user },
61-
notification$,
61+
events$,
6262
connectionState$,
6363
},
6464
},

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
UpdatedMessage,
2020
UserResponse,
2121
} from 'stream-chat';
22-
import { ChatClientService, Notification } from './chat-client.service';
22+
import { ChatClientService, ClientEvent } from './chat-client.service';
2323
import { createMessagePreview } from './message-preview';
2424
import { getReadBy } from './read-by';
2525
import { AttachmentUpload, MessageReactionType, StreamMessage } from './types';
@@ -105,21 +105,21 @@ export class ChannelService {
105105
* Custom event handler to call if a new message received from a channel that is not being watched, provide an event handler if you want to override the [default channel list ordering](./ChannelService.mdx/#channels)
106106
*/
107107
customNewMessageNotificationHandler?: (
108-
notification: Notification,
108+
clientEvent: ClientEvent,
109109
channelListSetter: (channels: (Channel | ChannelResponse)[]) => void
110110
) => void;
111111
/**
112112
* Custom event handler to call when the user is added to a channel, provide an event handler if you want to override the [default channel list ordering](./ChannelService.mdx/#channels)
113113
*/
114114
customAddedToChannelNotificationHandler?: (
115-
notification: Notification,
115+
clientEvent: ClientEvent,
116116
channelListSetter: (channels: (Channel | ChannelResponse)[]) => void
117117
) => void;
118118
/**
119119
* Custom event handler to call when the user is removed from a channel, provide an event handler if you want to override the [default channel list ordering](./ChannelService.mdx/#channels)
120120
*/
121121
customRemovedFromChannelNotificationHandler?: (
122-
notification: Notification,
122+
clientEvent: ClientEvent,
123123
channelListSetter: (channels: (Channel | ChannelResponse)[]) => void
124124
) => void;
125125
/**
@@ -408,7 +408,7 @@ export class ChannelService {
408408
};
409409
this.sort = sort || { last_message_at: -1, updated_at: -1 };
410410
await this.queryChannels();
411-
this.chatClientService.notification$.subscribe(
411+
this.chatClientService.events$.subscribe(
412412
(notification) => void this.handleNotification(notification)
413413
);
414414
}
@@ -692,17 +692,17 @@ export class ChannelService {
692692
}
693693
}
694694

695-
private handleNotification(notification: Notification) {
696-
switch (notification.eventType) {
695+
private handleNotification(clientEvent: ClientEvent) {
696+
switch (clientEvent.eventType) {
697697
case 'notification.message_new': {
698698
this.ngZone.run(() => {
699699
if (this.customNewMessageNotificationHandler) {
700700
this.customNewMessageNotificationHandler(
701-
notification,
701+
clientEvent,
702702
this.channelListSetter
703703
);
704704
} else {
705-
this.handleNewMessageNotification(notification);
705+
this.handleNewMessageNotification(clientEvent);
706706
}
707707
});
708708
break;
@@ -711,11 +711,11 @@ export class ChannelService {
711711
this.ngZone.run(() => {
712712
if (this.customAddedToChannelNotificationHandler) {
713713
this.customAddedToChannelNotificationHandler(
714-
notification,
714+
clientEvent,
715715
this.channelListSetter
716716
);
717717
} else {
718-
this.handleAddedToChannelNotification(notification);
718+
this.handleAddedToChannelNotification(clientEvent);
719719
}
720720
});
721721
break;
@@ -724,31 +724,31 @@ export class ChannelService {
724724
this.ngZone.run(() => {
725725
if (this.customRemovedFromChannelNotificationHandler) {
726726
this.customRemovedFromChannelNotificationHandler(
727-
notification,
727+
clientEvent,
728728
this.channelListSetter
729729
);
730730
} else {
731-
this.handleRemovedFromChannelNotification(notification);
731+
this.handleRemovedFromChannelNotification(clientEvent);
732732
}
733733
});
734734
}
735735
}
736736
}
737737

738-
private handleRemovedFromChannelNotification(notification: Notification) {
739-
const channelIdToBeRemoved = notification.event.channel!.cid;
738+
private handleRemovedFromChannelNotification(clientEvent: ClientEvent) {
739+
const channelIdToBeRemoved = clientEvent.event.channel!.cid;
740740
this.removeChannelsFromChannelList([channelIdToBeRemoved]);
741741
}
742742

743-
private handleNewMessageNotification(notification: Notification) {
744-
if (notification.event.channel) {
745-
this.addChannelsFromNotification([notification.event.channel]);
743+
private handleNewMessageNotification(clientEvent: ClientEvent) {
744+
if (clientEvent.event.channel) {
745+
this.addChannelsFromNotification([clientEvent.event.channel]);
746746
}
747747
}
748748

749-
private handleAddedToChannelNotification(notification: Notification) {
750-
if (notification.event.channel) {
751-
this.addChannelsFromNotification([notification.event.channel]);
749+
private handleAddedToChannelNotification(clientEvent: ClientEvent) {
750+
if (clientEvent.event.channel) {
751+
this.addChannelsFromNotification([clientEvent.event.channel]);
752752
}
753753
}
754754

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('ChatClientService', () => {
8787

8888
it('should watch for added to channel events', () => {
8989
const spy = jasmine.createSpy();
90-
service.notification$.subscribe(spy);
90+
service.events$.subscribe(spy);
9191
const event = {
9292
id: 'mockevent',
9393
type: 'notification.added_to_channel',
@@ -102,7 +102,7 @@ describe('ChatClientService', () => {
102102

103103
it('should watch for new message events', () => {
104104
const spy = jasmine.createSpy();
105-
service.notification$.subscribe(spy);
105+
service.events$.subscribe(spy);
106106
const event = {
107107
id: 'mockevent',
108108
type: 'notification.message_new',
@@ -117,7 +117,7 @@ describe('ChatClientService', () => {
117117

118118
it('should watch for removed from channel events', () => {
119119
const spy = jasmine.createSpy();
120-
service.notification$.subscribe(spy);
120+
service.events$.subscribe(spy);
121121
const event = {
122122
id: 'mockevent',
123123
type: 'notification.removed_from_channel',

0 commit comments

Comments
 (0)