Fix bug with all mobile notifications for disputes are sent at startup.

This commit is contained in:
chimp1984 2020-09-03 23:50:28 -05:00 committed by Christoph Atteneder
parent 2400014db6
commit 3e933c31a5
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
3 changed files with 27 additions and 34 deletions

View File

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

View File

@ -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 +

View File

@ -231,7 +231,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> 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();