Fix message insertion into empty list and from sender

This commit is contained in:
Kai S. K. Engelbart 2020-07-01 08:45:39 +02:00
parent 26a8650353
commit c54e7085ce
2 changed files with 6 additions and 3 deletions

View File

@ -32,7 +32,8 @@ public final class Chat implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Provides the list of messages that the recipient receives.<p> * Provides the list of messages that the recipient receives.
* <p>
* Saves the Messages in the corresponding chat at that Point. * Saves the Messages in the corresponding chat at that Point.
* *
* @param recipient the user who receives the messages * @param recipient the user who receives the messages
@ -100,7 +101,8 @@ public final class Chat implements Serializable {
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void insert(Message message) { 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())) { if (message.getCreationDate().isAfter(messages.get(i).getCreationDate())) {
messages.add(i + 1, message); messages.add(i + 1, message);
break; break;

View File

@ -317,7 +317,8 @@ public final class ChatScene {
writeProxy.writeMessage(message); writeProxy.writeMessage(message);
// Add message to LocalDB and update UI // Add message to LocalDB and update UI
messageList.getItems().add(message); currentChat.insert(message);
messageList.refresh();
scrollToMessageListEnd(); scrollToMessageListEnd();
// Request a new ID generator if all IDs were used // Request a new ID generator if all IDs were used