Removed LocalDB#addWaitingMessageToLocalDB, fixed formatting

This commit is contained in:
Kai S. K. Engelbart 2019-11-16 10:47:32 +01:00
parent eadccd7126
commit b657f2a516
2 changed files with 5 additions and 19 deletions

View File

@ -46,7 +46,7 @@ public class LocalDB {
* *
* @param client the user that is logged in with this client * @param client the user that is logged in with this client
* @since Envoy v0.1-alpha * @since Envoy v0.1-alpha
**/ */
public LocalDB(User sender) { public LocalDB(User sender) {
this.sender = sender; this.sender = sender;
@ -64,7 +64,7 @@ public class LocalDB {
* @param localDBDir the directory where we wish to save/load the database from. * @param localDBDir the directory where we wish to save/load the database from.
* @throws EnvoyException if the directory selected is not an actual directory. * @throws EnvoyException if the directory selected is not an actual directory.
* @since Envoy v0.1-alpha * @since Envoy v0.1-alpha
**/ */
public void initializeDBFile(File localDBDir) throws EnvoyException { public void initializeDBFile(File localDBDir) throws EnvoyException {
if (localDBDir.exists() && !localDBDir.isDirectory()) if (localDBDir.exists() && !localDBDir.isDirectory())
throw new EnvoyException(String.format("LocalDBDir '%s' is not a directory!", localDBDir.getAbsolutePath())); 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 * @throws IOException if something went wrong during saving
* @since Envoy v0.1-alpha * @since Envoy v0.1-alpha
**/ */
public void saveToLocalDB() { public void saveToLocalDB() {
try { try {
localDB.getParentFile().mkdirs(); localDB.getParentFile().mkdirs();
@ -99,7 +99,7 @@ public class LocalDB {
* *
* @throws EnvoyException if something fails while loading. * @throws EnvoyException if something fails while loading.
* @since Envoy v0.1-alpha * @since Envoy v0.1-alpha
**/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void loadFromLocalDB() throws EnvoyException { private void loadFromLocalDB() throws EnvoyException {
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(localDB))) { 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().setMessageId(returnSync.getMessages().get(j).getMetadata().getMessageId());
sync.getMessages().get(j).getMetadata().setState(returnSync.getMessages().get(j).getMetadata().getState()); 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 if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0 && returnSync.getMessages().get(i).getMetadata().getSender() != 0
&& returnSync.getMessages().get(i).getMetadata().getState() == MessageState.RECEIVED) { && returnSync.getMessages().get(i).getMetadata().getState() == MessageState.RECEIVED) {
// these are the unread Messages from the server // these are the unread Messages from the server
unreadMessagesSync.getMessages().add(returnSync.getMessages().get(i)); unreadMessagesSync.getMessages().add(returnSync.getMessages().get(i));
} }
if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0 && returnSync.getMessages().get(i).getMetadata().getSender() == 0 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.getMessages().clear();
sync.getUsers().clear(); sync.getUsers().clear();
} }
/** /**
@ -261,15 +256,6 @@ public class LocalDB {
} else break; } 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 * Adds all messages with state {@code WAITING} from the {@link LocalDB} to the
* {@link Sync} object. * {@link Sync} object.

View File

@ -269,7 +269,7 @@ public class ChatWindow extends JFrame {
// Create and send message object // Create and send message object
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient()); final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient());
localDB.addWaitingMessageToLocalDB(message, currentChat); currentChat.appendMessage(message);
messageList.setModel(currentChat.getModel()); messageList.setModel(currentChat.getModel());
// Clear text field // Clear text field