From 3c7841ae28e014802f648808ae645a58fe79edad Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 18 Mar 2024 10:47:43 -0400 Subject: [PATCH] fix chat message listeners by returning source observable list (#830) --- core/src/main/java/haveno/core/trade/Trade.java | 7 +------ .../portfolio/pendingtrades/PendingTradesView.java | 12 +++++++----- .../java/haveno/desktop/main/shared/ChatView.java | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 6fa413032b..74531ba129 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -394,6 +394,7 @@ public abstract class Trade implements Tradable, Model { @Setter @Nullable private String counterCurrencyTxId; + @Getter private final ObservableList chatMessages = FXCollections.observableArrayList(); // Transient @@ -1666,12 +1667,6 @@ public abstract class Trade implements Tradable, Model { throw new IllegalArgumentException("Trade is not buyer, seller, or arbitrator"); } - public ObservableList getChatMessages() { - synchronized (chatMessages) { - return FXCollections.observableArrayList(chatMessages); - } - } - public MessageState getPaymentSentMessageState() { if (isPaymentReceived()) return MessageState.ACKNOWLEDGED; if (processModel.getPaymentSentMessageStateProperty().get() == MessageState.ACKNOWLEDGED) return MessageState.ACKNOWLEDGED; diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesView.java b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesView.java index 5e3b643d70..6df3a7c0a4 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesView.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesView.java @@ -416,11 +416,13 @@ public class PendingTradesView extends ActivatableViewAndModel { Trade trade = t.getTrade(); - newChatMessagesByTradeMap.put(trade.getId(), - trade.getChatMessages().stream() - .filter(m -> !m.isWasDisplayed()) - .filter(m -> !m.isSystemMessage()) - .count()); + synchronized (trade.getChatMessages()) { + newChatMessagesByTradeMap.put(trade.getId(), + trade.getChatMessages().stream() + .filter(m -> !m.isWasDisplayed()) + .filter(m -> !m.isSystemMessage()) + .count()); + } }); } diff --git a/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java b/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java index d9152899d9..eecf326fd5 100644 --- a/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java +++ b/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java @@ -439,7 +439,7 @@ public class ChatView extends AnchorPane { copyIcon.getStyleClass().addAll("icon", "copy-icon-disputes"); // TODO There are still some cell rendering issues on updates - setGraphic(messageAnchorPane); + UserThread.execute(() -> setGraphic(messageAnchorPane)); } else { if (sendMsgBusyAnimation != null && sendMsgBusyAnimationListener != null) sendMsgBusyAnimation.isRunningProperty().removeListener(sendMsgBusyAnimationListener); @@ -448,7 +448,7 @@ public class ChatView extends AnchorPane { copyIcon.setOnMouseClicked(null); messageLabel.setOnMouseClicked(null); - setGraphic(null); + UserThread.execute(() -> setGraphic(null)); } }