Skip to content

Commit

Permalink
Refactor dto and model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Jan 13, 2025
1 parent c9c45ef commit 3302191
Show file tree
Hide file tree
Showing 48 changed files with 157 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ import network.bisq.mobile.domain.data.replicated.account.protocol_type.TradePro
import network.bisq.mobile.domain.data.replicated.chat.ChatChannelDomainEnum
import network.bisq.mobile.domain.data.replicated.chat.ChatMessageTypeEnum
import network.bisq.mobile.domain.data.replicated.chat.CitationVO
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.offerbook.BisqEasyOfferbookMessageVO
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannelModel
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannelVO
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.offerbook.BisqEasyOfferbookMessageDto
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannelDto
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.open_trades.BisqEasyOpenTradeMessageDto
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.open_trades.BisqEasyOpenTradeMessageModel
import network.bisq.mobile.domain.data.replicated.chat.bisq_easy.open_trades.BisqEasyOpenTradeMessageVO
import network.bisq.mobile.domain.data.replicated.chat.notifications.ChatChannelNotificationTypeEnum
import network.bisq.mobile.domain.data.replicated.chat.reactions.BisqEasyOfferbookMessageReactionVO
import network.bisq.mobile.domain.data.replicated.chat.reactions.BisqEasyOpenTradeMessageReactionVO
Expand Down Expand Up @@ -133,9 +132,9 @@ import network.bisq.mobile.domain.data.replicated.security.keys.TorKeyPairVO
import network.bisq.mobile.domain.data.replicated.security.pow.ProofOfWorkVO
import network.bisq.mobile.domain.data.replicated.settings.SettingsVO
import network.bisq.mobile.domain.data.replicated.trade.TradeRoleEnum
import network.bisq.mobile.domain.data.replicated.trade.bisq_easy.BisqEasyTradeDto
import network.bisq.mobile.domain.data.replicated.trade.bisq_easy.BisqEasyTradeModel
import network.bisq.mobile.domain.data.replicated.trade.bisq_easy.BisqEasyTradePartyVO
import network.bisq.mobile.domain.data.replicated.trade.bisq_easy.BisqEasyTradeVO
import network.bisq.mobile.domain.data.replicated.trade.bisq_easy.protocol.BisqEasyTradeStateEnum
import network.bisq.mobile.domain.data.replicated.user.identity.UserIdentityVO
import network.bisq.mobile.domain.data.replicated.user.profile.UserProfileVO
Expand Down Expand Up @@ -241,7 +240,7 @@ class Mappings {
// chat.bisq_easy.offerbook

object BisqEasyOfferbookMessageMapping {
fun toBisq2Model(value: BisqEasyOfferbookMessageVO): BisqEasyOfferbookMessage {
fun toBisq2Model(value: BisqEasyOfferbookMessageDto): BisqEasyOfferbookMessage {
return BisqEasyOfferbookMessage(
value.id,
ChatChannelDomain.BISQ_EASY_OFFERBOOK,
Expand All @@ -256,8 +255,8 @@ class Mappings {
)
}

fun fromBisq2Model(value: BisqEasyOfferbookMessage): BisqEasyOfferbookMessageVO {
return BisqEasyOfferbookMessageVO(
fun fromBisq2Model(value: BisqEasyOfferbookMessage): BisqEasyOfferbookMessageDto {
return BisqEasyOfferbookMessageDto(
value.id,
value.channelId,
value.authorUserProfileId,
Expand Down Expand Up @@ -288,8 +287,8 @@ class Mappings {
)
}*/

fun fromBisq2Model(value: BisqEasyOpenTradeChannel): BisqEasyOpenTradeChannelVO {
return BisqEasyOpenTradeChannelVO(
fun fromBisq2Model(value: BisqEasyOpenTradeChannel): BisqEasyOpenTradeChannelDto {
return BisqEasyOpenTradeChannelDto(
value.id,
value.tradeId,
BisqEasyOfferMapping.fromBisq2Model(value.bisqEasyOffer),
Expand All @@ -300,72 +299,15 @@ class Mappings {
}
}

object BisqEasyOpenTradeChannelModelMapping {
fun toBisq2Model(model: BisqEasyOpenTradeChannelModel): BisqEasyOpenTradeChannel {
val vo = model.bisqEasyOpenTradeChannel
return BisqEasyOpenTradeChannel(
vo.id,
vo.tradeId,
BisqEasyOfferMapping.toBisq2Model(vo.bisqEasyOffer),
UserIdentityMapping.toBisq2Model(vo.myUserIdentity),
vo.traders.map { UserProfileMapping.toBisq2Model(it) }.toSet(),
Optional.ofNullable(vo.mediator?.let { UserProfileMapping.toBisq2Model(it) }),
model.chatMessages.map { BisqEasyOpenTradeMessageModelMapping.toBisq2Model(it) }.toSet(),
model.isInMediation.value,
ChatChannelNotificationTypeMapping.toBisq2Model(model.chatChannelNotificationType.value),
)
}

fun fromBisq2Model(value: BisqEasyOpenTradeChannel): BisqEasyOpenTradeChannelModel {
return BisqEasyOpenTradeChannelModel(BisqEasyOpenTradeChannelVOMapping.fromBisq2Model(value))
.apply {
isInMediation.value = value.isInMediation
chatMessages.addAll(value.chatMessages.map { BisqEasyOpenTradeMessageModelMapping.fromBisq2Model(it) })
chatChannelNotificationType.value =
ChatChannelNotificationTypeMapping.fromBisq2Model(value.chatChannelNotificationType.get())
userProfileIdsOfActiveParticipants.addAll(value.userProfileIdsOfActiveParticipants)
numMessagesByAuthorId.putAll(value.numMessagesByAuthorId.entries.associate { it.key to it.value.get() })
userProfileIdsOfSendingLeaveMessage.addAll(value.userProfileIdsOfSendingLeaveMessage)
}
}
}

object BisqEasyOpenTradeMessageModelMapping {
fun toBisq2Model(value: BisqEasyOpenTradeMessageModel): BisqEasyOpenTradeMessage {
val vo = value.bisqEasyOpenTradeMessage
return BisqEasyOpenTradeMessage(
vo.tradeId,
vo.id,
ChatChannelDomainMapping.toBisq2Model(vo.chatChannelDomain),
vo.channelId,
UserProfileMapping.toBisq2Model(vo.senderUserProfile),
vo.receiverUserProfileId,
NetworkIdMapping.toBisq2Model(vo.receiverNetworkId),
vo.text,
Optional.ofNullable(vo.citation?.let { CitationMapping.toBisq2Model(it) }),
vo.date,
vo.wasEdited,
Optional.ofNullable(vo.mediator?.let { UserProfileMapping.toBisq2Model(it) }),
ChatMessageTypeMapping.toBisq2Model(vo.chatMessageType),
Optional.ofNullable(vo.bisqEasyOffer?.let { BisqEasyOfferMapping.toBisq2Model(it) }),
value.chatMessageReactions.map { BisqEasyOpenTradeMessageReactionMapping.toBisq2Model(it) }.toSet(),
)
}

fun fromBisq2Model(value: BisqEasyOpenTradeMessage): BisqEasyOpenTradeMessageModel {
return BisqEasyOpenTradeMessageModel(
BisqEasyOpenTradeMessageVOMapping.fromBisq2Model(value),
value.chatMessageReactions.map { BisqEasyOpenTradeMessageReactionMapping.fromBisq2Model(it) }.toMutableSet()
)
return BisqEasyOpenTradeMessageModel(BisqEasyOpenTradeMessageVOMapping.fromBisq2Model(value))
}
}

object BisqEasyOpenTradeMessageVOMapping {
// toBisq2Model no supported as BisqEasyOpenTradeMessageVO is missing mutable data.
// Use BisqEasyOpenTradeMessageModelMapping.toBisq2Model instead

fun fromBisq2Model(value: BisqEasyOpenTradeMessage): BisqEasyOpenTradeMessageVO {
return BisqEasyOpenTradeMessageVO(
fun fromBisq2Model(value: BisqEasyOpenTradeMessage): BisqEasyOpenTradeMessageDto {
return BisqEasyOpenTradeMessageDto(
value.id,
ChatChannelDomainMapping.fromBisq2Model(value.chatChannelDomain),
value.channelId,
Expand Down Expand Up @@ -1195,21 +1137,8 @@ class Mappings {
// trade

object BisqEasyTradeVOMapping {
//todo BisqEasyTradeState is mutable value
/* fun toBisq2Model(value: BisqEasyTradeVO): BisqEasyTrade {
return BisqEasyTrade(
BisqEasyContractMapping.toBisq2Model(value.contract),
BisqEasyTradeState.INIT, //todo
value.id,
TradeRoleMapping.toBisq2Model(value.tradeRole),
IdentityMapping.toBisq2Model(value.myIdentity),
BisqEasyTradePartyVOMapping.toBisq2Model(value.taker),
BisqEasyTradePartyVOMapping.toBisq2Model(value.maker),
)
}*/

fun fromBisq2Model(value: BisqEasyTrade): BisqEasyTradeVO {
return BisqEasyTradeVO(
fun fromBisq2Model(value: BisqEasyTrade): BisqEasyTradeDto {
return BisqEasyTradeDto(
BisqEasyContractMapping.fromBisq2Model(value.contract),
value.id,
TradeRoleMapping.fromBisq2Model(value.tradeRole),
Expand All @@ -1230,18 +1159,6 @@ class Mappings {
}

object BisqEasyTradeModelMapping {
/* fun toBisq2Model(value: BisqEasyTradeModel): BisqEasyTrade {
return BisqEasyTrade(
BisqEasyContractMapping.toBisq2Model(value.contract),
BisqEasyTradeStateMapping.toBisq2Model(value.tradeState.value),
value.id,
TradeRoleMapping.toBisq2Model(value.tradeRole),
IdentityMapping.toBisq2Model(value.myIdentity),
BisqEasyTradePartyModelMapping.toBisq2Model(value.taker),
BisqEasyTradePartyModelMapping.toBisq2Model(value.maker),
)
}*/

fun fromBisq2Model(value: BisqEasyTrade): BisqEasyTradeModel {
return BisqEasyTradeModel(
BisqEasyTradeVOMapping.fromBisq2Model(value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import bisq.user.identity.UserIdentityService
import bisq.user.profile.UserProfileService
import bisq.user.reputation.ReputationService
import network.bisq.mobile.android.node.mapping.Mappings.BisqEasyOfferMapping
import network.bisq.mobile.domain.data.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.data.replicated.presentation.offerbook.OfferItemPresentationDto
import java.text.DateFormat
import java.util.Date
import java.util.stream.Collectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import bisq.trade.bisq_easy.BisqEasyTradeUtils
import bisq.user.profile.UserProfileService
import bisq.user.reputation.ReputationService
import network.bisq.mobile.android.node.mapping.Mappings.ReputationScoreMapping
import network.bisq.mobile.domain.data.presentation.open_trades.TradeItemPresentationDto
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationDto
import network.bisq.mobile.domain.data.replicated.user.profile.UserProfileVO


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package network.bisq.mobile.android.node.service.mediation

import bisq.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannel
import bisq.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannelService
import bisq.contract.bisq_easy.BisqEasyContract
import bisq.i18n.Res
import bisq.support.mediation.MediationRequestService
import network.bisq.mobile.android.node.AndroidApplicationService
import network.bisq.mobile.android.node.mapping.Mappings
import network.bisq.mobile.domain.data.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.service.mediation.MediationServiceFacade
import network.bisq.mobile.domain.utils.Logging

Expand All @@ -26,17 +25,23 @@ class NodeMediationServiceFacade(applicationService: AndroidApplicationService.P

// API
override suspend fun reportToMediator(value: TradeItemPresentationModel): Result<Unit> {
val channel: BisqEasyOpenTradeChannel =
Mappings.BisqEasyOpenTradeChannelModelMapping.toBisq2Model(value.bisqEasyOpenTradeChannelModel)
val mediator = channel.mediator
if (mediator.isPresent) {
val encoded =
Res.encode("bisqEasy.mediation.requester.tradeLogMessage", channel.myUserIdentity.userName)
channelService.sendTradeLogMessage(encoded, channel).join()
channel.setIsInMediation(true)
val contract: BisqEasyContract = Mappings.BisqEasyContractMapping.toBisq2Model(value.bisqEasyTradeModel.contract)
mediationRequestService.requestMediation(channel, contract)
val tradeId = value.tradeId
val optionalChannel = channelService.findChannelByTradeId(tradeId)
if (optionalChannel.isPresent) {
val channel = optionalChannel.get()
val mediator = channel.mediator
if (mediator != null) {
val encoded = Res.encode("bisqEasy.mediation.requester.tradeLogMessage", channel.myUserIdentity.userName)
channelService.sendTradeLogMessage(encoded, channel).join()
channel.setIsInMediation(true)
val contract: BisqEasyContract = Mappings.BisqEasyContractMapping.toBisq2Model(value.bisqEasyTradeModel.contract)
mediationRequestService.requestMediation(channel, contract)
return Result.success(Unit)
} else {
return Result.failure(RuntimeException("No mediator found"))
}
} else {
return Result.failure(RuntimeException("No channel found for trade ID $tradeId"))
}
return Result.success(Unit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import network.bisq.mobile.android.node.mapping.Mappings
import network.bisq.mobile.android.node.mapping.OfferItemPresentationVOFactory
import network.bisq.mobile.domain.data.model.offerbook.MarketListItem
import network.bisq.mobile.domain.data.model.offerbook.OfferbookMarket
import network.bisq.mobile.domain.data.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.data.presentation.offerbook.OfferItemPresentationModel
import network.bisq.mobile.domain.data.replicated.common.currency.MarketVO
import network.bisq.mobile.domain.data.replicated.offer.DirectionEnum
import network.bisq.mobile.domain.data.replicated.offer.amount.spec.AmountSpecVO
import network.bisq.mobile.domain.data.replicated.offer.price.spec.PriceSpecVO
import network.bisq.mobile.domain.data.replicated.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.data.replicated.presentation.offerbook.OfferItemPresentationModel
import network.bisq.mobile.domain.service.market_price.MarketPriceServiceFacade
import network.bisq.mobile.domain.service.offers.OffersServiceFacade
import network.bisq.mobile.domain.utils.Logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import kotlinx.coroutines.withTimeout
import network.bisq.mobile.android.node.AndroidApplicationService
import network.bisq.mobile.android.node.mapping.Mappings
import network.bisq.mobile.android.node.mapping.TradeItemPresentationDtoFactory
import network.bisq.mobile.domain.data.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.data.replicated.common.monetary.MonetaryVO
import network.bisq.mobile.domain.data.replicated.offer.bisq_easy.BisqEasyOfferVO
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.service.trades.TakeOfferStatus
import network.bisq.mobile.domain.service.trades.TradesServiceFacade
import network.bisq.mobile.domain.utils.Logging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package network.bisq.mobile.client.service.mediation

import network.bisq.mobile.domain.data.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.service.mediation.MediationServiceFacade
import network.bisq.mobile.domain.utils.Logging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import network.bisq.mobile.client.websocket.subscription.WebSocketEventPayload
import network.bisq.mobile.domain.data.BackgroundDispatcher
import network.bisq.mobile.domain.data.model.offerbook.MarketListItem
import network.bisq.mobile.domain.data.model.offerbook.OfferbookMarket
import network.bisq.mobile.domain.data.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.data.presentation.offerbook.OfferItemPresentationModel
import network.bisq.mobile.domain.data.replicated.common.currency.MarketVO
import network.bisq.mobile.domain.data.replicated.offer.DirectionEnum
import network.bisq.mobile.domain.data.replicated.offer.amount.spec.AmountSpecVO
import network.bisq.mobile.domain.data.replicated.offer.price.spec.PriceSpecVO
import network.bisq.mobile.domain.data.replicated.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.data.replicated.presentation.offerbook.OfferItemPresentationModel
import network.bisq.mobile.domain.service.market_price.MarketPriceServiceFacade
import network.bisq.mobile.domain.service.offers.OffersServiceFacade
import network.bisq.mobile.domain.utils.Logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import network.bisq.mobile.client.websocket.WebSocketClient
import network.bisq.mobile.client.websocket.api_proxy.WebSocketApiClient
import network.bisq.mobile.client.websocket.subscription.Topic
import network.bisq.mobile.client.websocket.subscription.WebSocketEventObserver
import network.bisq.mobile.domain.data.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.data.replicated.common.currency.MarketVO
import network.bisq.mobile.domain.data.replicated.offer.DirectionEnum
import network.bisq.mobile.domain.data.replicated.offer.amount.spec.AmountSpecVO
import network.bisq.mobile.domain.data.replicated.offer.price.spec.PriceSpecVO
import network.bisq.mobile.domain.data.replicated.presentation.offerbook.OfferItemPresentationDto
import network.bisq.mobile.domain.utils.Logging

class OfferbookApiGateway(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import network.bisq.mobile.client.websocket.subscription.ModificationType
import network.bisq.mobile.client.websocket.subscription.Subscription
import network.bisq.mobile.client.websocket.subscription.Topic
import network.bisq.mobile.domain.data.BackgroundDispatcher
import network.bisq.mobile.domain.data.presentation.open_trades.TradeItemPresentationDto
import network.bisq.mobile.domain.data.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.data.replicated.common.monetary.MonetaryVO
import network.bisq.mobile.domain.data.replicated.offer.bisq_easy.BisqEasyOfferVO
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationDto
import network.bisq.mobile.domain.data.replicated.presentation.open_trades.TradeItemPresentationModel
import network.bisq.mobile.domain.service.trades.TakeOfferStatus
import network.bisq.mobile.domain.service.trades.TradesServiceFacade
import network.bisq.mobile.domain.utils.Logging
Expand Down Expand Up @@ -40,7 +40,7 @@ class ClientTradesServiceFacade(
private val openTradesSubscription: Subscription<TradeItemPresentationDto> =
Subscription(webSocketClient, json, Topic.TRADES, this::handleTradeItemPresentationChange)

private val tradePropertiesSubscription: Subscription<Map<String, TradeProperties>> =
private val tradePropertiesSubscription: Subscription<Map<String, TradePropertiesDto>> =
Subscription(webSocketClient, json, Topic.TRADE_PROPERTIES, this::handleTradePropertiesChange)

//private var openTradesSubscriptionJob: Job? = null
Expand Down Expand Up @@ -155,7 +155,7 @@ class ClientTradesServiceFacade(
//applyOffersToSelectedMarket()
}

private fun handleTradePropertiesChange(payload: List<Map<String, TradeProperties>>, modificationType: ModificationType) {
private fun handleTradePropertiesChange(payload: List<Map<String, TradePropertiesDto>>, modificationType: ModificationType) {
payload.flatMap { it.entries }
.forEach { (tradeId, data) ->
findOpenTradeItemModel(tradeId)?.apply {
Expand Down
Loading

0 comments on commit 3302191

Please sign in to comment.