Move delay for applying mailbox messages inside onInitialized

We need to set addDecryptedDirectMessageListener without
delay as otherwise we could miss direct messages (detected
with localhost testing, with tor its likely slower and
would not have been triggered).
This commit is contained in:
chimp1984 2020-11-19 10:19:48 -05:00
parent d6f4eed39e
commit a4db09fe1d
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -71,22 +71,24 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void initialize(ProcessModelServiceProvider serviceProvider, TradeManager tradeManager, Offer offer) {
processModel.applyTransient(serviceProvider, tradeManager, offer);
// We delay a bit here as the trade gets updated from the wallet to update the trade
// state (deposit confirmed) and that happens after our method is called.
// TODO To fix that in a better way we would need to change the order of some routines
// from the TradeManager, but as we are close to a release I dont want to risk a bigger
// change and leave that for a later PR
UserThread.runAfter(this::onInitialized, 100, TimeUnit.MILLISECONDS);
onInitialized();
}
protected void onInitialized() {
if (!trade.isWithdrawn()) {
processModel.getP2PService().addDecryptedDirectMessageListener(this);
}
processModel.getP2PService().addDecryptedMailboxListener(this);
processModel.getP2PService().getMailBoxMessages()
.forEach(this::handleDecryptedMessageWithPubKey);
// We delay a bit here as the trade gets updated from the wallet to update the trade
// state (deposit confirmed) and that happens after our method is called.
// TODO To fix that in a better way we would need to change the order of some routines
// from the TradeManager, but as we are close to a release I dont want to risk a bigger
// change and leave that for a later PR
UserThread.runAfter(() -> {
processModel.getP2PService().addDecryptedMailboxListener(this);
processModel.getP2PService().getMailBoxMessages()
.forEach(this::handleDecryptedMessageWithPubKey);
}, 100, TimeUnit.MILLISECONDS);
}
public void onWithdrawCompleted() {