Fixed bug not scrolling to the correct message

This commit is contained in:
delvh 2020-07-15 21:44:57 +02:00
parent 88afb77a2c
commit c963b9bdcc

View File

@ -184,7 +184,7 @@ public final class ChatScene implements Restorable {
switch (e.getOperationType()) { switch (e.getOperationType()) {
case ADD: case ADD:
localDB.getUsers().put(contact.getName(), contact); localDB.getUsers().put(contact.getName(), contact);
Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact); final Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact);
Platform.runLater(() -> chatList.getItems().add(chat)); Platform.runLater(() -> chatList.getItems().add(chat));
break; break;
case REMOVE: case REMOVE:
@ -240,7 +240,7 @@ public final class ChatScene implements Restorable {
currentChat = localDB.getChat(user.getID()).get(); currentChat = localDB.getChat(user.getID()).get();
messageList.setItems(FXCollections.observableList(currentChat.getMessages())); messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
final var scrollIndex = messageList.getItems().size() - currentChat.getUnreadAmount() - 1; final var scrollIndex = messageList.getItems().size() - currentChat.getUnreadAmount();
messageList.scrollTo(scrollIndex); messageList.scrollTo(scrollIndex);
logger.log(Level.FINEST, "Loading chat with " + user + " at index " + scrollIndex); logger.log(Level.FINEST, "Loading chat with " + user + " at index " + scrollIndex);
deleteContactMenuItem.setText("Delete " + user.getName()); deleteContactMenuItem.setText("Delete " + user.getName());