Skip to content

Commit

Permalink
Merge pull request #2393 from axpoems/clean-up-reactions
Browse files Browse the repository at this point in the history
Clean up chat message class definition
  • Loading branch information
djing-chan authored Jul 11, 2024
2 parents 0a21412 + eab2c3c commit 36c45e8
Show file tree
Hide file tree
Showing 40 changed files with 130 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class MediatorModel implements Model {
private final Map<String, StringProperty> chatMessagesByChannelId = new HashMap<>();
private final StringProperty selectedChatMessages = new SimpleStringProperty("");
private final ObjectProperty<ChatChannel<? extends ChatMessage<?>>> selectedChannel = new SimpleObjectProperty<>();
private final ObjectProperty<ChatChannel<? extends ChatMessage>> selectedChannel = new SimpleObjectProperty<>();

private final BooleanProperty showClosedCases = new SimpleBooleanProperty();
private final BooleanProperty noOpenCases = new SimpleBooleanProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void onDeactivate() {
}

@Override
protected void selectedChannelChanged(ChatChannel<? extends ChatMessage<?>> chatChannel) {
protected void selectedChannelChanged(ChatChannel<? extends ChatMessage> chatChannel) {
super.selectedChannelChanged(chatChannel);

UIThread.run(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void onDeactivate() {
}

@Override
protected void selectedChannelChanged(ChatChannel<? extends ChatMessage<?>> chatChannel) {
protected void selectedChannelChanged(ChatChannel<? extends ChatMessage> chatChannel) {
super.selectedChannelChanged(chatChannel);

UIThread.run(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import bisq.chat.ChatChannel;
import bisq.chat.ChatMessage;
import bisq.chat.reactions.ChatMessageReaction;
import bisq.desktop.components.controls.BisqMenuItem;
import bisq.desktop.main.content.chat.message_container.list.ChatMessageListItem;
import bisq.desktop.main.content.chat.message_container.list.ChatMessagesListController;
Expand All @@ -31,7 +30,7 @@
public class MyProtocolLogMessageBox extends PeerProtocolLogMessageBox {
private final Subscription shouldShowTryAgainPin, messageDeliveryStatusNodePin;

public MyProtocolLogMessageBox(ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>> item,
public MyProtocolLogMessageBox(ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>> item,
ChatMessagesListController controller) {
super(item);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import bisq.chat.ChatChannel;
import bisq.chat.ChatMessage;
import bisq.chat.reactions.ChatMessageReaction;
import bisq.desktop.main.content.chat.message_container.list.ChatMessageListItem;
import bisq.desktop.main.content.chat.message_container.list.message_box.MessageBox;
import bisq.i18n.Res;
Expand All @@ -31,13 +30,13 @@
import javafx.scene.layout.VBox;

public class PeerProtocolLogMessageBox extends MessageBox {
protected final ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>> item;
protected final ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>> item;
protected final VBox tradeLogMessageBg = new VBox();
protected final VBox contentVBox;
protected final HBox dateTimeHBox;
protected final Label message, dateTime;

public PeerProtocolLogMessageBox(ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>> item) {
public PeerProtocolLogMessageBox(ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>> item) {
this.item = item;

String decoded = Res.decode(item.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected void openUserProfileSidebar(UserProfile userProfile) {
model.getChatUserDetailsRoot().set(userProfileSidebar.getRoot());
}

protected void selectedChannelChanged(@Nullable ChatChannel<? extends ChatMessage<?>> chatChannel) {
protected void selectedChannelChanged(@Nullable ChatChannel<? extends ChatMessage> chatChannel) {
UIThread.run(() -> {
model.selectedChannelProperty().set(chatChannel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class BaseChatModel extends NavigationModel {
private final StringProperty channelTitle = new SimpleStringProperty("");
private final StringProperty channelDescription = new SimpleStringProperty("");
private final StringProperty channelIconId = new SimpleStringProperty("");
private final ObjectProperty<ChatChannel<? extends ChatMessage<?>>> selectedChannel = new SimpleObjectProperty<>();
private final ObjectProperty<ChatChannel<? extends ChatMessage>> selectedChannel = new SimpleObjectProperty<>();
private final ObjectProperty<Pane> chatUserDetailsRoot = new SimpleObjectProperty<>();
private final BooleanProperty sideBarVisible = new SimpleBooleanProperty();
private final BooleanProperty sideBarChanged = new SimpleBooleanProperty();
Expand Down Expand Up @@ -75,11 +75,11 @@ public BaseChatModel(ChatChannelDomain chatChannelDomain) {
}

@Nullable
public ChatChannel<? extends ChatMessage<?>> getSelectedChannel() {
public ChatChannel<? extends ChatMessage> getSelectedChannel() {
return selectedChannel.get();
}

public ObjectProperty<ChatChannel<? extends ChatMessage<?>>> selectedChannelProperty() {
public ObjectProperty<ChatChannel<? extends ChatMessage>> selectedChannelProperty() {
return selectedChannel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void onSelected(NavigationTarget navigationTarget) {
.filter(Objects::nonNull)
.filter(item -> item.getNavigationTarget().equals(navigationTarget))
.findFirst()
.<ChatChannel<? extends ChatMessage<?>>>map(ChannelTabButtonModel::getChatChannel)
.<ChatChannel<? extends ChatMessage>>map(ChannelTabButtonModel::getChatChannel)
.ifPresent(chatChannelSelectionService::selectChannel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import bisq.chat.bisqeasy.open_trades.BisqEasyOpenTradeChannel;
import bisq.chat.common.CommonPublicChatChannel;
import bisq.chat.pub.PublicChatChannel;
import bisq.chat.reactions.ChatMessageReaction;
import bisq.chat.two_party.TwoPartyPrivateChatChannel;
import bisq.common.observable.Pin;
import bisq.desktop.ServiceProvider;
Expand Down Expand Up @@ -108,11 +107,11 @@ public void enableChatDialog(boolean isEnabled) {
model.getChatDialogEnabled().set(isEnabled);
}

public void setSearchPredicate(Predicate<? super ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>>> predicate) {
public void setSearchPredicate(Predicate<? super ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>> predicate) {
chatMessagesListController.setSearchPredicate(predicate);
}

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

Expand Down Expand Up @@ -154,7 +153,7 @@ public void onDeactivate() {
// Handlers passed to list view component
///////////////////////////////////////////////////////////////////////////////////////////////////

private void replyHandler(ChatMessage<?> chatMessage) {
private void replyHandler(ChatMessage chatMessage) {
if (!chatMessage.isMyMessage(userIdentityService)) {
citationBlock.reply(chatMessage);
// To ensure that we trigger an update we set it to null first (and don't use a
Expand All @@ -164,7 +163,7 @@ private void replyHandler(ChatMessage<?> chatMessage) {
}
}

private void showChatUserDetailsHandler(ChatMessage<?> chatMessage) {
private void showChatUserDetailsHandler(ChatMessage chatMessage) {
model.setSelectedChatMessage(chatMessage);
userProfileService.findUserProfile(chatMessage.getAuthorUserProfileId())
.ifPresent(openUserProfileSidebarHandler);
Expand Down Expand Up @@ -232,7 +231,7 @@ private void applyUserProfileOrChannelChange() {
}


protected void selectedChannelChanged(ChatChannel<? extends ChatMessage<?>> chatChannel) {
protected void selectedChannelChanged(ChatChannel<? extends ChatMessage> chatChannel) {
UIThread.run(() -> {
model.getSelectedChannel().set(chatChannel);
applyUserProfileOrChannelChange();
Expand All @@ -245,7 +244,7 @@ private void doSendMessage(String text) {
return;
}

ChatChannel<? extends ChatMessage<?>> chatChannel = model.getSelectedChannel().get();
ChatChannel<? extends ChatMessage> chatChannel = model.getSelectedChannel().get();
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
Optional<Citation> citation = citationBlock.getCitation();

Expand Down Expand Up @@ -293,9 +292,8 @@ private void maybeSwitchUserProfile() {
}

private List<UserIdentity> getMyUserProfilesInChannel() {
Comparator<ChatMessage<?>> dateComparator = Comparator.comparing(ChatMessage::getDate);
return model.getSelectedChannel().get().getChatMessages().stream()
.sorted(dateComparator.reversed())
.sorted(Comparator.comparing(ChatMessage::getDate).reversed())
.map(ChatMessage::getAuthorUserProfileId)
.map(userIdentityService::findUserIdentity)
.filter(Optional::isPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Getter
public class ChatMessageContainerModel implements bisq.desktop.common.view.Model {
private final ChatChannelDomain chatChannelDomain;
private final ObjectProperty<ChatChannel<? extends ChatMessage<?>>> selectedChannel = new SimpleObjectProperty<>();
private final ObjectProperty<ChatChannel<? extends ChatMessage>> selectedChannel = new SimpleObjectProperty<>();
private final StringProperty textInput = new SimpleStringProperty("");
private final BooleanProperty userProfileSelectionVisible = new SimpleBooleanProperty();
private final ObjectProperty<Boolean> focusInputTextField = new SimpleObjectProperty<>();
Expand All @@ -24,7 +24,7 @@ public class ChatMessageContainerModel implements bisq.desktop.common.view.Model
private final IntegerProperty caretPosition = new SimpleIntegerProperty();
@Nullable
@Setter
private ChatMessage<?> selectedChatMessage;
private ChatMessage selectedChatMessage;

public ChatMessageContainerModel(ChatChannelDomain chatChannelDomain) {
this.chatChannelDomain = chatChannelDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import bisq.chat.ChatChannel;
import bisq.chat.ChatMessage;
import bisq.chat.reactions.ChatMessageReaction;
import bisq.desktop.main.content.bisq_easy.open_trades.MyProtocolLogMessageBox;
import bisq.desktop.main.content.bisq_easy.open_trades.PeerProtocolLogMessageBox;
import bisq.desktop.main.content.chat.message_container.list.message_box.LeaveChatMessageBox;
Expand All @@ -41,17 +40,17 @@

@Slf4j
final class ChatMessageListCellFactory
implements Callback<ListView<ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>>>,
ListCell<ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>>>> {
implements Callback<ListView<ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>>,
ListCell<ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>>> {
private final ChatMessagesListController controller;

public ChatMessageListCellFactory(ChatMessagesListController controller) {
this.controller = controller;
}

@Override
public ListCell<ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>>> call(
ListView<ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>>> list) {
public ListCell<ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>> call(
ListView<ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>> list) {
return new ListCell<>() {
private final static double CHAT_BOX_MAX_WIDTH = 1200;
private final static String STYLE_CLASS_WITHOUT_SCROLLBAR = "chat-message-list-cell-wo-scrollbar";
Expand All @@ -68,7 +67,7 @@ public ChatMessageListCellFactory(ChatMessagesListController controller) {
}

@Override
public void updateItem(final ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>> item,
public void updateItem(final ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>> item,
boolean empty) {
super.updateItem(item, empty);

Expand Down Expand Up @@ -126,8 +125,8 @@ private String getMessageStyleClass(double listWidth, double cellWidth) {
};
}

private MessageBox createMessage(ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>> item,
ListView<ChatMessageListItem<? extends ChatMessageReaction, ? extends ChatMessage<?>, ? extends ChatChannel<? extends ChatMessage<?>>>> list) {
private MessageBox createMessage(ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>> item,
ListView<ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>> list) {
if (item.isLeaveChatMessage()) {
return new LeaveChatMessageBox(item, controller);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
@Slf4j
@Getter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public final class ChatMessageListItem<R extends ChatMessageReaction, M extends ChatMessage<R>, C extends ChatChannel<M>>
implements Comparable<ChatMessageListItem<R, M, C>> {
public final class ChatMessageListItem<M extends ChatMessage, C extends ChatChannel<M>> implements Comparable<ChatMessageListItem<M, C>> {
private static final List<Reaction> REACTION_DISPLAY_ORDER = Arrays.asList(Reaction.THUMBS_UP, Reaction.THUMBS_DOWN,
Reaction.HAPPY, Reaction.LAUGH, Reaction.HEART, Reaction.PARTY);

Expand Down Expand Up @@ -272,8 +271,7 @@ public void clear() {

@Override
public int compareTo(ChatMessageListItem o) {
Comparator<ChatMessage<?>> dateComparator = Comparator.comparingLong(ChatMessage::getDate);
return dateComparator.compare(this.getChatMessage(), o.getChatMessage());
return Comparator.comparingLong(ChatMessage::getDate).compare(this.getChatMessage(), o.getChatMessage());
}

public boolean match(String filterString) {
Expand Down
Loading

0 comments on commit 36c45e8

Please sign in to comment.