From 3e933c31a5be225fc242eb3b38046dcfdda43db7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 3 Sep 2020 23:50:28 -0500 Subject: [PATCH] Fix bug with all mobile notifications for disputes are sent at startup. --- .../alerts/DisputeMsgEvents.java | 53 +++++++++---------- .../core/support/messages/ChatMessage.java | 6 +-- .../main/offer/MutableOfferViewModel.java | 2 +- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java b/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java index 1c2b9390ff..f6c4d97e9d 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java +++ b/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java @@ -73,10 +73,20 @@ public class DisputeMsgEvents { } }); mediationManager.getDisputesAsObservableList().forEach(this::setDisputeListener); + + // We do not need a handling for unread messages as mailbox messages arrive later and will trigger the + // event listeners. But the existing messages are not causing a notification. + } + + public static MobileMessage getTestMsg() { + String shortId = UUID.randomUUID().toString().substring(0, 8); + return new MobileMessage(Res.get("account.notifications.dispute.message.title"), + Res.get("account.notifications.dispute.message.msg", shortId), + shortId, + MobileMessageType.DISPUTE); } private void setDisputeListener(Dispute dispute) { - //TODO use weak ref or remove listener log.debug("We got a dispute added. id={}, tradeId={}", dispute.getId(), dispute.getTradeId()); dispute.getChatMessages().addListener((ListChangeListener) c -> { log.debug("We got a ChatMessage added. id={}, tradeId={}", dispute.getId(), dispute.getTradeId()); @@ -85,31 +95,24 @@ public class DisputeMsgEvents { c.getAddedSubList().forEach(chatMessage -> onChatMessage(chatMessage, dispute)); } }); - - //TODO test - if (!dispute.getChatMessages().isEmpty()) - onChatMessage(dispute.getChatMessages().get(0), dispute); } private void onChatMessage(ChatMessage chatMessage, Dispute dispute) { - // TODO we need to prevent to send msg for old dispute messages again at restart - // Maybe we need a new property in ChatMessage - // As key is not set in initial iterations it seems we don't need an extra handling. - // the mailbox msg is set a bit later so that triggers a notification, but not the old messages. + if (chatMessage.getSenderNodeAddress().equals(p2PService.getAddress())) { + return; + } // We only send msg in case we are not the sender - if (!chatMessage.getSenderNodeAddress().equals(p2PService.getAddress())) { - String shortId = chatMessage.getShortId(); - MobileMessage message = new MobileMessage(Res.get("account.notifications.dispute.message.title"), - Res.get("account.notifications.dispute.message.msg", shortId), - shortId, - MobileMessageType.DISPUTE); - try { - mobileNotificationService.sendMessage(message); - } catch (Exception e) { - log.error(e.toString()); - e.printStackTrace(); - } + String shortId = chatMessage.getShortId(); + MobileMessage message = new MobileMessage(Res.get("account.notifications.dispute.message.title"), + Res.get("account.notifications.dispute.message.msg", shortId), + shortId, + MobileMessageType.DISPUTE); + try { + mobileNotificationService.sendMessage(message); + } catch (Exception e) { + log.error(e.toString()); + e.printStackTrace(); } // We check at every new message if it might be a message sent after the dispute had been closed. If that is the @@ -122,12 +125,4 @@ public class DisputeMsgEvents { dispute.setIsClosed(false); } } - - public static MobileMessage getTestMsg() { - String shortId = UUID.randomUUID().toString().substring(0, 8); - return new MobileMessage(Res.get("account.notifications.dispute.message.title"), - Res.get("account.notifications.dispute.message.msg", shortId), - shortId, - MobileMessageType.DISPUTE); - } } diff --git a/core/src/main/java/bisq/core/support/messages/ChatMessage.java b/core/src/main/java/bisq/core/support/messages/ChatMessage.java index 3b38c8a244..a4e328ec39 100644 --- a/core/src/main/java/bisq/core/support/messages/ChatMessage.java +++ b/core/src/main/java/bisq/core/support/messages/ChatMessage.java @@ -351,8 +351,7 @@ public final class ChatMessage extends SupportMessage { @Override public String toString() { return "ChatMessage{" + - "\n type='" + supportType + '\'' + - ",\n tradeId='" + tradeId + '\'' + + "\n tradeId='" + tradeId + '\'' + ",\n traderId=" + traderId + ",\n senderIsTrader=" + senderIsTrader + ",\n message='" + message + '\'' + @@ -360,10 +359,9 @@ public final class ChatMessage extends SupportMessage { ",\n senderNodeAddress=" + senderNodeAddress + ",\n date=" + date + ",\n isSystemMessage=" + isSystemMessage + + ",\n wasDisplayed=" + wasDisplayed + ",\n arrivedProperty=" + arrivedProperty + ",\n storedInMailboxProperty=" + storedInMailboxProperty + - ",\n ChatMessage.uid='" + uid + '\'' + - ",\n messageVersion=" + messageVersion + ",\n acknowledgedProperty=" + acknowledgedProperty + ",\n sendMessageErrorProperty=" + sendMessageErrorProperty + ",\n ackErrorProperty=" + ackErrorProperty + diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index 55b9e75d5d..989d063b25 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -231,7 +231,7 @@ public abstract class MutableOfferViewModel ext if (DevEnv.isDevMode()) { UserThread.runAfter(() -> { amount.set("0.001"); - price.set("0.0001"); // for BSQ + price.set("0.008"); minAmount.set(amount.get()); onFocusOutPriceAsPercentageTextField(true, false); applyMakerFee();