Skip to content

Commit b64baf1

Browse files
committed
feat: run all WS event handlers inside Angular's zone
1 parent 413a800 commit b64baf1

File tree

4 files changed

+305
-354
lines changed

4 files changed

+305
-354
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ export class AvatarComponent
163163
.pipe(filter((e) => e.eventType === 'user.presence.changed'))
164164
.subscribe((event) => {
165165
if (event.event.user?.id === otherMember.id) {
166-
this.ngZone.run(() => {
167-
this.isOnline = event.event.user?.online || false;
168-
});
166+
this.isOnline = event.event.user?.online || false;
169167
}
170168
});
171169
} else {

projects/stream-chat-angular/src/lib/channel-preview/channel-preview.component.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
8585
this.channel!.on('channel.truncated', this.handleMessageEvent.bind(this))
8686
);
8787
this.subscriptions.push(
88-
this.channel!.on('message.read', () =>
89-
this.ngZone.run(() => {
90-
this.isUnreadMessageWasCalled = false;
91-
this.updateUnreadState();
92-
})
93-
)
88+
this.channel!.on('message.read', () => {
89+
this.isUnreadMessageWasCalled = false;
90+
this.updateUnreadState();
91+
})
9492
);
9593
this.subscriptions.push(
9694
this.chatClientService.events$
@@ -102,10 +100,8 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
102100
)
103101
)
104102
.subscribe(() => {
105-
this.ngZone.run(() => {
106-
this.isUnreadMessageWasCalled = true;
107-
this.updateUnreadState();
108-
});
103+
this.isUnreadMessageWasCalled = true;
104+
this.updateUnreadState();
109105
})
110106
);
111107
}
@@ -137,24 +133,22 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
137133
}
138134

139135
private handleMessageEvent(event: Event) {
140-
this.ngZone.run(() => {
141-
if (this.channel?.state.latestMessages.length === 0) {
142-
this.latestMessage = undefined;
143-
this.latestMessageStatus = undefined;
144-
this.latestMessageText = 'streamChat.Nothing yet...';
145-
this.latestMessageTime = undefined;
146-
return;
147-
}
148-
const latestMessage =
149-
this.channel?.state.latestMessages[
150-
this.channel?.state.latestMessages.length - 1
151-
];
152-
if (!event.message || latestMessage?.id !== event.message.id) {
153-
return;
154-
}
155-
this.setLatestMessage(latestMessage);
156-
this.updateUnreadState();
157-
});
136+
if (this.channel?.state.latestMessages.length === 0) {
137+
this.latestMessage = undefined;
138+
this.latestMessageStatus = undefined;
139+
this.latestMessageText = 'streamChat.Nothing yet...';
140+
this.latestMessageTime = undefined;
141+
return;
142+
}
143+
const latestMessage =
144+
this.channel?.state.latestMessages[
145+
this.channel?.state.latestMessages.length - 1
146+
];
147+
if (!event.message || latestMessage?.id !== event.message.id) {
148+
return;
149+
}
150+
this.setLatestMessage(latestMessage);
151+
this.updateUnreadState();
158152
}
159153

160154
private setLatestMessage(

0 commit comments

Comments
 (0)