diff --git a/core/src/main/java/bisq/core/api/CoreNotificationService.java b/core/src/main/java/bisq/core/api/CoreNotificationService.java index 2fee37fd..fd78663c 100644 --- a/core/src/main/java/bisq/core/api/CoreNotificationService.java +++ b/core/src/main/java/bisq/core/api/CoreNotificationService.java @@ -1,9 +1,10 @@ package bisq.core.api; import bisq.core.api.CoreApi.NotificationListener; - +import bisq.core.api.model.TradeInfo; +import bisq.core.trade.Trade; import bisq.proto.grpc.NotificationMessage; - +import bisq.proto.grpc.NotificationMessage.NotificationType; import javax.inject.Singleton; import java.util.Iterator; @@ -33,10 +34,19 @@ public class CoreNotificationService { try { listener.onMessage(notification); } catch (RuntimeException e) { - log.warn("Failed to send message {} to listener {}", notification, listener, e); + log.warn("Failed to send notification to listener {}: {}", listener, e.getMessage()); iter.remove(); } } } } + + public void sendTradeNotification(Trade trade, String title, String message) { + sendNotification(NotificationMessage.newBuilder() + .setType(NotificationType.TRADE_UPDATE) + .setTrade(TradeInfo.toTradeInfo(trade).toProtoMessage()) + .setTimestamp(System.currentTimeMillis()) + .setTitle(title) + .setMessage(message).build()); + } } diff --git a/core/src/main/java/bisq/core/api/model/ContractInfo.java b/core/src/main/java/bisq/core/api/model/ContractInfo.java index b4041e64..e93fd64c 100644 --- a/core/src/main/java/bisq/core/api/model/ContractInfo.java +++ b/core/src/main/java/bisq/core/api/model/ContractInfo.java @@ -94,8 +94,8 @@ public class ContractInfo implements Payload { proto.getIsBuyerMakerAndSellerTaker(), proto.getMakerAccountId(), proto.getTakerAccountId(), - PaymentAccountPayloadInfo.fromProto(proto.getMakerPaymentAccountPayload()), - PaymentAccountPayloadInfo.fromProto(proto.getTakerPaymentAccountPayload()), + proto.getMakerPaymentAccountPayload() == null ? null : PaymentAccountPayloadInfo.fromProto(proto.getMakerPaymentAccountPayload()), + proto.getTakerPaymentAccountPayload() == null ? null : PaymentAccountPayloadInfo.fromProto(proto.getTakerPaymentAccountPayload()), proto.getMakerPayoutAddressString(), proto.getTakerPayoutAddressString(), proto.getLockTime()); @@ -103,18 +103,18 @@ public class ContractInfo implements Payload { @Override public bisq.proto.grpc.ContractInfo toProtoMessage() { - return bisq.proto.grpc.ContractInfo.newBuilder() + bisq.proto.grpc.ContractInfo.Builder builder = bisq.proto.grpc.ContractInfo.newBuilder() .setBuyerNodeAddress(buyerNodeAddress) .setSellerNodeAddress(sellerNodeAddress) .setArbitratorNodeAddress(arbitratorNodeAddress) .setIsBuyerMakerAndSellerTaker(isBuyerMakerAndSellerTaker) .setMakerAccountId(makerAccountId) .setTakerAccountId(takerAccountId) - .setMakerPaymentAccountPayload(makerPaymentAccountPayload.toProtoMessage()) - .setTakerPaymentAccountPayload(takerPaymentAccountPayload.toProtoMessage()) .setMakerPayoutAddressString(makerPayoutAddressString) .setTakerPayoutAddressString(takerPayoutAddressString) - .setLockTime(lockTime) - .build(); + .setLockTime(lockTime); + if (makerPaymentAccountPayload != null) builder.setMakerPaymentAccountPayload(makerPaymentAccountPayload.toProtoMessage()); + if (takerPaymentAccountPayload != null) builder.setTakerPaymentAccountPayload(takerPaymentAccountPayload.toProtoMessage()); + return builder.build(); } } diff --git a/core/src/main/java/bisq/core/api/model/PaymentAccountPayloadInfo.java b/core/src/main/java/bisq/core/api/model/PaymentAccountPayloadInfo.java index 76b8b3ce..e0f4ac5c 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountPayloadInfo.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountPayloadInfo.java @@ -47,6 +47,7 @@ public class PaymentAccountPayloadInfo implements Payload { } public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(PaymentAccountPayload paymentAccountPayload) { + if (paymentAccountPayload == null) return null; Optional address = Optional.empty(); if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload) address = Optional.of(((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress()); diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index d348b2d4..7bca9ecc 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -66,7 +66,6 @@ import bisq.network.p2p.DecryptedMessageWithPubKey; import bisq.network.p2p.NodeAddress; import bisq.network.p2p.P2PService; import bisq.network.p2p.network.TorNetworkNode; -import bisq.proto.grpc.NotificationMessage; import com.google.common.collect.ImmutableList; import bisq.common.ClockWatcher; import bisq.common.config.Config; @@ -93,7 +92,6 @@ import javafx.collections.ObservableList; import org.bouncycastle.crypto.params.KeyParameter; import org.fxmisc.easybind.EasyBind; -import org.fxmisc.easybind.Subscription; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -522,10 +520,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi // TODO (woodser): save subscription, bind on startup EasyBind.subscribe(trade.statePhaseProperty(), phase -> { if (phase == Phase.DEPOSIT_PUBLISHED) { - notificationService.sendNotification(NotificationMessage.newBuilder() - .setTimestamp(System.currentTimeMillis()) - .setTitle("Offer Taken") - .setMessage("Your offer " + offer.getId() + " has been accepted").build()); + notificationService.sendTradeNotification(trade, "Offer Taken", "Your offer " + offer.getId() + " has been accepted"); // TODO (woodser): use language translation } }); diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index cb733859..b4aa2fcb 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -55,9 +55,19 @@ message RegisterNotificationListenerRequest { } message NotificationMessage { - int64 timestamp = 1; - string title = 2; - string message = 3; + enum NotificationType { + TRADE_UPDATE = 0; + CHAT_MESSAGE = 1; + KEEP_ALIVE = 2; + } + + string id = 1; + NotificationType type = 2; + int64 timestamp = 3; + string title = 4; + string message = 5; + TradeInfo trade = 6; + ChatMessage chat_message = 7; } message SendNotificationRequest {