Fixed errors caused by the new ListModel

This commit is contained in:
DieGurke 2020-08-01 17:34:34 +02:00
parent 0901f900e7
commit a1d09d6550
1 changed files with 7 additions and 5 deletions

View File

@ -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<Chat>) 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<Chat>) 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;
}
});