From b380efc38fdb678cb174a5e6d0e2c2dbc7936b39 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 1 Jul 2020 08:45:39 +0200 Subject: [PATCH] Fix message insertion into empty list and from sender --- src/main/java/envoy/client/data/Chat.java | 6 ++++-- src/main/java/envoy/client/ui/controller/ChatScene.java | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index f26fa15..51c2b1b 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -32,7 +32,8 @@ public final class Chat implements Serializable { private static final long serialVersionUID = 1L; /** - * Provides the list of messages that the recipient receives.

+ * Provides the list of messages that the recipient receives. + *

* Saves the Messages in the corresponding chat at that Point. * * @param recipient the user who receives the messages @@ -100,7 +101,8 @@ public final class Chat implements Serializable { * @since Envoy Client v0.1-beta */ public void insert(Message message) { - for (int i = messages.size() - 1; i >= 0; --i) + if (messages.isEmpty()) messages.add(message); + else for (int i = messages.size() - 1; i >= 0; --i) if (message.getCreationDate().isAfter(messages.get(i).getCreationDate())) { messages.add(i + 1, message); break; diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index e31ebcb..38f3aa1 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -317,7 +317,8 @@ public final class ChatScene { writeProxy.writeMessage(message); // Add message to LocalDB and update UI - messageList.getItems().add(message); + currentChat.insert(message); + messageList.refresh(); scrollToMessageListEnd(); // Request a new ID generator if all IDs were used