From 1cf6b9852370f63d15dd15cf59bea39f0a52023d Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 1 Aug 2020 17:34:34 +0200 Subject: [PATCH] Fixed errors caused by the new ListModel --- .../java/envoy/client/ui/controller/ChatScene.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index d8f096e..a041b9d 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -191,8 +191,9 @@ public final class ChatScene implements Restorable { // Move chat with most recent unread messages to the top Platform.runLater(() -> { - chatList.getItems().remove(chat); - chatList.getItems().add(0, chat); + chats.getSource().remove(chat); + ((ObservableList) chats.getSource()).add(0, chat); + if (chat.equals(currentChat)) chatList.getSelectionModel().select(0); }); }); @@ -215,7 +216,7 @@ public final class ChatScene implements Restorable { // Listen to user status changes eventBus.register(UserStatusChange.class, - e -> chatList.getItems() + e -> chats.getSource() .stream() .filter(c -> c.getRecipient().getID() == e.getID()) .findAny() @@ -229,10 +230,11 @@ public final class ChatScene implements Restorable { case ADD: if (contact instanceof User) localDB.getUsers().put(contact.getName(), (User) contact); final Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact); - Platform.runLater(() -> chatList.getItems().add(chat)); + Platform.runLater(() -> ((ObservableList) chats.getSource()).add(0, chat)); + break; case REMOVE: - Platform.runLater(() -> chatList.getItems().removeIf(c -> c.getRecipient().equals(contact))); + Platform.runLater(() -> chats.getSource().removeIf(c -> c.getRecipient().equals(contact))); break; } });