From 5a3365b4cb44e260151c938da38ec017a0e06aa2 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 16 Nov 2019 08:23:04 +0100 Subject: [PATCH] Preventing sent messages from being added to the sync again Fixed #25 --- src/main/java/envoy/client/LocalDB.java | 45 +++---------------- src/main/java/envoy/client/ui/ChatWindow.java | 3 +- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/main/java/envoy/client/LocalDB.java b/src/main/java/envoy/client/LocalDB.java index 29d7a5c..ace6881 100644 --- a/src/main/java/envoy/client/LocalDB.java +++ b/src/main/java/envoy/client/LocalDB.java @@ -137,10 +137,7 @@ public class LocalDB { public Sync fillSync(long userId) { addWaitingMessagesToSync(); - getSentStateMessagesFromLocalDB(); - for (int i = 0; i < readMessages.getMessages().size(); i++) { - sync.getMessages().add(readMessages.getMessages().get(i)); - } + sync.getMessages().addAll(readMessages.getMessages()); readMessages.getMessages().clear(); System.out.println(sync.getMessages().size()); @@ -230,14 +227,6 @@ public class LocalDB { } - /** - * Adds a message to the "sync" Sync object. - * - * @param message - * @since Envoy v0.1-alpha - */ - private void addMessageToSync(Message message) { sync.getMessages().add(message); } - /** * Adds the unread messages returned from the server in the latest sync to the * right chats in the LocalDB. @@ -254,23 +243,6 @@ public class LocalDB { } } - /** - * Gets all messages with state {@code SENT} from the LocalDB and adds them to - * the {@code sync} {@link Sync} object. - * - * @param localDB - * @since Envoy v0.1-alpha - */ - private void getSentStateMessagesFromLocalDB() { - for (int i = 0; i < getChats().size(); i++) { - for (int j = 0; j < getChats().get(i).getModel().getSize(); j++) { - if (getChats().get(i).getModel().get(j).getMetadata().getState() == MessageState.SENT) { - addMessageToSync(getChats().get(i).getModel().get(j)); - } - } - } - } - /** * Changes all messages with state {@code RECEIVED} of a specific chat to state * {@code READ}. @@ -299,21 +271,18 @@ public class LocalDB { public void addWaitingMessageToLocalDB(Message message, Chat currentChat) { currentChat.appendMessage(message); } /** - * Adds all messages with State WAITING from the {@link LocalDB} to the Sync. + * Adds all messages with state {@code WAITING} from the {@link LocalDB} to the + * {@link Sync} object. * - * @param localDB * @since Envoy v0.1-alpha */ private void addWaitingMessagesToSync() { - for (int i = 0; i < getChats().size(); i++) { - for (int j = 0; j < getChats().get(i).getModel().getSize(); j++) { - if (getChats().get(i).getModel().get(j).getMetadata().getState() == MessageState.WAITING) { - // addMessageToSync(localDB.getChats().get(i).getModel().get(j)); + for (Chat chat : getChats()) + for (int i = 0; i < chat.getModel().size(); i++) + if (chat.getModel().get(i).getMetadata().getState() == MessageState.WAITING) { System.out.println("Got Waiting Message"); - sync.getMessages().add(0, getChats().get(i).getModel().get(j)); + sync.getMessages().add(chat.getModel().get(i)); } - } - } } /** diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 66b750f..48d3bdc 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -306,7 +306,8 @@ public class ChatWindow extends JFrame { } /** - * Updates the data model and the ui every x seconds. + * Updates the data model and the UI every repeatedly after a certain amount of + * time. * * @param timeout the amount of time that passes between two requests sent to * the server