Mark all newly received messages in the current chat as read

Fixes #24
This commit is contained in:
2019-11-16 08:06:07 +01:00
parent 0b5dbe59dc
commit 49ea688770
2 changed files with 42 additions and 65 deletions

View File

@ -223,7 +223,7 @@ public class ChatWindow extends JFrame {
.get();
// Set all unread messages in the chat to read
if (currentChat != null) { localDB.setMessagesToRead(currentChat); }
readCurrentChat();
client.setRecipient(user);
@ -319,9 +319,14 @@ public class ChatWindow extends JFrame {
// Synchronize
localDB.applySync(
client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
// Process unread messages
localDB.addUnreadMessagesToLocalDB();
localDB.clearUnreadMessagesSync();
// Mark unread messages as read when they are in the current chat
readCurrentChat();
// Update UI
SwingUtilities
.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
@ -335,4 +340,9 @@ public class ChatWindow extends JFrame {
if (userList.getModel().getElementAt(i).getID() == localDB.getChats().get(j).getRecipient().getID())
userList.getModel().getElementAt(i).setStatus(localDB.getChats().get(j).getRecipient().getStatus());
}
/**
* Marks messages in the current chat as {@code READ}.
*/
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
}