mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 14:42:37 +01:00
Add wasDisplayed field to chatMsg
- Fix logger - Manage display state off trade chat msg (wip)
This commit is contained in:
parent
855cb4f620
commit
e0c1a85406
6 changed files with 108 additions and 71 deletions
|
@ -301,6 +301,7 @@ message DisputeCommunicationMessage {
|
|||
bool acknowledged = 13;
|
||||
string ack_error = 14;
|
||||
Type type = 15;
|
||||
bool was_displayed = 16;
|
||||
}
|
||||
|
||||
message DisputeResultMessage {
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
public class DisputeChatSession extends ChatSession {
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeManager.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeChatSession.class);
|
||||
|
||||
private Dispute dispute;
|
||||
private DisputeManager disputeManager;
|
||||
|
|
|
@ -92,6 +92,10 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
@Setter
|
||||
private boolean isSystemMessage;
|
||||
|
||||
// Added in v1.1.6.
|
||||
@Setter
|
||||
private boolean wasDisplayed;
|
||||
|
||||
private final BooleanProperty arrivedProperty;
|
||||
private final BooleanProperty storedInMailboxProperty;
|
||||
private final BooleanProperty acknowledgedProperty;
|
||||
|
@ -120,7 +124,8 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
Version.getP2PMessageVersion(),
|
||||
false,
|
||||
null,
|
||||
null);
|
||||
null,
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,13 +147,15 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
int messageVersion,
|
||||
boolean acknowledged,
|
||||
@Nullable String sendMessageError,
|
||||
@Nullable String ackError) {
|
||||
@Nullable String ackError,
|
||||
boolean wasDisplayed) {
|
||||
super(messageVersion, uid);
|
||||
this.type = type;
|
||||
this.tradeId = tradeId;
|
||||
this.traderId = traderId;
|
||||
this.senderIsTrader = senderIsTrader;
|
||||
this.message = message;
|
||||
this.wasDisplayed = wasDisplayed;
|
||||
Optional.ofNullable(attachments).ifPresent(e -> addAllAttachments(attachments));
|
||||
this.senderNodeAddress = senderNodeAddress;
|
||||
this.date = date;
|
||||
|
@ -203,7 +210,8 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
messageVersion,
|
||||
proto.getAcknowledged(),
|
||||
proto.getSendMessageError().isEmpty() ? null : proto.getSendMessageError(),
|
||||
proto.getAckError().isEmpty() ? null : proto.getAckError());
|
||||
proto.getAckError().isEmpty() ? null : proto.getAckError(),
|
||||
proto.getWasDisplayed());
|
||||
disputeCommunicationMessage.setSystemMessage(proto.getIsSystemMessage());
|
||||
return disputeCommunicationMessage;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package bisq.core.chat;
|
||||
|
||||
import bisq.core.arbitration.DisputeManager;
|
||||
import bisq.core.arbitration.messages.DisputeCommunicationMessage;
|
||||
import bisq.core.arbitration.messages.DisputeMessage;
|
||||
import bisq.core.btc.setup.WalletsSetup;
|
||||
|
@ -47,7 +46,7 @@ import lombok.Setter;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
public class ChatManager {
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeManager.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(ChatManager.class);
|
||||
|
||||
@Getter
|
||||
private final P2PService p2PService;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package bisq.core.trade;
|
||||
|
||||
import bisq.core.arbitration.DisputeManager;
|
||||
import bisq.core.arbitration.messages.DisputeCommunicationMessage;
|
||||
import bisq.core.arbitration.messages.DisputeMessage;
|
||||
import bisq.core.chat.ChatManager;
|
||||
|
@ -40,7 +39,7 @@ import org.slf4j.LoggerFactory;
|
|||
* sessions. This is only to make it easier to understand who's who, there is no real
|
||||
* server/client relationship */
|
||||
public class TradeChatSession extends ChatSession {
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeManager.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TradeChatSession.class);
|
||||
|
||||
private Trade trade;
|
||||
private boolean isClient;
|
||||
|
@ -159,11 +158,12 @@ public class TradeChatSession extends ChatSession {
|
|||
Optional<Trade> tradeOptional = tradeManager.getTradeById(message.getTradeId());
|
||||
if (tradeOptional.isPresent()) {
|
||||
if (tradeOptional.get().getCommunicationMessages().stream()
|
||||
.noneMatch(m -> m.getUid().equals(message.getUid())))
|
||||
.noneMatch(m -> m.getUid().equals(message.getUid()))) {
|
||||
tradeOptional.get().addCommunicationMessage(message);
|
||||
else
|
||||
} else {
|
||||
log.warn("Trade got a disputeCommunicationMessage what we have already stored. UId = {} TradeId = {}",
|
||||
message.getUid(), message.getTradeId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,11 +77,14 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
|
|||
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.transformation.SortedList;
|
||||
|
||||
import javafx.util.Callback;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@FxmlView
|
||||
public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTradesViewModel> {
|
||||
|
@ -103,6 +106,8 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
private Subscription selectedTableItemSubscription;
|
||||
private Subscription selectedItemSubscription;
|
||||
private Stage chatPopupStage;
|
||||
private ListChangeListener<PendingTradesListItem> tradesListChangeListener;
|
||||
private Map<String, Long> newChatMessagesByTradeMap = new HashMap<>();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -199,6 +204,8 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
.show();
|
||||
}
|
||||
};
|
||||
|
||||
tradesListChangeListener = c -> updateNewChatMessagesByTradeMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -260,6 +267,9 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
});
|
||||
|
||||
updateTableSelection();
|
||||
|
||||
model.dataModel.list.addListener(tradesListChangeListener);
|
||||
updateNewChatMessagesByTradeMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -270,6 +280,8 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
|
||||
removeSelectedSubView();
|
||||
|
||||
model.dataModel.list.removeListener(tradesListChangeListener);
|
||||
|
||||
if (scene != null)
|
||||
scene.removeEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
|
||||
}
|
||||
|
@ -282,6 +294,84 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Chat
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void updateNewChatMessagesByTradeMap() {
|
||||
model.dataModel.list.forEach(t -> {
|
||||
Trade trade = t.getTrade();
|
||||
newChatMessagesByTradeMap.put(trade.getId(),
|
||||
trade.getCommunicationMessages().stream().filter(m -> !m.isWasDisplayed()).count());
|
||||
});
|
||||
|
||||
log.error(newChatMessagesByTradeMap.toString());
|
||||
}
|
||||
|
||||
private void openChat(Trade trade) {
|
||||
if (chatPopupStage != null)
|
||||
chatPopupStage.close();
|
||||
|
||||
Chat tradeChat = new Chat(model.dataModel.tradeManager.getChatManager(), formatter);
|
||||
tradeChat.setAllowAttachments(false);
|
||||
tradeChat.setDisplayHeader(false);
|
||||
tradeChat.initialize();
|
||||
|
||||
trade.getCommunicationMessages().forEach(m -> m.setWasDisplayed(true));
|
||||
trade.persist();
|
||||
|
||||
AnchorPane pane = new AnchorPane(tradeChat);
|
||||
pane.setPrefSize(600, 400);
|
||||
AnchorPane.setLeftAnchor(tradeChat, 10d);
|
||||
AnchorPane.setRightAnchor(tradeChat, 10d);
|
||||
AnchorPane.setTopAnchor(tradeChat, -20d);
|
||||
AnchorPane.setBottomAnchor(tradeChat, 10d);
|
||||
|
||||
boolean isTaker = !model.dataModel.isMaker(trade.getOffer());
|
||||
boolean isBuyer = model.dataModel.isBuyer();
|
||||
tradeChat.display(new TradeChatSession(trade, isTaker, isBuyer,
|
||||
model.dataModel.tradeManager,
|
||||
model.dataModel.tradeManager.getChatManager()),
|
||||
null,
|
||||
pane.widthProperty());
|
||||
|
||||
tradeChat.activate();
|
||||
tradeChat.scrollToBottom();
|
||||
|
||||
chatPopupStage = new Stage();
|
||||
chatPopupStage.setTitle(Res.get("portfolio.pending.chatWindowTitle", trade.getShortId()));
|
||||
StackPane owner = MainView.getRootContainer();
|
||||
Scene rootScene = owner.getScene();
|
||||
chatPopupStage.initOwner(rootScene.getWindow());
|
||||
chatPopupStage.initModality(Modality.NONE);
|
||||
chatPopupStage.initStyle(StageStyle.DECORATED);
|
||||
chatPopupStage.setOnHiding(event -> tradeChat.deactivate());
|
||||
|
||||
Scene scene = new Scene(pane);
|
||||
scene.getStylesheets().setAll("/bisq/desktop/theme-light.css",
|
||||
"/bisq/desktop/bisq.css",
|
||||
"/bisq/desktop/images.css");
|
||||
scene.addEventHandler(KeyEvent.KEY_RELEASED, ev -> {
|
||||
if (ev.getCode() == KeyCode.ESCAPE) {
|
||||
ev.consume();
|
||||
chatPopupStage.hide();
|
||||
}
|
||||
});
|
||||
chatPopupStage.setScene(scene);
|
||||
|
||||
chatPopupStage.setOpacity(0);
|
||||
chatPopupStage.show();
|
||||
|
||||
Window rootSceneWindow = rootScene.getWindow();
|
||||
double titleBarHeight = rootSceneWindow.getHeight() - rootScene.getHeight();
|
||||
chatPopupStage.setX(Math.round(rootSceneWindow.getX() + (owner.getWidth() - chatPopupStage.getWidth() / 4 * 3)));
|
||||
chatPopupStage.setY(Math.round(rootSceneWindow.getY() + titleBarHeight + (owner.getHeight() - chatPopupStage.getHeight() / 4 * 3)));
|
||||
|
||||
// Delay display to next render frame to avoid that the popup is first quickly displayed in default position
|
||||
// and after a short moment in the correct position
|
||||
UserThread.execute(() -> chatPopupStage.setOpacity(1));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
|
@ -561,66 +651,5 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
});
|
||||
return chatColumn;
|
||||
}
|
||||
|
||||
private void openChat(Trade trade) {
|
||||
if (chatPopupStage != null)
|
||||
chatPopupStage.close();
|
||||
|
||||
Chat tradeChat = new Chat(model.dataModel.tradeManager.getChatManager(), formatter);
|
||||
tradeChat.setAllowAttachments(false);
|
||||
tradeChat.setDisplayHeader(false);
|
||||
tradeChat.initialize();
|
||||
|
||||
AnchorPane pane = new AnchorPane(tradeChat);
|
||||
pane.setPrefSize(600, 400);
|
||||
AnchorPane.setLeftAnchor(tradeChat, 10d);
|
||||
AnchorPane.setRightAnchor(tradeChat, 10d);
|
||||
AnchorPane.setTopAnchor(tradeChat, -20d);
|
||||
AnchorPane.setBottomAnchor(tradeChat, 10d);
|
||||
|
||||
boolean isTaker = !model.dataModel.isMaker(trade.getOffer());
|
||||
boolean isBuyer = model.dataModel.isBuyer();
|
||||
tradeChat.display(new TradeChatSession(trade, isTaker, isBuyer,
|
||||
model.dataModel.tradeManager,
|
||||
model.dataModel.tradeManager.getChatManager()),
|
||||
null,
|
||||
pane.widthProperty());
|
||||
|
||||
tradeChat.activate();
|
||||
tradeChat.scrollToBottom();
|
||||
|
||||
chatPopupStage = new Stage();
|
||||
chatPopupStage.setTitle(Res.get("portfolio.pending.chatWindowTitle", trade.getShortId()));
|
||||
StackPane owner = MainView.getRootContainer();
|
||||
Scene rootScene = owner.getScene();
|
||||
chatPopupStage.initOwner(rootScene.getWindow());
|
||||
chatPopupStage.initModality(Modality.NONE);
|
||||
chatPopupStage.initStyle(StageStyle.DECORATED);
|
||||
chatPopupStage.setOnHiding(event -> tradeChat.deactivate());
|
||||
|
||||
Scene scene = new Scene(pane);
|
||||
scene.getStylesheets().setAll(
|
||||
"/bisq/desktop/bisq.css",
|
||||
"/bisq/desktop/images.css");
|
||||
scene.addEventHandler(KeyEvent.KEY_RELEASED, ev -> {
|
||||
if (ev.getCode() == KeyCode.ESCAPE) {
|
||||
ev.consume();
|
||||
chatPopupStage.hide();
|
||||
}
|
||||
});
|
||||
chatPopupStage.setScene(scene);
|
||||
|
||||
chatPopupStage.setOpacity(0);
|
||||
chatPopupStage.show();
|
||||
|
||||
Window rootSceneWindow = rootScene.getWindow();
|
||||
double titleBarHeight = rootSceneWindow.getHeight() - rootScene.getHeight();
|
||||
chatPopupStage.setX(Math.round(rootSceneWindow.getX() + (owner.getWidth() - chatPopupStage.getWidth() / 4 * 3)));
|
||||
chatPopupStage.setY(Math.round(rootSceneWindow.getY() + titleBarHeight + (owner.getHeight() - chatPopupStage.getHeight() / 4 * 3)));
|
||||
|
||||
// Delay display to next render frame to avoid that the popup is first quickly displayed in default position
|
||||
// and after a short moment in the correct position
|
||||
UserThread.execute(() -> chatPopupStage.setOpacity(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue