fix chat message listeners by returning source observable list (#830)

This commit is contained in:
woodser 2024-03-18 10:47:43 -04:00 committed by GitHub
parent 317aa2e72f
commit 3c7841ae28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 13 deletions

View File

@ -394,6 +394,7 @@ public abstract class Trade implements Tradable, Model {
@Setter
@Nullable
private String counterCurrencyTxId;
@Getter
private final ObservableList<ChatMessage> 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<ChatMessage> getChatMessages() {
synchronized (chatMessages) {
return FXCollections.observableArrayList(chatMessages);
}
}
public MessageState getPaymentSentMessageState() {
if (isPaymentReceived()) return MessageState.ACKNOWLEDGED;
if (processModel.getPaymentSentMessageStateProperty().get() == MessageState.ACKNOWLEDGED) return MessageState.ACKNOWLEDGED;

View File

@ -416,11 +416,13 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
private void updateNewChatMessagesByTradeMap() {
model.dataModel.list.forEach(t -> {
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());
}
});
}

View File

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