Skip to content

Commit

Permalink
Fix bug with not showing system msg at peer who receives msg
Browse files Browse the repository at this point in the history
- We only added the system msg when one opens the chat but not when
one received a message.
  • Loading branch information
chimp1984 committed Aug 30, 2019
1 parent 6e232d8 commit 39e22ca
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@ public DisputeCommunicationMessage(DisputeCommunicationMessage.Type type,
false);
}

public DisputeCommunicationMessage(DisputeCommunicationMessage.Type type,
String tradeId,
int traderId,
boolean senderIsTrader,
String message,
NodeAddress senderNodeAddress,
long date) {
this(type,
tradeId,
traderId,
senderIsTrader,
message,
null,
senderNodeAddress,
date,
false,
false,
UUID.randomUUID().toString(),
Version.getP2PMessageVersion(),
false,
null,
null,
false);
}


///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
Expand Down
27 changes: 24 additions & 3 deletions core/src/main/java/bisq/core/trade/TradeChatSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.core.arbitration.messages.DisputeResultMessage;
import bisq.core.chat.ChatManager;
import bisq.core.chat.ChatSession;
import bisq.core.locale.Res;

import bisq.network.p2p.NodeAddress;

Expand Down Expand Up @@ -181,13 +182,33 @@ public boolean channelOpen(DisputeCommunicationMessage message) {
public void storeDisputeCommunicationMessage(DisputeCommunicationMessage message) {
Optional<Trade> tradeOptional = tradeManager.getTradeById(message.getTradeId());
if (tradeOptional.isPresent()) {
if (tradeOptional.get().getCommunicationMessages().stream()
.noneMatch(m -> m.getUid().equals(message.getUid()))) {
tradeOptional.get().addCommunicationMessage(message);
Trade trade = tradeOptional.get();
ObservableList<DisputeCommunicationMessage> communicationMessages = trade.getCommunicationMessages();
if (communicationMessages.stream().noneMatch(m -> m.getUid().equals(message.getUid()))) {
if (communicationMessages.isEmpty()) {
addSystemMsg(trade);
}
trade.addCommunicationMessage(message);
} else {
log.warn("Trade got a disputeCommunicationMessage what we have already stored. UId = {} TradeId = {}",
message.getUid(), message.getTradeId());
}
}
}

public void addSystemMsg(Trade trade) {
// We need to use the trade date as otherwise our system msg would not be displayed first as the list is sorted
// by date.
DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(
DisputeCommunicationMessage.Type.TRADE,
trade.getId(),
0,
false,
Res.get("tradeChat.rules"),
new NodeAddress("null:0000"),
trade.getDate().getTime()
);
disputeCommunicationMessage.setSystemMessage(true);
trade.getCommunicationMessages().add(disputeCommunicationMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ private void updateNewChatMessagesByTradeMap() {
model.dataModel.list.forEach(t -> {
Trade trade = t.getTrade();
newChatMessagesByTradeMap.put(trade.getId(),
trade.getCommunicationMessages().stream().filter(m -> !m.isWasDisplayed()).count());
trade.getCommunicationMessages().stream()
.filter(m -> !m.isWasDisplayed())
.filter(m -> !m.isSystemMessage())
.count());
});
}

Expand All @@ -326,16 +329,7 @@ private void openChat(Trade trade) {
chatPopupStage.close();

if (trade.getCommunicationMessages().isEmpty()) {
DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(
DisputeCommunicationMessage.Type.TRADE,
trade.getId(),
0,
false,
Res.get("tradeChat.rules"),
new NodeAddress("null:0000")
);
disputeCommunicationMessage.setSystemMessage(true);
trade.getCommunicationMessages().add(disputeCommunicationMessage);
((TradeChatSession) model.dataModel.tradeManager.getChatManager().getChatSession()).addSystemMsg(trade);
}

trade.getCommunicationMessages().forEach(m -> m.setWasDisplayed(true));
Expand Down

0 comments on commit 39e22ca

Please sign in to comment.