Fix Unread Messages Not Being Displayed for Groups (#49)

Fix unread messages not being displayed for groups

Fixes #48
Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/49
Reviewed-by: delvh <leon@kske.dev>
This commit is contained in:
Kai S. K. Engelbart 2020-09-25 11:22:59 +02:00
parent f02b01291b
commit f0e645c0ae

View File

@ -222,20 +222,21 @@ public final class ChatScene implements EventListener, Restorable {
// The sender of the message is the recipient of the chat // The sender of the message is the recipient of the chat
// Exceptions: this user is the sender (sync) or group message (group is // Exceptions: this user is the sender (sync) or group message (group is
// recipient) // recipient)
final var recipientID = message instanceof GroupMessage || message.getSenderID() == localDB.getUser().getID() ? message.getRecipientID() final boolean ownMessage = message.getSenderID() == localDB.getUser().getID();
: message.getSenderID(); final var recipientID = message instanceof GroupMessage || ownMessage ? message.getRecipientID() : message.getSenderID();
localDB.getChat(recipientID).ifPresent(chat -> { localDB.getChat(recipientID).ifPresent(chat -> {
chat.insert(message); chat.insert(message);
// Read current chat or increment unread amount
if (chat.equals(currentChat)) { if (chat.equals(currentChat)) {
try { try {
currentChat.read(writeProxy); currentChat.read(writeProxy);
} catch (final IOException e1) { } catch (final IOException e) {
logger.log(Level.WARNING, "Could not read current chat: ", e1); logger.log(Level.WARNING, "Could not read current chat: ", e);
} }
Platform.runLater(() -> { ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); }); Platform.runLater(() -> { ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); });
// TODO: Increment unread counter for group messages with status < RECEIVED } else if (!ownMessage && message.getStatus() != MessageStatus.READ) chat.incrementUnreadAmount();
} else
if (message.getSenderID() != localDB.getUser().getID() && message.getStatus() == MessageStatus.RECEIVED) chat.incrementUnreadAmount();
// Move chat with most recent unread messages to the top // Move chat with most recent unread messages to the top
Platform.runLater(() -> { Platform.runLater(() -> {