From 47ab5d1e0c03c8d6180d7cb15b3b35f4297273fd Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 17 Jul 2020 00:27:00 +0200 Subject: [PATCH] Fix unread message counter A bug remains when the total status of a group message is SENT, but the individual status for the client user is RECEIVED. In this case, the counter should be incremented but isn't. --- .../java/envoy/client/ui/controller/ChatScene.java | 14 +++++++++++--- .../processors/LoginCredentialProcessor.java | 12 ++++++------ 2 files changed, 17 insertions(+), 9 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 ef4e38f..574e036 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -138,7 +138,13 @@ public final class ChatScene implements Restorable { // Listen to received messages eventBus.register(MessageCreationEvent.class, e -> { final var message = e.get(); - localDB.getChat(message instanceof GroupMessage ? message.getRecipientID() : message.getSenderID()).ifPresent(chat -> { + + // 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 long recipientID = message instanceof GroupMessage || message.getSenderID() == localDB.getUser().getID() ? message.getRecipientID() + : message.getSenderID(); + localDB.getChat(recipientID).ifPresent(chat -> { chat.insert(message); if (chat.equals(currentChat)) { try { @@ -147,8 +153,10 @@ public final class ChatScene implements Restorable { logger.log(Level.WARNING, "Could not read current chat: ", e1); } Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); }); - } else if (message.getRecipientID() == chat.getRecipient().getID() && message.getStatus() == RECEIVED) chat.incrementUnreadAmount(); - // Moving chat with most recent unreadMessages to the top + // TODO: Increment unread counter for group messages with status < RECEIVED + } else if (message.getSenderID() != localDB.getUser().getID() && message.getStatus() == RECEIVED) chat.incrementUnreadAmount(); + + // Move chat with most recent unread messages to the top Platform.runLater(() -> { chatList.getItems().remove(chat); chatList.getItems().add(0, chat); diff --git a/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index 391dab0..598d2d4 100755 --- a/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -110,8 +110,9 @@ public final class LoginCredentialProcessor implements ObjectProcessor