Merge pull request #5175 from jmacxx/fix_NPE_trader_chat

Fix NPE in trader chat
This commit is contained in:
Christoph Atteneder 2021-02-12 11:35:44 +01:00 committed by GitHub
commit de57900765
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 9 deletions

View File

@ -18,6 +18,7 @@
package bisq.core.support;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.locale.Res;
import bisq.core.support.messages.ChatMessage;
import bisq.core.support.messages.SupportMessage;
@ -191,7 +192,10 @@ public abstract class SupportManager {
public ChatMessage sendChatMessage(ChatMessage message) {
NodeAddress peersNodeAddress = getPeerNodeAddress(message);
PubKeyRing receiverPubKeyRing = getPeerPubKeyRing(message);
if (receiverPubKeyRing != null) {
if (peersNodeAddress == null || receiverPubKeyRing == null) {
UserThread.runAfter(() ->
message.setSendMessageError(Res.get("support.receiverNotKnown")), 1);
} else {
log.info("Send {} to peer {}. tradeId={}, uid={}",
message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid());

View File

@ -46,7 +46,7 @@ public abstract class SupportSession {
public abstract String getTradeId();
public abstract PubKeyRing getClientPubKeyRing();
public abstract int getClientId();
public abstract ObservableList<ChatMessage> getObservableChatMessageList();

View File

@ -57,9 +57,14 @@ public abstract class DisputeSession extends SupportSession {
}
@Override
public PubKeyRing getClientPubKeyRing() {
public int getClientId() {
// Get pubKeyRing of trader. Arbitrator is considered server for the chat session
return dispute != null ? dispute.getTraderPubKeyRing() : null;
try {
return dispute.getTraderPubKeyRing().hashCode();
} catch (NullPointerException e) {
log.warn("Unable to get traderPubKeyRing from Dispute - {}", e.toString());
}
return 0;
}
@Override

View File

@ -48,12 +48,15 @@ public class TradeChatSession extends SupportSession {
}
@Override
public PubKeyRing getClientPubKeyRing() {
public int getClientId() {
// TODO remove that client-server concept for trade chat
// Get pubKeyRing of taker. Maker is considered server for chat sessions
if (trade != null && trade.getContract() != null)
return trade.getContract().getTakerPubKeyRing();
return null;
try {
return trade.getContract().getTakerPubKeyRing().hashCode();
} catch (NullPointerException e) {
log.warn("Unable to get takerPubKeyRing from Trade Contract - {}", e.toString());
}
return 0;
}
@Override

View File

@ -1105,6 +1105,7 @@ support.noTickets=There are no open tickets
support.sendingMessage=Sending Message...
support.receiverNotOnline=Receiver is not online. Message is saved to their mailbox.
support.sendMessageError=Sending message failed. Error: {0}
support.receiverNotKnown=Receiver not known
support.wrongVersion=The offer in that dispute has been created with an older version of Bisq.\n\
You cannot close that dispute with your version of the application.\n\n\
Please use an older version with protocol version {0}

View File

@ -648,7 +648,7 @@ public class ChatView extends AnchorPane {
ChatMessage message = new ChatMessage(
supportManager.getSupportType(),
supportSession.getTradeId(),
supportSession.getClientPubKeyRing().hashCode(),
supportSession.getClientId(),
supportSession.isClient(),
text,
supportManager.getMyAddress(),