Skip to content

Commit

Permalink
Avoid updating all list items and only target the chat with new notif…
Browse files Browse the repository at this point in the history
…ications
  • Loading branch information
axpoems committed Mar 13, 2024
1 parent df6f33e commit f8ce877
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,17 @@ private void handleNotification(ChatNotification notification) {
return;
}

String channelId = notification.getChatChannelId();
if (isPrivateChannel(channelId)) {
handlePrivateNotification();
}
}

private boolean isPrivateChannel(String channelId) {
return channelService.findChannel(channelId).isPresent();
handlePrivateNotification(notification.getChatChannelId());
}

private void handlePrivateNotification() {
private void handlePrivateNotification(String channelId) {
UIThread.run(() -> {
channelService.getChannels().forEach(channel -> {
channelService.findChannel(channelId).ifPresent(channel -> {
long numNotifications = chatNotificationService.getNotConsumedNotifications(channel.getId()).count();
model.getFilteredList().stream()
.filter(listItem -> listItem.getChannel() == channel)
.findAny()
.ifPresent(listItem -> listItem.setNumNotifications(numNotifications)
);
.ifPresent(listItem -> listItem.setNumNotifications(numNotifications));
});
});
}
Expand Down

0 comments on commit f8ce877

Please sign in to comment.