Fix Unread Messages Not Being Displayed for Groups #49

Merged
kske merged 1 commits from b/group-unread-messages into develop 2020-09-25 11:23:00 +02:00
Showing only changes of commit 0c10068fb5 - Show all commits

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(() -> {