Merge branch 'develop' into f/logging

This commit is contained in:
delvh
2019-11-29 20:33:42 +01:00
committed by GitHub
2 changed files with 319 additions and 378 deletions

View File

@ -226,7 +226,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);
@ -272,7 +272,7 @@ public class ChatWindow extends JFrame {
// Create and send message object
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient());
localDB.addWaitingMessageToLocalDB(message, currentChat);
currentChat.appendMessage(message);
messageList.setModel(currentChat.getModel());
// Clear text field
@ -309,7 +309,8 @@ public class ChatWindow extends JFrame {
}
/**
* Updates the data model and the ui every x seconds.
* Updates the data model and the UI repeatedly after a certain amount of
* time.
*
* @param timeout the amount of time that passes between two requests sent to
* the server
@ -322,9 +323,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(); });
@ -338,4 +344,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); } }
}