Skip to content

Commit

Permalink
Merge pull request #688 from GetStream/run-ws-events-inside-scope
Browse files Browse the repository at this point in the history
feat: run all WS event handlers inside Angular's zone
  • Loading branch information
szuperaz authored Feb 20, 2025
2 parents 413a800 + b64baf1 commit 785513e
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ export class AvatarComponent
.pipe(filter((e) => e.eventType === 'user.presence.changed'))
.subscribe((event) => {
if (event.event.user?.id === otherMember.id) {
this.ngZone.run(() => {
this.isOnline = event.event.user?.online || false;
});
this.isOnline = event.event.user?.online || false;
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
this.channel!.on('channel.truncated', this.handleMessageEvent.bind(this))
);
this.subscriptions.push(
this.channel!.on('message.read', () =>
this.ngZone.run(() => {
this.isUnreadMessageWasCalled = false;
this.updateUnreadState();
})
)
this.channel!.on('message.read', () => {
this.isUnreadMessageWasCalled = false;
this.updateUnreadState();
})
);
this.subscriptions.push(
this.chatClientService.events$
Expand All @@ -102,10 +100,8 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
)
)
.subscribe(() => {
this.ngZone.run(() => {
this.isUnreadMessageWasCalled = true;
this.updateUnreadState();
});
this.isUnreadMessageWasCalled = true;
this.updateUnreadState();
})
);
}
Expand Down Expand Up @@ -137,24 +133,22 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
}

private handleMessageEvent(event: Event) {
this.ngZone.run(() => {
if (this.channel?.state.latestMessages.length === 0) {
this.latestMessage = undefined;
this.latestMessageStatus = undefined;
this.latestMessageText = 'streamChat.Nothing yet...';
this.latestMessageTime = undefined;
return;
}
const latestMessage =
this.channel?.state.latestMessages[
this.channel?.state.latestMessages.length - 1
];
if (!event.message || latestMessage?.id !== event.message.id) {
return;
}
this.setLatestMessage(latestMessage);
this.updateUnreadState();
});
if (this.channel?.state.latestMessages.length === 0) {
this.latestMessage = undefined;
this.latestMessageStatus = undefined;
this.latestMessageText = 'streamChat.Nothing yet...';
this.latestMessageTime = undefined;
return;
}
const latestMessage =
this.channel?.state.latestMessages[
this.channel?.state.latestMessages.length - 1
];
if (!event.message || latestMessage?.id !== event.message.id) {
return;
}
this.setLatestMessage(latestMessage);
this.updateUnreadState();
}

private setLatestMessage(
Expand Down
Loading

0 comments on commit 785513e

Please sign in to comment.