mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-23 03:59:36 +00:00
synchronize chat messages to avoid concurrency exception
This commit is contained in:
parent
dc015ad83d
commit
548cae004d
1 changed files with 19 additions and 9 deletions
|
@ -1210,20 +1210,24 @@ public abstract class Trade implements Tradable, Model {
|
|||
}
|
||||
|
||||
public void addAndPersistChatMessage(ChatMessage chatMessage) {
|
||||
synchronized (chatMessages) {
|
||||
if (!chatMessages.contains(chatMessage)) {
|
||||
chatMessages.add(chatMessage);
|
||||
} else {
|
||||
log.error("Trade ChatMessage already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeAllChatMessages() {
|
||||
synchronized (chatMessages) {
|
||||
if (chatMessages.size() > 0) {
|
||||
chatMessages.clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mediationResultAppliedPenaltyToSeller() {
|
||||
// If mediated payout is same or more then normal payout we enable otherwise a penalty was applied
|
||||
|
@ -1646,6 +1650,12 @@ 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;
|
||||
|
@ -2296,7 +2306,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
.setPayoutState(Trade.PayoutState.toProtoMessage(payoutState))
|
||||
.setDisputeState(Trade.DisputeState.toProtoMessage(disputeState))
|
||||
.setPeriodState(Trade.TradePeriodState.toProtoMessage(periodState))
|
||||
.addAllChatMessage(chatMessages.stream()
|
||||
.addAllChatMessage(getChatMessages().stream()
|
||||
.map(msg -> msg.toProtoNetworkEnvelope().getChatMessage())
|
||||
.collect(Collectors.toList()))
|
||||
.setLockTime(lockTime)
|
||||
|
|
Loading…
Reference in a new issue