From 0c10068fb548342e6756497d0eea32be252dd31e Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 24 Sep 2020 11:24:39 +0200 Subject: [PATCH] Fix unread messages not being displayed for groups Fixes #48 --- .../envoy/client/ui/controller/ChatScene.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index fbec656..4ee5e38 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -222,20 +222,21 @@ public final class ChatScene implements EventListener, Restorable { // The sender of the message is the recipient of the chat // Exceptions: this user is the sender (sync) or group message (group is // recipient) - final var recipientID = message instanceof GroupMessage || message.getSenderID() == localDB.getUser().getID() ? message.getRecipientID() - : message.getSenderID(); + final boolean ownMessage = message.getSenderID() == localDB.getUser().getID(); + final var recipientID = message instanceof GroupMessage || ownMessage ? message.getRecipientID() : message.getSenderID(); + localDB.getChat(recipientID).ifPresent(chat -> { chat.insert(message); + + // Read current chat or increment unread amount if (chat.equals(currentChat)) { try { currentChat.read(writeProxy); - } catch (final IOException e1) { - logger.log(Level.WARNING, "Could not read current chat: ", e1); + } catch (final IOException e) { + logger.log(Level.WARNING, "Could not read current chat: ", e); } Platform.runLater(() -> { ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); }); - // TODO: Increment unread counter for group messages with status < RECEIVED - } else - if (message.getSenderID() != localDB.getUser().getID() && message.getStatus() == MessageStatus.RECEIVED) chat.incrementUnreadAmount(); + } else if (!ownMessage && message.getStatus() != MessageStatus.READ) chat.incrementUnreadAmount(); // Move chat with most recent unread messages to the top Platform.runLater(() -> { -- 2.45.2