Skip to content

Commit

Permalink
Use highlightedMessage observable in BisqEasyOfferbookChannel for man…
Browse files Browse the repository at this point in the history
…aging highlighted offers
  • Loading branch information
HenrikJannsen committed Jan 16, 2025
1 parent f75e94e commit 091cd95
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import bisq.chat.ChatMessage;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookChannel;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookChannelService;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookMessage;
import bisq.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannel;
import bisq.chat.notifications.ChatNotification;
import bisq.chat.notifications.ChatNotificationService;
Expand All @@ -36,9 +35,7 @@
import bisq.common.proto.ProtobufUtils;
import bisq.desktop.ServiceProvider;
import bisq.desktop.common.observable.FxBindings;
import bisq.desktop.common.threading.UIScheduler;
import bisq.desktop.common.threading.UIThread;
import bisq.desktop.common.view.InitWithDataController;
import bisq.desktop.common.view.Navigation;
import bisq.desktop.main.content.bisq_easy.offerbook.offerbook_list.OfferbookListController;
import bisq.desktop.main.content.bisq_easy.trade_wizard.TradeWizardController;
Expand All @@ -51,9 +48,6 @@
import bisq.settings.SettingsService;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
Expand All @@ -68,19 +62,7 @@
import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
public final class BisqEasyOfferbookController extends ChatController<BisqEasyOfferbookView, BisqEasyOfferbookModel>
implements InitWithDataController<BisqEasyOfferbookController.InitData> {
@Getter
@EqualsAndHashCode
@ToString
public static final class InitData {
private final BisqEasyOfferbookMessage chatMessage;

public InitData(BisqEasyOfferbookMessage chatMessage) {
this.chatMessage = chatMessage;
}
}

public final class BisqEasyOfferbookController extends ChatController<BisqEasyOfferbookView, BisqEasyOfferbookModel> {
private final SettingsService settingsService;
private final MarketPriceService marketPriceService;
private final BisqEasyOfferbookChannelService bisqEasyOfferbookChannelService;
Expand Down Expand Up @@ -117,15 +99,6 @@ public BisqEasyOfferbookController(ServiceProvider serviceProvider) {
favouriteMarketChannelItemsPredicate = item -> item.getIsFavourite().get();
}

@Override
public void initWithData(InitData initData) {
BisqEasyOfferbookMessage chatMessage = initData.getChatMessage();
bisqEasyOfferbookChannelService.findChannel(chatMessage.getChannelId()).ifPresent(channel -> {
maybeUpdateSelectedChannel(channel);
UIScheduler.run(() -> chatMessageContainerController.highlightOfferChatMessage(initData.getChatMessage())).after(110);
});
}

@Override
public BisqEasyOfferbookModel createAndGetModel(ChatChannelDomain chatChannelDomain) {
BisqEasyOfferbookModel model = new BisqEasyOfferbookModel(chatChannelDomain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ void toggleOfferList() {
}

void onSelectOfferMessageItem(OfferbookListItem item) {
chatMessageContainerController.highlightOfferChatMessage(item == null ? null : item.getBisqEasyOfferbookMessage());
if (item != null) {
model.getChannel().get().getHighlightedMessage().set(item.getBisqEasyOfferbookMessage());
}
}

void onSelectBuyFromFilter() {
Expand Down Expand Up @@ -251,7 +253,7 @@ private boolean shouldShowListItem(OfferbookListItem item) {
boolean paymentFiltersApplied = model.getActiveMarketPaymentsCount().get() != 0;
boolean matchesPaymentFilters = paymentFiltersApplied && item.getFiatPaymentMethods().stream()
.anyMatch(payment -> (payment.isCustomPaymentMethod() && model.getIsCustomPaymentsSelected().get())
|| model.getSelectedMarketPayments().contains(payment));
|| model.getSelectedMarketPayments().contains(payment));
boolean myOffersOnly = model.getShowMyOffersOnly().get();
UserProfile mySelectedUserProfile = userIdentityService.getSelectedUserIdentity().getUserProfile();
boolean isMyOffer = item.getSenderUserProfile().equals(mySelectedUserProfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
package bisq.desktop.main.content.chat.message_container;

import bisq.bisq_easy.NavigationTarget;
import bisq.chat.ChatChannel;
import bisq.chat.ChatChannelDomain;
import bisq.chat.ChatChannelSelectionService;
import bisq.chat.ChatMessage;
import bisq.chat.ChatService;
import bisq.chat.Citation;
import bisq.chat.*;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookChannel;
import bisq.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannel;
import bisq.chat.common.CommonPublicChatChannel;
Expand All @@ -47,7 +42,6 @@
import bisq.user.profile.UserProfileService;
import lombok.Getter;

import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -116,10 +110,6 @@ public void setSearchPredicate(Predicate<? super ChatMessageListItem<? extends C
chatMessagesListController.setSearchPredicate(predicate);
}

public void highlightOfferChatMessage(@Nullable ChatMessage message) {
chatMessagesListController.highlightOfferChatMessage(message);
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// Controller
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package bisq.desktop.main.content.chat.message_container.list;

import bisq.bisq_easy.BisqEasyService;
import bisq.bisq_easy.BisqEasyTradeAmountLimits;
import bisq.bisq_easy.NavigationTarget;
import bisq.bonded_roles.market_price.MarketPriceService;
Expand Down Expand Up @@ -58,7 +57,6 @@
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -88,10 +86,9 @@ public class ChatMessagesListController implements bisq.desktop.common.view.Cont
private final BannedUserService bannedUserService;
private final NetworkService networkService;
private final Optional<ResendMessageService> resendMessageService;
private final BisqEasyService bisqEasyService;
private final MarketPriceService marketPriceService;
private final LeavePrivateChatManager leavePrivateChatManager;
private Pin selectedChannelPin, chatMessagesPin, bisqEasyOfferbookMessageTypeFilterPin;
private Pin selectedChannelPin, chatMessagesPin, bisqEasyOfferbookMessageTypeFilterPin, highlightedMessagePin;
private Subscription selectedChannelSubscription, focusSubscription, scrollValuePin, scrollBarVisiblePin,
layoutChildrenDonePin;

Expand All @@ -107,7 +104,6 @@ public ChatMessagesListController(ServiceProvider serviceProvider,
userProfileService = serviceProvider.getUserService().getUserProfileService();
reputationService = serviceProvider.getUserService().getReputationService();
settingsService = serviceProvider.getSettingsService();
bisqEasyService = serviceProvider.getBisqEasyService();
bisqEasyTradeService = serviceProvider.getTradeService().getBisqEasyTradeService();
bannedUserService = serviceProvider.getUserService().getBannedUserService();
networkService = serviceProvider.getNetworkService();
Expand Down Expand Up @@ -166,6 +162,11 @@ public void onDeactivate() {
chatMessagesPin.unbind();
chatMessagesPin = null;
}
if (highlightedMessagePin != null) {
highlightedMessagePin.unbind();
highlightedMessagePin = null;
}

if (focusSubscription != null) {
focusSubscription.unsubscribe();
}
Expand Down Expand Up @@ -232,6 +233,26 @@ private void selectedChannelChanged(ChatChannel<? extends ChatMessage> channel)
});
}
});

if (channel instanceof BisqEasyOfferbookChannel bisqEasyOfferbookChannel) {
if (highlightedMessagePin != null) {
highlightedMessagePin.unbind();
}
highlightedMessagePin = bisqEasyOfferbookChannel.getHighlightedMessage().addObserver(highlightedMessage -> {
if (highlightedMessage != null) {
model.getChatMessages().stream()
.filter(ChatMessageListItem::isBisqEasyPublicChatMessageWithOffer)
.forEach(item -> {
boolean shouldHighlightMessage = item.getChatMessage().getId().equals(highlightedMessage.getId());
item.getShowHighlighted().set(shouldHighlightMessage);
if (shouldHighlightMessage) {
view.scrollToChatMessage(item);
}
});
}

});
}
}


Expand Down Expand Up @@ -524,18 +545,6 @@ public void onReactMessage(ChatMessage chatMessage, Reaction reaction, ChatChann
}
}

public void highlightOfferChatMessage(@Nullable ChatMessage message) {
model.getChatMessages().stream()
.filter(ChatMessageListItem::isBisqEasyPublicChatMessageWithOffer)
.forEach(item -> {
boolean shouldHighlightMessage = message != null && Objects.equals(item.getChatMessage(), message);
item.getShowHighlighted().set(shouldHighlightMessage);
if (shouldHighlightMessage) {
view.scrollToChatMessage(item);
}
});
}

public String getUserName(String userProfileId) {
return userProfileService.findUserProfile(userProfileId)
.map(UserProfile::getUserName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookChannel;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookChannelService;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookMessage;
import bisq.chat.bisq_easy.offerbook.BisqEasyOfferbookSelectionService;
import bisq.desktop.ServiceProvider;
import bisq.desktop.common.view.Controller;
import bisq.desktop.common.view.Navigation;
import bisq.desktop.main.content.bisq_easy.offerbook.BisqEasyOfferbookController;
import bisq.desktop.main.content.bisq_easy.offerbook.offerbook_list.OfferbookListItem;
import bisq.desktop.overlay.OverlayController;
import bisq.user.profile.UserProfile;
Expand All @@ -42,11 +42,13 @@ public class ProfileCardOffersController implements Controller {
private final BisqEasyOfferbookChannelService bisqEasyOfferbookChannelService;
private final ReputationService reputationService;
private final MarketPriceService marketPriceService;
private final BisqEasyOfferbookSelectionService bisqEasyOfferbookChannelSelectionService;

public ProfileCardOffersController(ServiceProvider serviceProvider) {
model = new ProfileCardOffersModel();
view = new ProfileCardOffersView(model, this);
bisqEasyOfferbookChannelService = serviceProvider.getChatService().getBisqEasyOfferbookChannelService();
bisqEasyOfferbookChannelSelectionService= serviceProvider.getChatService().getBisqEasyOfferbookChannelSelectionService();
reputationService = serviceProvider.getUserService().getReputationService();
marketPriceService = serviceProvider.getBondedRolesService().getMarketPriceService();
}
Expand Down Expand Up @@ -79,8 +81,12 @@ public String getNumberOffers() {
}

void onGoToOfferbookMessage(BisqEasyOfferbookMessage bisqEasyOfferbookMessage) {
OverlayController.hide(() ->
Navigation.navigateTo(NavigationTarget.BISQ_EASY_OFFERBOOK,
new BisqEasyOfferbookController.InitData(bisqEasyOfferbookMessage)));
bisqEasyOfferbookChannelService.findChannel(bisqEasyOfferbookMessage.getChannelId())
.ifPresent(channel -> {
bisqEasyOfferbookChannelSelectionService.selectChannel(channel);
channel.getHighlightedMessage().set(bisqEasyOfferbookMessage);
});

OverlayController.hide(() -> Navigation.navigateTo(NavigationTarget.BISQ_EASY_OFFERBOOK));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.chat.notifications.ChatChannelNotificationType;
import bisq.chat.pub.PublicChatChannel;
import bisq.common.currency.Market;
import bisq.common.observable.Observable;
import bisq.i18n.Res;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -37,6 +38,7 @@ static String createId(Market market) {
}

private final Market market;
private final Observable<BisqEasyOfferbookMessage> highlightedMessage = new Observable<>();

public BisqEasyOfferbookChannel(Market market) {
this(createId(market), ChatChannelNotificationType.ALL, market);
Expand Down

0 comments on commit 091cd95

Please sign in to comment.