From b657f2a516ef3799a2bbfbda0910359aedf67894 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 16 Nov 2019 10:47:32 +0100 Subject: [PATCH] Removed LocalDB#addWaitingMessageToLocalDB, fixed formatting --- src/main/java/envoy/client/LocalDB.java | 22 ++++--------------- src/main/java/envoy/client/ui/ChatWindow.java | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/main/java/envoy/client/LocalDB.java b/src/main/java/envoy/client/LocalDB.java index ace6881..3cc96a2 100644 --- a/src/main/java/envoy/client/LocalDB.java +++ b/src/main/java/envoy/client/LocalDB.java @@ -46,7 +46,7 @@ public class LocalDB { * * @param client the user that is logged in with this client * @since Envoy v0.1-alpha - **/ + */ public LocalDB(User sender) { this.sender = sender; @@ -64,7 +64,7 @@ public class LocalDB { * @param localDBDir the directory where we wish to save/load the database from. * @throws EnvoyException if the directory selected is not an actual directory. * @since Envoy v0.1-alpha - **/ + */ public void initializeDBFile(File localDBDir) throws EnvoyException { if (localDBDir.exists() && !localDBDir.isDirectory()) throw new EnvoyException(String.format("LocalDBDir '%s' is not a directory!", localDBDir.getAbsolutePath())); @@ -77,7 +77,7 @@ public class LocalDB { * * @throws IOException if something went wrong during saving * @since Envoy v0.1-alpha - **/ + */ public void saveToLocalDB() { try { localDB.getParentFile().mkdirs(); @@ -99,7 +99,7 @@ public class LocalDB { * * @throws EnvoyException if something fails while loading. * @since Envoy v0.1-alpha - **/ + */ @SuppressWarnings("unchecked") private void loadFromLocalDB() throws EnvoyException { try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(localDB))) { @@ -155,15 +155,12 @@ public class LocalDB { sync.getMessages().get(j).getMetadata().setMessageId(returnSync.getMessages().get(j).getMetadata().getMessageId()); sync.getMessages().get(j).getMetadata().setState(returnSync.getMessages().get(j).getMetadata().getState()); } - } - } if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0 && returnSync.getMessages().get(i).getMetadata().getSender() != 0 && returnSync.getMessages().get(i).getMetadata().getState() == MessageState.RECEIVED) { // these are the unread Messages from the server unreadMessagesSync.getMessages().add(returnSync.getMessages().get(i)); - } if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0 && returnSync.getMessages().get(i).getMetadata().getSender() == 0 @@ -207,7 +204,6 @@ public class LocalDB { } } } - } } @@ -224,7 +220,6 @@ public class LocalDB { sync.getMessages().clear(); sync.getUsers().clear(); - } /** @@ -261,15 +256,6 @@ public class LocalDB { } else break; } - /** - * Adds a message with State WAITING to a specific chat in the LocalDB. - * - * @param message - * @param currentChat - * @since Envoy v0.1-alpha - */ - public void addWaitingMessageToLocalDB(Message message, Chat currentChat) { currentChat.appendMessage(message); } - /** * Adds all messages with state {@code WAITING} from the {@link LocalDB} to the * {@link Sync} object. diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 48d3bdc..b9aea74 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -269,7 +269,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