mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-22 00:11:19 -04:00
Add API functions to support trade chat (#257)
This commit is contained in:
parent
e7b4627102
commit
2851319e3b
4 changed files with 102 additions and 3 deletions
|
@ -32,6 +32,7 @@ import bisq.core.payment.payload.PaymentMethod;
|
|||
import bisq.core.support.dispute.Attachment;
|
||||
import bisq.core.support.dispute.Dispute;
|
||||
import bisq.core.support.dispute.DisputeResult;
|
||||
import bisq.core.support.messages.ChatMessage;
|
||||
import bisq.core.trade.Trade;
|
||||
import bisq.core.trade.statistics.TradeStatistics3;
|
||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
|
@ -543,4 +544,12 @@ public class CoreApi {
|
|||
public String getTradeRole(String tradeId) {
|
||||
return coreTradesService.getTradeRole(tradeId);
|
||||
}
|
||||
|
||||
public List<ChatMessage> getChatMessages(String tradeId) {
|
||||
return coreTradesService.getChatMessages(tradeId);
|
||||
}
|
||||
|
||||
public void sendChatMessage(String tradeId, String message) {
|
||||
coreTradesService.sendChatMessage(tradeId, message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ import bisq.core.btc.wallet.BtcWalletService;
|
|||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.offer.takeoffer.TakeOfferModel;
|
||||
import bisq.core.support.dispute.Dispute;
|
||||
import bisq.core.support.messages.ChatMessage;
|
||||
import bisq.core.support.traderchat.TradeChatSession;
|
||||
import bisq.core.support.traderchat.TraderChatManager;
|
||||
import bisq.core.trade.Tradable;
|
||||
import bisq.core.trade.Trade;
|
||||
import bisq.core.trade.TradeManager;
|
||||
|
@ -58,10 +62,10 @@ class CoreTradesService {
|
|||
// exception is made in this case.
|
||||
private final CoreWalletsService coreWalletsService;
|
||||
private final BtcWalletService btcWalletService;
|
||||
private final OfferUtil offerUtil;
|
||||
private final ClosedTradableManager closedTradableManager;
|
||||
private final TakeOfferModel takeOfferModel;
|
||||
private final TradeManager tradeManager;
|
||||
private final TraderChatManager traderChatManager;
|
||||
private final TradeUtil tradeUtil;
|
||||
private final User user;
|
||||
|
||||
|
@ -69,19 +73,19 @@ class CoreTradesService {
|
|||
public CoreTradesService(CoreContext coreContext,
|
||||
CoreWalletsService coreWalletsService,
|
||||
BtcWalletService btcWalletService,
|
||||
OfferUtil offerUtil,
|
||||
ClosedTradableManager closedTradableManager,
|
||||
TakeOfferModel takeOfferModel,
|
||||
TradeManager tradeManager,
|
||||
TraderChatManager traderChatManager,
|
||||
TradeUtil tradeUtil,
|
||||
User user) {
|
||||
this.coreContext = coreContext;
|
||||
this.coreWalletsService = coreWalletsService;
|
||||
this.btcWalletService = btcWalletService;
|
||||
this.offerUtil = offerUtil;
|
||||
this.closedTradableManager = closedTradableManager;
|
||||
this.takeOfferModel = takeOfferModel;
|
||||
this.tradeManager = tradeManager;
|
||||
this.traderChatManager = traderChatManager;
|
||||
this.tradeUtil = tradeUtil;
|
||||
this.user = user;
|
||||
}
|
||||
|
@ -237,6 +241,34 @@ class CoreTradesService {
|
|||
return trades;
|
||||
}
|
||||
|
||||
List<ChatMessage> getChatMessages(String tradeId) {
|
||||
Trade trade;
|
||||
var tradeOptional = tradeManager.getTradeById(tradeId);
|
||||
if (tradeOptional.isPresent()) trade = tradeOptional.get();
|
||||
else throw new IllegalStateException(format("trade with id '%s' not found", tradeId));
|
||||
boolean isMaker = tradeManager.isMyOffer(trade.getOffer());
|
||||
TradeChatSession tradeChatSession = new TradeChatSession(trade, !isMaker);
|
||||
return tradeChatSession.getObservableChatMessageList();
|
||||
}
|
||||
|
||||
void sendChatMessage(String tradeId, String message) {
|
||||
Trade trade;
|
||||
var tradeOptional = tradeManager.getTradeById(tradeId);
|
||||
if (tradeOptional.isPresent()) trade = tradeOptional.get();
|
||||
else throw new IllegalStateException(format("trade with id '%s' not found", tradeId));
|
||||
boolean isMaker = tradeManager.isMyOffer(trade.getOffer());
|
||||
TradeChatSession tradeChatSession = new TradeChatSession(trade, !isMaker);
|
||||
ChatMessage chatMessage = new ChatMessage(
|
||||
traderChatManager.getSupportType(),
|
||||
tradeChatSession.getTradeId(),
|
||||
tradeChatSession.getClientId(),
|
||||
tradeChatSession.isClient(),
|
||||
message,
|
||||
traderChatManager.getMyAddress());
|
||||
traderChatManager.addAndPersistChatMessage(chatMessage);
|
||||
traderChatManager.sendChatMessage(chatMessage);
|
||||
}
|
||||
|
||||
private boolean isFollowingBuyerProtocol(Trade trade) {
|
||||
return tradeManager.getTradeProtocol(trade) instanceof BuyerProtocol;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue