update chat view messages on user thread

This commit is contained in:
woodser 2024-05-19 10:55:55 -04:00
parent 2e605a590e
commit 3fbb2f95d0

View File

@ -299,6 +299,7 @@ public class ChatView extends AnchorPane {
@Override
protected void updateItem(ChatMessage message, boolean empty) {
UserThread.execute(() -> {
super.updateItem(message, empty);
if (message != null && !empty) {
copyIcon.setOnMouseClicked(e -> Utilities.copyToClipboard(messageLabel.getText()));
@ -346,7 +347,7 @@ public class ChatView extends AnchorPane {
bg.setId("message-bubble-green");
messageLabel.getStyleClass().add("my-message");
copyIcon.getStyleClass().add("my-message");
message.addWeakMessageStateListener(() -> updateMsgState(message));
message.addWeakMessageStateListener(() -> UserThread.execute(() -> updateMsgState(message)));
updateMsgState(message);
} else if (isMyMsg) {
headerLabel.getStyleClass().add("my-message-header");
@ -363,11 +364,11 @@ public class ChatView extends AnchorPane {
sendMsgBusyAnimationListener = (observable, oldValue, newValue) -> {
if (!newValue)
updateMsgState(message);
UserThread.execute(() -> updateMsgState(message));
};
sendMsgBusyAnimation.isRunningProperty().addListener(sendMsgBusyAnimationListener);
message.addWeakMessageStateListener(() -> updateMsgState(message));
message.addWeakMessageStateListener(() -> UserThread.execute(() -> updateMsgState(message)));
updateMsgState(message);
} else {
headerLabel.getStyleClass().add("message-header");
@ -456,7 +457,7 @@ public class ChatView extends AnchorPane {
copyIcon.getStyleClass().addAll("icon", "copy-icon-disputes");
// TODO There are still some cell rendering issues on updates
UserThread.execute(() -> setGraphic(messageAnchorPane));
setGraphic(messageAnchorPane);
} else {
if (sendMsgBusyAnimation != null && sendMsgBusyAnimationListener != null)
sendMsgBusyAnimation.isRunningProperty().removeListener(sendMsgBusyAnimationListener);
@ -465,12 +466,12 @@ public class ChatView extends AnchorPane {
copyIcon.setOnMouseClicked(null);
messageLabel.setOnMouseClicked(null);
UserThread.execute(() -> setGraphic(null));
setGraphic(null);
}
});
}
private void updateMsgState(ChatMessage message) {
UserThread.execute(() -> {
boolean visible;
AwesomeIcon icon = null;
String text = null;
@ -508,7 +509,6 @@ public class ChatView extends AnchorPane {
statusIcon.setTooltip(new Tooltip(text));
statusInfoLabel.setText(text);
}
});
}
};
}