diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index 5f757a672b..5a83e78bbd 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -47,23 +47,13 @@ import java.security.NoSuchAlgorithmException; import java.util.Map; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @Slf4j public class PeerInfoIcon extends Group { - public interface notify { - /** - * Callback from one avatar letting us know that the user updated the tag text. - * We need to update all avatars, as some could be sharing the same tag. - */ - void avatarTagUpdated(); - } - @Setter - private notify callback; protected Preferences preferences; protected final String fullAddress; protected String tooltipText; @@ -72,6 +62,7 @@ public class PeerInfoIcon extends Group { protected Pane tagPane; protected Pane numTradesPane; protected int numTrades = 0; + private Map avatarMap; public PeerInfoIcon(NodeAddress nodeAddress, Preferences preferences) { this.preferences = preferences; @@ -188,8 +179,11 @@ public class PeerInfoIcon extends Group { .position(localToScene(new Point2D(0, 0))) .onSave(newTag -> { preferences.setTagForPeer(fullAddress, newTag); - if (callback != null) { - callback.avatarTagUpdated(); + if (avatarMap != null) { + log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size()); + avatarMap.forEach((key, avatarIcon) -> avatarIcon.refreshTag()); + } else { + this.refreshTag(); } }) .show(); @@ -224,7 +218,7 @@ public class PeerInfoIcon extends Group { refreshTag(); } - public void refreshTag() { + protected void refreshTag() { String tag; Map peerTagMap = preferences.getPeerTagMap(); if (peerTagMap.containsKey(fullAddress)) { @@ -242,4 +236,16 @@ public class PeerInfoIcon extends Group { tagPane.setVisible(!tag.isEmpty()); } + + /** + * Sets the map where this icon is stored and associates the latter with the specified key. + * The map will be traversed later on if the user updates an icon's tag, and all avatars + * will be refreshed as some could be sharing the same tag. + * @param avatarMap The map to which this avatar is stored + * @param key Key that is associated with the avatar + */ + public void setAvatarMapAndKey(Map avatarMap, String key) { + this.avatarMap = avatarMap; + avatarMap.put(key, this); + } } diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java index 32f70cf996..31f5e4a1d8 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java @@ -8,8 +8,13 @@ import bisq.core.user.Preferences; import bisq.network.p2p.NodeAddress; +import java.util.Map; + +import lombok.extern.slf4j.Slf4j; + import javax.annotation.Nullable; +@Slf4j public class PeerInfoIconSmall extends PeerInfoIconTrading { public PeerInfoIconSmall(NodeAddress nodeAddress, String role, @@ -53,4 +58,10 @@ public class PeerInfoIconSmall extends PeerInfoIconTrading { numTradesPane.setVisible(false); tagPane.setVisible(false); } + + @Override + public void setAvatarMapAndKey(Map avatarMap, String key) { + // We don't show a tag, so no map needs to be traversed to refresh any tags + log.error("setAvatarMapAndKey: method not supported"); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index b7ec009165..ac88cafcfa 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -121,7 +121,7 @@ import org.jetbrains.annotations.NotNull; import static bisq.desktop.util.FormBuilder.addTitledGroupBg; -abstract public class OfferBookView extends ActivatableViewAndModel implements PeerInfoIcon.notify { +abstract public class OfferBookView extends ActivatableViewAndModel { private final Navigation navigation; private final OfferDetailsWindow offerDetailsWindow; @@ -154,7 +154,7 @@ abstract public class OfferBookView avatarMap = new HashMap<>(); + private final Map avatarMap = new HashMap<>(); /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -1271,7 +1271,20 @@ abstract public class OfferBookView { - avatarIcon.refreshTag(); - }); - } - @NotNull private Region getSpacer() { final Region spacer = new Region(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java index 8aeb3baf02..e5564dcbcc 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java @@ -22,6 +22,7 @@ import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.HyperlinkWithIcon; +import bisq.desktop.components.PeerInfoIcon; import bisq.desktop.components.PeerInfoIconTrading; import bisq.desktop.components.list.FilterBox; import bisq.desktop.main.overlays.windows.BsqTradeDetailsWindow; @@ -46,7 +47,6 @@ import javafx.fxml.FXML; import javafx.stage.Stage; -import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; @@ -68,6 +68,8 @@ import javafx.collections.transformation.SortedList; import javafx.util.Callback; import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; import java.util.function.Function; @FxmlView @@ -129,6 +131,7 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel sortedList; private FilteredList filteredList; private ChangeListener widthListener; + private final Map avatarMap = new HashMap<>(); @Inject public UnconfirmedBsqSwapsView(UnconfirmedBsqSwapsViewModel model, @@ -259,6 +262,8 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel> Comparator nullsFirstComparing( @@ -400,7 +405,7 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel sortedList; private FilteredList filteredList; private ChangeListener widthListener; + private final Map avatarMap = new HashMap<>(); @Inject public ClosedTradesView(ClosedTradesViewModel model, @@ -344,6 +347,8 @@ public class ClosedTradesView extends ActivatableViewAndModel> Comparator nullsFirstComparing(Function keyExtractor) { @@ -528,7 +533,7 @@ public class ClosedTradesView extends ActivatableViewAndModel disputeStateListener; private ChangeListener mediationResultStateListener; private ChangeListener getMempoolStatusListener; + private final Map avatarMap = new HashMap<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -357,6 +358,8 @@ public class PendingTradesView extends ActivatableViewAndModel implements PeerInfoIcon.notify, DisputeChatPopup.ChatCallback { +public abstract class DisputeView extends ActivatableView implements DisputeChatPopup.ChatCallback { public enum FilterResult { NO_MATCH("No Match"), NO_FILTER("No filter text"), @@ -191,7 +191,7 @@ public abstract class DisputeView extends ActivatableView implements private Map chatButtonByDispute = new HashMap<>(); private Map chatBadgeByDispute = new HashMap<>(); private Map newBadgeByDispute = new HashMap<>(); - private Map avatarMap = new HashMap<>(); + private final Map avatarMap = new HashMap<>(); protected DisputeChatPopup chatPopup; @@ -1489,19 +1489,10 @@ public abstract class DisputeView extends ActivatableView implements disputeManager.getNrOfDisputes(isBuyer, contract), accountAge, preferences); - peerInfoIcon.setCallback(this); - avatarMap.put(key, peerInfoIcon); + peerInfoIcon.setAvatarMapAndKey(avatarMap, key); return peerInfoIcon; } - @Override - public void avatarTagUpdated() { - log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size()); - avatarMap.forEach((key, avatarIcon) -> { - avatarIcon.refreshTag(); - }); - } - @Override public void onCloseDisputeFromChatWindow(Dispute dispute) { handleOnProcessDispute(dispute);