Preventing sent messages from being added to the sync again

Fixed #25
This commit is contained in:
Kai S. K. Engelbart 2019-11-16 08:23:04 +01:00
parent 73eb312a90
commit eadccd7126
2 changed files with 9 additions and 39 deletions

View File

@ -137,10 +137,7 @@ public class LocalDB {
public Sync fillSync(long userId) { public Sync fillSync(long userId) {
addWaitingMessagesToSync(); addWaitingMessagesToSync();
getSentStateMessagesFromLocalDB(); sync.getMessages().addAll(readMessages.getMessages());
for (int i = 0; i < readMessages.getMessages().size(); i++) {
sync.getMessages().add(readMessages.getMessages().get(i));
}
readMessages.getMessages().clear(); readMessages.getMessages().clear();
System.out.println(sync.getMessages().size()); 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 * Adds the unread messages returned from the server in the latest sync to the
* right chats in the LocalDB. * 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 * Changes all messages with state {@code RECEIVED} of a specific chat to state
* {@code READ}. * {@code READ}.
@ -299,21 +271,18 @@ public class LocalDB {
public void addWaitingMessageToLocalDB(Message message, Chat currentChat) { currentChat.appendMessage(message); } 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 * @since Envoy v0.1-alpha
*/ */
private void addWaitingMessagesToSync() { private void addWaitingMessagesToSync() {
for (int i = 0; i < getChats().size(); i++) { for (Chat chat : getChats())
for (int j = 0; j < getChats().get(i).getModel().getSize(); j++) { for (int i = 0; i < chat.getModel().size(); i++)
if (getChats().get(i).getModel().get(j).getMetadata().getState() == MessageState.WAITING) { if (chat.getModel().get(i).getMetadata().getState() == MessageState.WAITING) {
// addMessageToSync(localDB.getChats().get(i).getModel().get(j));
System.out.println("Got Waiting Message"); System.out.println("Got Waiting Message");
sync.getMessages().add(0, getChats().get(i).getModel().get(j)); sync.getMessages().add(chat.getModel().get(i));
} }
}
}
} }
/** /**

View File

@ -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 * @param timeout the amount of time that passes between two requests sent to
* the server * the server