Skip to content

Commit

Permalink
Merge pull request #3653 from lusarz/refactor-send-private-notification
Browse files Browse the repository at this point in the history
Remove redundant interfaces from SendPrivateNotificationWindow
  • Loading branch information
ripcurlx authored Nov 22, 2019
2 parents 90bf138 + e23ad9e commit 8ffc4b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,12 @@ private void addContent() {
doClose();
UserThread.runAfter(() -> {
//TODO only taker could send msg as maker would use its own key from offer....
PubKeyRing pubKeyRing = offer.getPubKeyRing();
new SendPrivateNotificationWindow(pubKeyRing, offer.getMakerNodeAddress(), useDevPrivilegeKeys)
.onAddAlertMessage(privateNotificationManager::sendPrivateNotificationMessageIfKeyIsValid)
.show();
new SendPrivateNotificationWindow(
privateNotificationManager,
offer.getPubKeyRing(),
offer.getMakerNodeAddress(),
useDevPrivilegeKeys
).show();
}, 100, TimeUnit.MILLISECONDS);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.main.overlays.popups.Popup;

import bisq.core.alert.PrivateNotificationManager;
import bisq.core.alert.PrivateNotificationPayload;
import bisq.core.locale.Res;

Expand Down Expand Up @@ -51,29 +52,13 @@
public class SendPrivateNotificationWindow extends Overlay<SendPrivateNotificationWindow> {
private static final Logger log = LoggerFactory.getLogger(SendPrivateNotificationWindow.class);

private final PrivateNotificationManager privateNotificationManager;
private final PubKeyRing pubKeyRing;
private final NodeAddress nodeAddress;
private final boolean useDevPrivilegeKeys;
private SendPrivateNotificationHandler sendPrivateNotificationHandler;


///////////////////////////////////////////////////////////////////////////////////////////
// Interface
///////////////////////////////////////////////////////////////////////////////////////////

public interface SendPrivateNotificationHandler {
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
boolean handle(PrivateNotificationPayload privateNotification, PubKeyRing pubKeyRing,
NodeAddress nodeAddress, String privKey, SendMailboxMessageListener sendMailboxMessageListener);
}


///////////////////////////////////////////////////////////////////////////////////////////
// Public API
///////////////////////////////////////////////////////////////////////////////////////////


public SendPrivateNotificationWindow(PubKeyRing pubKeyRing, NodeAddress nodeAddress, boolean useDevPrivilegeKeys) {
public SendPrivateNotificationWindow(PrivateNotificationManager privateNotificationManager, PubKeyRing pubKeyRing, NodeAddress nodeAddress, boolean useDevPrivilegeKeys) {
this.privateNotificationManager = privateNotificationManager;
this.pubKeyRing = pubKeyRing;
this.nodeAddress = nodeAddress;
this.useDevPrivilegeKeys = useDevPrivilegeKeys;
Expand All @@ -92,16 +77,6 @@ public void show() {
display();
}

public SendPrivateNotificationWindow onAddAlertMessage(SendPrivateNotificationHandler sendPrivateNotificationHandler) {
this.sendPrivateNotificationHandler = sendPrivateNotificationHandler;
return this;
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////

@Override
protected void setupKeyHandler(Scene scene) {
if (!hideCloseButton) {
Expand All @@ -115,8 +90,7 @@ protected void setupKeyHandler(Scene scene) {
}

private void addContent() {
InputTextField keyInputTextField = addInputTextField(gridPane, ++rowIndex,
Res.get("shared.unlock"), 10);
InputTextField keyInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("shared.unlock"), 10);
if (useDevPrivilegeKeys)
keyInputTextField.setText(DevEnv.DEV_PRIVILEGE_PRIV_KEY);

Expand All @@ -131,7 +105,7 @@ private void addContent() {
sendButton.setOnAction(e -> {
if (alertMessageTextArea.getText().length() > 0 && keyInputTextField.getText().length() > 0) {
PrivateNotificationPayload privateNotification = new PrivateNotificationPayload(alertMessageTextArea.getText());
if (!sendPrivateNotificationHandler.handle(
if (!privateNotificationManager.sendPrivateNotificationMessageIfKeyIsValid(
privateNotification,
pubKeyRing,
nodeAddress,
Expand Down Expand Up @@ -177,6 +151,4 @@ public void onFault(String errorMessage) {
gridPane.getChildren().add(hBox);
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,12 @@ public void initialize() {
else
nodeAddress = selectedDispute.getContract().getSellerNodeAddress();

new SendPrivateNotificationWindow(pubKeyRing, nodeAddress, useDevPrivilegeKeys)
.onAddAlertMessage(privateNotificationManager::sendPrivateNotificationMessageIfKeyIsValid)
.show();
new SendPrivateNotificationWindow(
privateNotificationManager,
pubKeyRing,
nodeAddress,
useDevPrivilegeKeys
).show();
}
} else {
handleKeyPressed(event);
Expand Down

0 comments on commit 8ffc4b0

Please sign in to comment.