Skip to content

Commit

Permalink
Merge pull request #5175 from jmacxx/fix_NPE_trader_chat
Browse files Browse the repository at this point in the history
Fix NPE in trader chat
  • Loading branch information
ripcurlx authored Feb 12, 2021
2 parents 8bcd32f + ed78d0f commit de57900
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
6 changes: 5 additions & 1 deletion core/src/main/java/bisq/core/support/SupportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -191,7 +192,10 @@ private void onAckMessage(AckMessage ackMessage) {
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());

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/support/SupportSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean isClient() {

public abstract String getTradeId();

public abstract PubKeyRing getClientPubKeyRing();
public abstract int getClientId();

public abstract ObservableList<ChatMessage> getObservableChatMessageList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ public String getTradeId() {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public String getTradeId() {
}

@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
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ private ChatMessage sendDisputeDirectMessage(String text, ArrayList<Attachment>
ChatMessage message = new ChatMessage(
supportManager.getSupportType(),
supportSession.getTradeId(),
supportSession.getClientPubKeyRing().hashCode(),
supportSession.getClientId(),
supportSession.isClient(),
text,
supportManager.getMyAddress(),
Expand Down

0 comments on commit de57900

Please sign in to comment.