Skip to content

Commit

Permalink
Merge pull request #4475 from chimp1984/fix-mobile-notification-bug
Browse files Browse the repository at this point in the history
Fix bug with all mobile notifications for disputes are sent at startup.
  • Loading branch information
ripcurlx authored Sep 4, 2020
2 parents d33b401 + 6d37bed commit 57bed13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ public void onAllServicesInitialized() {
}
});
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<ChatMessage>) c -> {
log.debug("We got a ChatMessage added. id={}, tradeId={}", dispute.getId(), dispute.getTradeId());
Expand All @@ -85,31 +95,24 @@ private void setDisputeListener(Dispute dispute) {
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
Expand All @@ -122,12 +125,4 @@ private void onChatMessage(ChatMessage chatMessage, Dispute dispute) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,17 @@ private void notifyChangeListener() {
@Override
public String toString() {
return "ChatMessage{" +
"\n type='" + supportType + '\'' +
",\n tradeId='" + tradeId + '\'' +
"\n tradeId='" + tradeId + '\'' +
",\n traderId=" + traderId +
",\n senderIsTrader=" + senderIsTrader +
",\n message='" + message + '\'' +
",\n attachments=" + attachments +
",\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 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void activate() {
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();
Expand Down

0 comments on commit 57bed13

Please sign in to comment.