mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Remove priv notif. after mailbox msg displayed
This commit is contained in:
parent
3e2f09b4a1
commit
ba41930abe
6 changed files with 86 additions and 87 deletions
|
@ -22,6 +22,7 @@ import io.bitsquare.common.crypto.KeyRing;
|
|||
import io.bitsquare.crypto.DecryptedMsgWithPubKey;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
|
@ -46,6 +47,7 @@ public class PrivateNotificationManager {
|
|||
// Pub key for developer global privateNotification message
|
||||
private static final String pubKeyAsHex = "02ba7c5de295adfe57b60029f3637a2c6b1d0e969a8aaefb9e0ddc3a7963f26925";
|
||||
private ECKey privateNotificationSigningKey;
|
||||
private DecryptedMsgWithPubKey decryptedMsgWithPubKey;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -62,6 +64,7 @@ public class PrivateNotificationManager {
|
|||
}
|
||||
|
||||
private void handleMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, NodeAddress senderNodeAddress) {
|
||||
this.decryptedMsgWithPubKey = decryptedMsgWithPubKey;
|
||||
Message message = decryptedMsgWithPubKey.message;
|
||||
if (message instanceof PrivateNotificationMessage) {
|
||||
PrivateNotificationMessage privateNotificationMessage = (PrivateNotificationMessage) message;
|
||||
|
@ -85,33 +88,20 @@ public class PrivateNotificationManager {
|
|||
return privateNotificationMessageProperty;
|
||||
}
|
||||
|
||||
public boolean sendPrivateNotificationMessageIfKeyIsValid(PrivateNotification privateNotification, Offer offer, String privKeyString) {
|
||||
// if there is a previous message we remove that first
|
||||
// if (user.getDevelopersPrivateNotification() != null)
|
||||
// removePrivateNotificationMessageIfKeyIsValid(privKeyString);
|
||||
|
||||
public boolean sendPrivateNotificationMessageIfKeyIsValid(PrivateNotification privateNotification, Offer offer,
|
||||
String privKeyString, SendMailboxMessageListener sendMailboxMessageListener) {
|
||||
boolean isKeyValid = isKeyValid(privKeyString);
|
||||
if (isKeyValid) {
|
||||
signAndAddSignatureToPrivateNotificationMessage(privateNotification);
|
||||
// user.setDevelopersPrivateNotification(privateNotification);
|
||||
privateNotificationService.sendPrivateNotificationMessage(privateNotification, offer, null, null);
|
||||
privateNotificationService.sendPrivateNotificationMessage(privateNotification, offer, sendMailboxMessageListener);
|
||||
}
|
||||
|
||||
return isKeyValid;
|
||||
}
|
||||
|
||||
public boolean removePrivateNotificationMessageIfKeyIsValid(String privKeyString) {
|
||||
/* PrivateNotification developersPrivateNotification = user.getDevelopersPrivateNotification();
|
||||
if (isKeyValid(privKeyString) && developersPrivateNotification != null) {
|
||||
privateNotificationService.removePrivateNotificationMessage(developersPrivateNotification, null, null);
|
||||
user.setDevelopersPrivateNotification(null);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}*/
|
||||
return false;
|
||||
public void removePrivateNotification(PrivateNotification privateNotification) {
|
||||
privateNotificationService.removePrivateNotification(decryptedMsgWithPubKey);
|
||||
}
|
||||
|
||||
private boolean isKeyValid(String privKeyString) {
|
||||
try {
|
||||
privateNotificationSigningKey = ECKey.fromPrivate(new BigInteger(1, HEX.decode(privKeyString)));
|
||||
|
@ -137,4 +127,6 @@ public class PrivateNotificationManager {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,14 +17,12 @@
|
|||
|
||||
package io.bitsquare.alert;
|
||||
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.crypto.DecryptedMsgWithPubKey;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.p2p.messaging.DecryptedDirectMessageListener;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMailboxListener;
|
||||
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -57,32 +55,14 @@ public class PrivateNotificationService {
|
|||
}
|
||||
|
||||
|
||||
public void sendPrivateNotificationMessage(PrivateNotification privateNotification, Offer offer, @Nullable ResultHandler resultHandler, @Nullable ErrorMessageHandler errorMessageHandler) {
|
||||
public void sendPrivateNotificationMessage(PrivateNotification privateNotification, Offer offer, SendMailboxMessageListener sendMailboxMessageListener) {
|
||||
p2PService.sendEncryptedMailboxMessage(offer.getOffererNodeAddress(),
|
||||
offer.getPubKeyRing(),
|
||||
new PrivateNotificationMessage(privateNotification, p2PService.getNetworkNode().getNodeAddress()),
|
||||
new SendMailboxMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
log.trace("PrivateNotificationMessage arrived at peer. PrivateNotificationMessage = " + privateNotification);
|
||||
if (resultHandler != null) resultHandler.handleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoredInMailbox() {
|
||||
log.trace("PrivateNotificationMessage was stored in mailbox. PrivateNotificationMessage = " + privateNotification);
|
||||
if (resultHandler != null) resultHandler.handleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault(String errorMessage) {
|
||||
if (errorMessageHandler != null)
|
||||
errorMessageHandler.handleErrorMessage("Add privateNotificationMessage failed");
|
||||
}
|
||||
});
|
||||
sendMailboxMessageListener);
|
||||
}
|
||||
|
||||
public void removePrivateNotificationMessage(PrivateNotification privateNotification, @Nullable ResultHandler resultHandler, @Nullable ErrorMessageHandler errorMessageHandler) {
|
||||
public void removePrivateNotification(DecryptedMsgWithPubKey decryptedMsgWithPubKey) {
|
||||
p2PService.removeEntryFromMailbox(decryptedMsgWithPubKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -872,11 +872,14 @@ public class MainViewModel implements ViewModel {
|
|||
}
|
||||
|
||||
private void displayPrivateNotification(PrivateNotification privateNotification) {
|
||||
new Popup<>().headLine("Important notification from Bitsquare developers!")
|
||||
.information(privateNotification.message)
|
||||
new Popup<>().headLine("Important private notification!")
|
||||
.attention(privateNotification.message)
|
||||
.setHeadlineStyle("-fx-text-fill: -bs-error-red; -fx-font-weight: bold; -fx-font-size: 16;")
|
||||
.onClose(() -> privateNotificationManager.removePrivateNotification(privateNotification))
|
||||
.closeButtonText("I understand")
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
private void swapPendingOfferFundingEntries() {
|
||||
tradeManager.getAddressEntriesForAvailableBalanceStream()
|
||||
.filter(addressEntry -> addressEntry.getOfferId() != null)
|
||||
|
|
|
@ -61,6 +61,7 @@ import static io.bitsquare.gui.util.FormBuilder.addCheckBox;
|
|||
public abstract class Overlay<T extends Overlay> {
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Enum
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -134,7 +135,8 @@ public abstract class Overlay<T extends Overlay> {
|
|||
protected Type type = Type.Undefined;
|
||||
protected boolean hideCloseButton;
|
||||
protected boolean useAnimation = true;
|
||||
|
||||
private String headlineStyle;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public API
|
||||
|
@ -350,6 +352,11 @@ public abstract class Overlay<T extends Overlay> {
|
|||
return (T) this;
|
||||
}
|
||||
|
||||
public T setHeadlineStyle(String headlineStyle) {
|
||||
this.headlineStyle = headlineStyle;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Protected
|
||||
|
@ -618,6 +625,10 @@ public abstract class Overlay<T extends Overlay> {
|
|||
|
||||
headLineLabel = new Label(BSResources.get(headLine));
|
||||
headLineLabel.setMouseTransparent(true);
|
||||
|
||||
if (headlineStyle != null)
|
||||
headLineLabel.setStyle(headlineStyle);
|
||||
|
||||
GridPane.setHalignment(headLineLabel, HPos.LEFT);
|
||||
GridPane.setRowIndex(headLineLabel, rowIndex);
|
||||
GridPane.setColumnSpan(headLineLabel, 2);
|
||||
|
|
|
@ -13,14 +13,17 @@ import javafx.animation.KeyValue;
|
|||
import javafx.animation.Timeline;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Camera;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyCodeCombination;
|
||||
import javafx.scene.input.KeyCombination;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.stage.Modality;
|
||||
|
@ -44,6 +47,7 @@ public class PeerInfoWithTagEditor extends Overlay<PeerInfoWithTagEditor> {
|
|||
private ChangeListener<Boolean> focusListener;
|
||||
private PrivateNotificationManager privateNotificationManager;
|
||||
private Offer offer;
|
||||
private EventHandler<KeyEvent> keyEventEventHandler;
|
||||
|
||||
|
||||
public PeerInfoWithTagEditor(PrivateNotificationManager privateNotificationManager, Offer offer) {
|
||||
|
@ -98,6 +102,10 @@ public class PeerInfoWithTagEditor extends Overlay<PeerInfoWithTagEditor> {
|
|||
hide();
|
||||
};
|
||||
stage.focusedProperty().addListener(focusListener);
|
||||
|
||||
Scene scene = stage.getScene();
|
||||
if (scene != null)
|
||||
scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,8 +128,14 @@ public class PeerInfoWithTagEditor extends Overlay<PeerInfoWithTagEditor> {
|
|||
protected void onHidden() {
|
||||
INSTANCE = null;
|
||||
|
||||
if (stage != null && focusListener != null)
|
||||
stage.focusedProperty().removeListener(focusListener);
|
||||
if (stage != null) {
|
||||
if (focusListener != null)
|
||||
stage.focusedProperty().removeListener(focusListener);
|
||||
|
||||
Scene scene = stage.getScene();
|
||||
if (scene != null)
|
||||
scene.removeEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addContent() {
|
||||
|
@ -132,13 +146,14 @@ public class PeerInfoWithTagEditor extends Overlay<PeerInfoWithTagEditor> {
|
|||
String tag = peerTagMap.containsKey(hostName) ? peerTagMap.get(hostName) : "";
|
||||
inputTextField.setText(tag);
|
||||
|
||||
Button button = FormBuilder.addButton(gridPane, ++rowIndex, "Send private message");
|
||||
button.setOnAction(e -> {
|
||||
new SendPrivateNotificationWindow(offer)
|
||||
.onAddAlertMessage(privateNotificationManager::sendPrivateNotificationMessageIfKeyIsValid)
|
||||
.onRemoveAlertMessage(privateNotificationManager::removePrivateNotificationMessageIfKeyIsValid)
|
||||
.show();
|
||||
});
|
||||
keyEventEventHandler = event -> {
|
||||
if (new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN).match(event)) {
|
||||
new SendPrivateNotificationWindow(offer)
|
||||
.onAddAlertMessage(privateNotificationManager::sendPrivateNotificationMessageIfKeyIsValid)
|
||||
.show();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ import io.bitsquare.common.util.Tuple2;
|
|||
import io.bitsquare.gui.components.InputTextField;
|
||||
import io.bitsquare.gui.main.overlays.Overlay;
|
||||
import io.bitsquare.gui.main.overlays.popups.Popup;
|
||||
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
|
@ -41,7 +42,6 @@ public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificati
|
|||
private static final Logger log = LoggerFactory.getLogger(SendPrivateNotificationWindow.class);
|
||||
private Button sendButton;
|
||||
private SendPrivateNotificationHandler sendPrivateNotificationHandler;
|
||||
private RemoveAlertMessageHandler removeAlertMessageHandler;
|
||||
private Offer offer;
|
||||
|
||||
|
||||
|
@ -49,11 +49,7 @@ public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificati
|
|||
// Interface
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
public interface SendPrivateNotificationHandler {
|
||||
boolean handle(PrivateNotification privateNotification, Offer offer, String privKey);
|
||||
}
|
||||
|
||||
public interface RemoveAlertMessageHandler {
|
||||
boolean handle(String privKey);
|
||||
boolean handle(PrivateNotification privateNotification, Offer offer, String privKey, SendMailboxMessageListener sendMailboxMessageListener);
|
||||
}
|
||||
|
||||
|
||||
|
@ -68,9 +64,9 @@ public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificati
|
|||
|
||||
public void show() {
|
||||
if (headLine == null)
|
||||
headLine = "Edit ban list";
|
||||
headLine = "Send private message";
|
||||
|
||||
width = 600;
|
||||
width = 800;
|
||||
createGridPane();
|
||||
addHeadLine();
|
||||
addSeparator();
|
||||
|
@ -84,10 +80,6 @@ public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificati
|
|||
return this;
|
||||
}
|
||||
|
||||
public SendPrivateNotificationWindow onRemoveAlertMessage(RemoveAlertMessageHandler removeAlertMessageHandler) {
|
||||
this.removeAlertMessageHandler = removeAlertMessageHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Protected
|
||||
|
@ -106,31 +98,37 @@ public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificati
|
|||
}
|
||||
|
||||
private void addContent() {
|
||||
InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Ban list private key:", 10).second;
|
||||
Tuple2<Label, TextArea> labelTextAreaTuple2 = addLabelTextArea(gridPane, ++rowIndex, "Private alert message:", "Enter message");
|
||||
InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Key for private notification:", 10).second;
|
||||
Tuple2<Label, TextArea> labelTextAreaTuple2 = addLabelTextArea(gridPane, ++rowIndex, "Private notification:", "Enter notification");
|
||||
TextArea alertMessageTextArea = labelTextAreaTuple2.second;
|
||||
Label first = labelTextAreaTuple2.first;
|
||||
first.setMinWidth(150);
|
||||
first.setMinWidth(200);
|
||||
|
||||
sendButton = new Button("Send private alert message");
|
||||
sendButton = new Button("Send private notification");
|
||||
sendButton.setOnAction(e -> {
|
||||
if (alertMessageTextArea.getText().length() > 0 && keyInputTextField.getText().length() > 0) {
|
||||
if (sendPrivateNotificationHandler.handle(
|
||||
if (!sendPrivateNotificationHandler.handle(
|
||||
new PrivateNotification(alertMessageTextArea.getText()),
|
||||
offer,
|
||||
keyInputTextField.getText()))
|
||||
hide();
|
||||
else
|
||||
new Popup().warning("The key you entered was not correct.").width(300).onClose(() -> blurAgain()).show();
|
||||
}
|
||||
});
|
||||
keyInputTextField.getText(),
|
||||
new SendMailboxMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
log.trace("PrivateNotificationMessage arrived at peer.");
|
||||
new Popup<>().feedback("Message arrived.").onClose(SendPrivateNotificationWindow.this::hide).show();
|
||||
}
|
||||
|
||||
Button removeAlertMessageButton = new Button("Remove notification");
|
||||
removeAlertMessageButton.setOnAction(e -> {
|
||||
if (keyInputTextField.getText().length() > 0) {
|
||||
if (removeAlertMessageHandler.handle(keyInputTextField.getText()))
|
||||
hide();
|
||||
else
|
||||
@Override
|
||||
public void onStoredInMailbox() {
|
||||
log.trace("PrivateNotificationMessage was stored in mailbox.");
|
||||
new Popup<>().feedback("Message stored in mailbox.").onClose(SendPrivateNotificationWindow.this::hide).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault(String errorMessage) {
|
||||
new Popup<>().feedback("Message sending failed. error=" + errorMessage).onClose(SendPrivateNotificationWindow.this::hide).show();
|
||||
}
|
||||
}))
|
||||
new Popup().warning("The key you entered was not correct.").width(300).onClose(() -> blurAgain()).show();
|
||||
}
|
||||
});
|
||||
|
@ -145,7 +143,7 @@ public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificati
|
|||
hBox.setSpacing(10);
|
||||
GridPane.setRowIndex(hBox, ++rowIndex);
|
||||
GridPane.setColumnIndex(hBox, 1);
|
||||
hBox.getChildren().addAll(sendButton, removeAlertMessageButton, closeButton);
|
||||
hBox.getChildren().addAll(sendButton, closeButton);
|
||||
gridPane.getChildren().add(hBox);
|
||||
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue