mirror of
https://github.com/retoaccess1/haveno-reto.git
synced 2024-11-10 13:13:36 +01:00
support notification types: trade update, chat message, keep alive
This commit is contained in:
parent
422267de79
commit
2715e1bba8
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ public class PaymentAccountPayloadInfo implements Payload {
|
||||
}
|
||||
|
||||
public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(PaymentAccountPayload paymentAccountPayload) {
|
||||
if (paymentAccountPayload == null) return null;
|
||||
Optional<String> address = Optional.empty();
|
||||
if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload)
|
||||
address = Optional.of(((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress());
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user