From f85fba02f87fc66c272e3dea53d743aec3bfb8d6 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 22 Dec 2022 18:58:17 -0500 Subject: [PATCH 01/15] Use channelId for lookup for existing channels in mediatorCreatesNewChannel and traderCreatesNewChannel. Refactor createChannelId method. --- .../main/java/bisq/chat/channel/PrivateChannel.java | 12 +++++++----- .../chat/discuss/priv/PrivateDiscussionChannel.java | 7 ++++--- .../bisq/chat/events/priv/PrivateEventsChannel.java | 7 ++++--- .../chat/support/priv/PrivateSupportChannel.java | 7 ++++--- .../bisq/chat/trade/priv/PrivateTradeChannel.java | 13 ++++++++----- .../chat/trade/priv/PrivateTradeChannelService.java | 10 +++++----- 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index ebf8fd2936..0f6a0e8eeb 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -19,6 +19,7 @@ import bisq.chat.message.PrivateChatMessage; import bisq.common.data.ByteArray; +import bisq.common.data.Pair; import bisq.common.observable.ObservableArray; import bisq.user.identity.UserIdentity; import bisq.user.profile.UserProfile; @@ -34,12 +35,13 @@ @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) public abstract class PrivateChannel extends Channel { - public static String createChannelId(String peersId, String myId) { - // Need to have an ordering here, otherwise there would be 2 channelIds for the same participants - if (peersId.compareTo(myId) < 0) { - return peersId + "-" + myId; + public static String createChannelId(Pair userIds) { + String userId1 = userIds.getFirst(); + String userId2 = userIds.getSecond(); + if (userId1.compareTo(userId2) < 0) { + return userId1 + "-" + userId2; } else { - return myId + "-" + peersId; + return userId2 + "-" + userId1; } } diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java index d4d37c8cbb..a8db761657 100644 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java +++ b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java @@ -19,6 +19,7 @@ import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; +import bisq.common.data.Pair; import bisq.user.identity.UserIdentity; import bisq.user.profile.UserProfile; import lombok.EqualsAndHashCode; @@ -36,10 +37,10 @@ public final class PrivateDiscussionChannel extends PrivateChannel { private final UserProfile peer; - public PrivateDiscussionChannel(UserProfile peer, UserIdentity myProfile) { - this(PrivateChannel.createChannelId(peer.getId(), myProfile.getId()), + public PrivateDiscussionChannel(UserProfile peer, UserIdentity myUserIdentity) { + this(PrivateChannel.createChannelId(new Pair<>(peer.getId(), myUserIdentity.getId())), peer, - myProfile, + myUserIdentity, new ArrayList<>(), ChannelNotificationType.ALL); } diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java index e2d40a78f3..7d7f788aab 100644 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java +++ b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java @@ -19,6 +19,7 @@ import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; +import bisq.common.data.Pair; import bisq.user.identity.UserIdentity; import bisq.user.profile.UserProfile; import lombok.EqualsAndHashCode; @@ -36,10 +37,10 @@ public final class PrivateEventsChannel extends PrivateChannel { private final UserProfile peer; - public PrivateEventsChannel(UserProfile peer, UserIdentity myProfile) { - this(PrivateChannel.createChannelId(peer.getId(), myProfile.getId()), + public PrivateEventsChannel(UserProfile peer, UserIdentity myUserIdentity) { + this(PrivateChannel.createChannelId(new Pair<>(peer.getId(), myUserIdentity.getId())), peer, - myProfile, + myUserIdentity, new ArrayList<>(), ChannelNotificationType.ALL); } diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java index 67d15fe51e..2a387bc398 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java +++ b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java @@ -19,6 +19,7 @@ import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; +import bisq.common.data.Pair; import bisq.user.identity.UserIdentity; import bisq.user.profile.UserProfile; import lombok.EqualsAndHashCode; @@ -36,10 +37,10 @@ public final class PrivateSupportChannel extends PrivateChannel { private final UserProfile peer; - public PrivateSupportChannel(UserProfile peer, UserIdentity myProfile) { - this(PrivateChannel.createChannelId(peer.getId(), myProfile.getId()), + public PrivateSupportChannel(UserProfile peer, UserIdentity myUserIdentity) { + this(PrivateChannel.createChannelId(new Pair<>(peer.getId(), myUserIdentity.getId())), peer, - myProfile, + myUserIdentity, new ArrayList<>(), ChannelNotificationType.ALL); } diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index 49f591a65a..7bb0982394 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -19,6 +19,7 @@ import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; +import bisq.common.data.Pair; import bisq.common.observable.Observable; import bisq.i18n.Res; import bisq.user.identity.UserIdentity; @@ -70,7 +71,7 @@ private PrivateTradeChannel(UserProfile peerOrTrader1, UserProfile myUserProfileOrTrader2, UserIdentity myUserIdentity, Optional mediator) { - super(PrivateChannel.createChannelId(peerOrTrader1.getId(), myUserProfileOrTrader2.getId()), + super(PrivateChannel.createChannelId(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), myUserIdentity, new ArrayList<>(), ChannelNotificationType.ALL); @@ -158,10 +159,12 @@ public String getDisplayString() { } public String getChannelSelectionDisplayString() { - if (isMediator()) { - return peerOrTrader1.getUserName() + ", " + myUserProfileOrTrader2.getUserName(); - } else if (mediator.isPresent() && inMediation.get()) { - return peerOrTrader1.getUserName() + ", " + mediator.get().getUserName(); + if (inMediation.get()) { + if (isMediator()) { + return peerOrTrader1.getUserName() + ", " + myUserProfileOrTrader2.getUserName(); + } else { + return peerOrTrader1.getUserName() + ", " + mediator.orElseThrow().getUserName(); + } } else { return peerOrTrader1.getUserName(); } diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index 5a59a290ea..626ab75cbe 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -19,6 +19,7 @@ import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.Quotation; +import bisq.common.data.Pair; import bisq.common.observable.ObservableArray; import bisq.common.util.CompletableFutureUtils; import bisq.common.util.StringUtils; @@ -95,10 +96,9 @@ protected PrivateTradeChannel createNewChannel(UserProfile peer, UserIdentity my } public PrivateTradeChannel mediatorCreatesNewChannel(UserIdentity myUserIdentity, UserProfile trader1, UserProfile trader2) { + String channelId = PrivateTradeChannel.createChannelId(new Pair<>(trader1.getId(), trader2.getId())); Optional existingChannel = getChannels().stream() - .filter(channel -> channel.getMyUserIdentity().equals(myUserIdentity) && - channel.getPeerOrTrader1().equals(trader1) && - channel.getMyUserProfileOrTrader2().equals(trader1)) + .filter(channel -> channel.getId().equals(channelId)) .findAny(); if (existingChannel.isPresent()) { return existingChannel.get(); @@ -111,9 +111,9 @@ public PrivateTradeChannel mediatorCreatesNewChannel(UserIdentity myUserIdentity } public PrivateTradeChannel traderCreatesNewChannel(UserIdentity myUserIdentity, UserProfile peersUserProfile, Optional mediator) { + String channelId = PrivateTradeChannel.createChannelId(new Pair<>(myUserIdentity.getUserProfile().getId(), peersUserProfile.getId())); Optional existingChannel = getChannels().stream() - .filter(channel -> channel.getMyUserIdentity().equals(myUserIdentity) && - channel.getPeer().equals(peersUserProfile)) + .filter(channel -> channel.getId().equals(channelId)) .findAny(); if (existingChannel.isPresent()) { return existingChannel.get(); From 2ede60c510d2c76c77a99c6d645fb5c8fd4c2416 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 11:48:56 -0500 Subject: [PATCH 02/15] Add support for leaving channel (WIP) --- .../main/java/bisq/chat/channel/Channel.java | 29 ++- .../bisq/chat/channel/PrivateChannel.java | 6 +- .../chat/channel/PrivateChannelService.java | 30 ++- .../java/bisq/chat/channel/PublicChannel.java | 5 +- .../priv/PrivateDiscussionChannel.java | 3 +- .../priv/PrivateDiscussionChannelService.java | 7 +- .../priv/PrivateDiscussionChatMessage.java | 9 +- .../discuss/pub/PublicDiscussionChannel.java | 3 +- .../pub/PublicDiscussionChatMessage.java | 5 + .../events/priv/PrivateEventsChannel.java | 3 +- .../priv/PrivateEventsChannelService.java | 7 +- .../events/priv/PrivateEventsChatMessage.java | 9 +- .../chat/events/pub/PublicEventsChannel.java | 3 +- .../events/pub/PublicEventsChatMessage.java | 5 + .../java/bisq/chat/message/ChatMessage.java | 4 + .../java/bisq/chat/message/MessageType.java | 36 +++ .../bisq/chat/message/PrivateChatMessage.java | 2 + .../bisq/chat/message/PublicChatMessage.java | 3 +- .../support/priv/PrivateSupportChannel.java | 3 +- .../priv/PrivateSupportChannelService.java | 7 +- .../priv/PrivateSupportChatMessage.java | 9 +- .../support/pub/PublicSupportChannel.java | 3 +- .../support/pub/PublicSupportChatMessage.java | 5 + .../chat/trade/priv/PrivateTradeChannel.java | 12 +- .../priv/PrivateTradeChannelService.java | 49 +++- .../trade/priv/PrivateTradeChatMessage.java | 29 ++- .../chat/trade/pub/PublicTradeChannel.java | 3 +- .../trade/pub/PublicTradeChatMessage.java | 5 + chat/src/main/proto/chat.proto | 7 +- .../channels/PrivateChannelSelection.java | 229 +++++++++++++----- .../channels/PublicTradeChannelSelection.java | 3 - .../content/chat/sidebar/ChannelSidebar.java | 7 +- .../components/ChatMessagesComponent.java | 8 +- .../overview/TradeOverviewBaseController.java | 6 +- i18n/src/main/resources/default.properties | 15 +- .../bisq/user/profile/UserProfileService.java | 14 +- 36 files changed, 428 insertions(+), 155 deletions(-) create mode 100644 chat/src/main/java/bisq/chat/message/MessageType.java diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index ebc16ecd97..e11f9461c6 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -17,15 +17,18 @@ package bisq.chat.channel; +import bisq.chat.ChannelKind; import bisq.chat.discuss.priv.PrivateDiscussionChannel; import bisq.chat.discuss.pub.PublicDiscussionChannel; import bisq.chat.events.priv.PrivateEventsChannel; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.support.priv.PrivateSupportChannel; import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; +import bisq.common.data.Pair; import bisq.common.observable.Observable; import bisq.common.observable.ObservableArray; import bisq.common.proto.Proto; @@ -34,7 +37,8 @@ import lombok.Getter; import lombok.ToString; -import java.util.Collection; +import java.util.*; +import java.util.stream.Collectors; @ToString @Getter @@ -42,10 +46,12 @@ public abstract class Channel implements Proto { @EqualsAndHashCode.Include protected final String id; + private final ChannelKind channelKind; protected final Observable channelNotificationType = new Observable<>(); - public Channel(String id, ChannelNotificationType channelNotificationType) { + public Channel(String id, ChannelNotificationType channelNotificationType, ChannelKind channelKind) { this.id = id; + this.channelKind = channelKind; this.channelNotificationType.set(channelNotificationType); } @@ -105,4 +111,23 @@ public static Channel fromProto(bisq.chat.protobuf.Channe public String getDisplayString() { return id; } + + public Set getMembers() { + Map> chatMessagesByAuthor = new HashMap<>(); + getChatMessages().forEach(chatMessage -> { + String authorId = chatMessage.getAuthorId(); + chatMessagesByAuthor.putIfAbsent(authorId, new ArrayList<>()); + chatMessagesByAuthor.get(authorId).add(chatMessage); + }); + + return chatMessagesByAuthor.entrySet().stream().map(entry -> { + List chatMessages = entry.getValue(); + chatMessages.sort(Comparator.comparing(chatMessage -> new Date(chatMessage.getDate()))); + ChatMessage lastChatMessage = chatMessages.get(chatMessages.size() - 1); + return new Pair<>(entry.getKey(), lastChatMessage); + }) + .filter(pair -> pair.getSecond().getMessageType() != MessageType.LEAVE) + .map(Pair::getFirst) + .collect(Collectors.toSet()); + } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index 0f6a0e8eeb..125b21b6cb 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -17,6 +17,7 @@ package bisq.chat.channel; +import bisq.chat.ChannelKind; import bisq.chat.message.PrivateChatMessage; import bisq.common.data.ByteArray; import bisq.common.data.Pair; @@ -53,8 +54,9 @@ public static String createChannelId(Pair userIds) { public PrivateChannel(String id, UserIdentity myUserIdentity, List chatMessages, - ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType); + ChannelNotificationType channelNotificationType, + ChannelKind channelKind) { + super(id, channelNotificationType, channelKind); this.myUserIdentity = myUserIdentity; this.chatMessages.addAll(chatMessages); diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index ec3d1da14e..11f62428da 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -17,9 +17,11 @@ package bisq.chat.channel; +import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; +import bisq.i18n.Res; import bisq.network.NetworkId; import bisq.network.NetworkIdWithKeyPair; import bisq.network.NetworkService; @@ -78,10 +80,24 @@ public Optional maybeCreateAndAddChannel(UserProfile peer) { .flatMap(myUserIdentity -> maybeCreateAndAddChannel(peer, myUserIdentity.getId())); } + protected CompletableFuture sendLeaveMessage(C channel) { + return sendPrivateChatMessage(Res.get("social.privateChannel.leave.message", channel.getMyUserIdentity().getUserProfile().getUserName()), + Optional.empty(), + channel, + MessageType.LEAVE); + } + public CompletableFuture sendPrivateChatMessage(String text, Optional quotedMessage, C channel) { - return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer()); + return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer(), MessageType.TEXT); + } + + public CompletableFuture sendPrivateChatMessage(String text, + Optional quotedMessage, + C channel, + MessageType messageType) { + return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer(), messageType); } protected CompletableFuture sendPrivateChatMessage(String messageId, @@ -89,7 +105,8 @@ protected CompletableFuture sendPrivateChatMes Optional quotedMessage, C channel, UserIdentity senderIdentity, - UserProfile receiver) { + UserProfile receiver, + MessageType messageType) { M chatMessage = createNewPrivateChatMessage(messageId, channel, senderIdentity.getUserProfile(), @@ -97,7 +114,8 @@ protected CompletableFuture sendPrivateChatMes text, quotedMessage, new Date().getTime(), - false); + false, + messageType); addMessage(chatMessage, channel); NetworkId receiverNetworkId = receiver.getNetworkId(); NetworkIdWithKeyPair senderNetworkIdWithKeyPair = senderIdentity.getNodeIdAndKeyPair(); @@ -149,11 +167,11 @@ protected abstract M createNewPrivateChatMessage(String messageId, String text, Optional quotedMessage, long time, - boolean wasEdited); + boolean wasEdited, + MessageType messageType); protected void processMessage(M message) { - if (!userIdentityService.isUserIdentityPresent(message.getAuthorId()) && - proofOfWorkService.verify(message.getSender().getProofOfWork())) { + if (!userIdentityService.isUserIdentityPresent(message.getAuthorId())) { findChannel(message.getChannelId()) .or(() -> maybeCreateAndAddChannel(message.getSender(), message.getReceiversId())) .ifPresent(channel -> addMessage(message, channel)); diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannel.java b/chat/src/main/java/bisq/chat/channel/PublicChannel.java index b4efff17ee..ee38b0d267 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannel.java @@ -17,6 +17,7 @@ package bisq.chat.channel; +import bisq.chat.ChannelKind; import bisq.chat.message.PublicChatMessage; import bisq.common.observable.ObservableArray; import lombok.EqualsAndHashCode; @@ -30,7 +31,7 @@ public abstract class PublicChannel extends Channel // We do not persist the messages as they are persisted in the P2P data store. protected transient final ObservableArray chatMessages = new ObservableArray<>(); - public PublicChannel(String id, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType); + public PublicChannel(String id, ChannelNotificationType channelNotificationType, ChannelKind channelKind) { + super(id, channelNotificationType, channelKind); } } diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java index a8db761657..b5515971c7 100644 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java +++ b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java @@ -17,6 +17,7 @@ package bisq.chat.discuss.priv; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -50,7 +51,7 @@ private PrivateDiscussionChannel(String id, UserIdentity myProfile, List chatMessages, ChannelNotificationType channelNotificationType) { - super(id, myProfile, chatMessages, channelNotificationType); + super(id, myProfile, chatMessages, channelNotificationType, ChannelKind.DISCUSSION); this.peer = peer; } diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java index 4b67fc093b..a34681d9e0 100644 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java +++ b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java @@ -18,6 +18,7 @@ package bisq.chat.discuss.priv; import bisq.chat.channel.PrivateChannelService; +import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; import bisq.network.NetworkService; @@ -64,7 +65,8 @@ protected PrivateDiscussionChatMessage createNewPrivateChatMessage(String messag String text, Optional quotedMessage, long time, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { return new PrivateDiscussionChatMessage(messageId, channel.getId(), sender, @@ -72,7 +74,8 @@ protected PrivateDiscussionChatMessage createNewPrivateChatMessage(String messag text, quotedMessage, new Date().getTime(), - wasEdited); + wasEdited, + messageType); } @Override diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java index 0e307a999d..0a683650e9 100644 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java +++ b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.discuss.priv; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; import bisq.network.p2p.services.data.storage.MetaData; @@ -42,7 +43,8 @@ public PrivateDiscussionChatMessage(String messageId, String text, Optional quotedMessage, long date, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { super(messageId, channelId, sender, @@ -51,6 +53,7 @@ public PrivateDiscussionChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, new MetaData(ChatMessage.TTL, 100000, PrivateDiscussionChatMessage.class.getSimpleName())); } @@ -62,8 +65,9 @@ private PrivateDiscussionChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, metaData); + super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); } @Override @@ -95,6 +99,7 @@ public static PrivateDiscussionChatMessage fromProto(bisq.chat.protobuf.ChatMess quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java b/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java index e2f6efe423..a6d1cd0299 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java +++ b/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java @@ -17,6 +17,7 @@ package bisq.chat.discuss.pub; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -66,7 +67,7 @@ private PublicDiscussionChannel(String id, String channelAdminId, List channelModeratorIds, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType); + super(id, channelNotificationType, ChannelKind.DISCUSSION); this.channelName = channelName; this.description = description; diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java b/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java index cd829b92ca..1a9e44c290 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java +++ b/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.discuss.pub; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; @@ -45,6 +46,7 @@ public PublicDiscussionChatMessage(String channelId, quotedMessage, date, wasEdited, + MessageType.TEXT, new MetaData(ChatMessage.TTL, 100000, PublicDiscussionChatMessage.class.getSimpleName())); } @@ -55,6 +57,7 @@ private PublicDiscussionChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { super(messageId, channelId, @@ -63,6 +66,7 @@ private PublicDiscussionChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, metaData); } @@ -82,6 +86,7 @@ public static PublicDiscussionChatMessage fromProto(bisq.chat.protobuf.ChatMessa quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java index 7d7f788aab..a1d488b614 100644 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java +++ b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java @@ -17,6 +17,7 @@ package bisq.chat.events.priv; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -50,7 +51,7 @@ private PrivateEventsChannel(String id, UserIdentity myProfile, List chatMessages, ChannelNotificationType channelNotificationType) { - super(id, myProfile, chatMessages, channelNotificationType); + super(id, myProfile, chatMessages, channelNotificationType, ChannelKind.EVENTS); this.peer = peer; } diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java index 1658589d15..02001089fa 100644 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java +++ b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java @@ -18,6 +18,7 @@ package bisq.chat.events.priv; import bisq.chat.channel.PrivateChannelService; +import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; import bisq.network.NetworkService; @@ -64,7 +65,8 @@ protected PrivateEventsChatMessage createNewPrivateChatMessage(String messageId, String text, Optional quotedMessage, long time, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { return new PrivateEventsChatMessage(messageId, channel.getId(), sender, @@ -72,7 +74,8 @@ protected PrivateEventsChatMessage createNewPrivateChatMessage(String messageId, text, quotedMessage, new Date().getTime(), - wasEdited); + wasEdited, + messageType); } @Override diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java index eb640daa68..8d54f64114 100644 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java +++ b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.events.priv; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; import bisq.network.p2p.services.data.storage.MetaData; @@ -42,7 +43,8 @@ public PrivateEventsChatMessage(String messageId, String text, Optional quotedMessage, long date, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { super(messageId, channelId, sender, @@ -51,6 +53,7 @@ public PrivateEventsChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, new MetaData(ChatMessage.TTL, 100000, PrivateEventsChatMessage.class.getSimpleName())); } @@ -62,8 +65,9 @@ private PrivateEventsChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, metaData); + super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); } @Override @@ -95,6 +99,7 @@ public static PrivateEventsChatMessage fromProto(bisq.chat.protobuf.ChatMessage quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java index bf9c32cb77..bd055ae4b5 100644 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java +++ b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java @@ -17,6 +17,7 @@ package bisq.chat.events.pub; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -66,7 +67,7 @@ private PublicEventsChannel(String id, String channelAdminId, List channelModeratorIds, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType); + super(id, channelNotificationType, ChannelKind.EVENTS); this.channelName = channelName; this.description = description; diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java index c6ce4e19a4..fdf378ed22 100644 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java +++ b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.events.pub; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; @@ -45,6 +46,7 @@ public PublicEventsChatMessage(String channelId, quotedMessage, date, wasEdited, + MessageType.TEXT, new MetaData(ChatMessage.TTL, 100000, PublicEventsChatMessage.class.getSimpleName())); } @@ -55,6 +57,7 @@ private PublicEventsChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { super(messageId, channelId, @@ -63,6 +66,7 @@ private PublicEventsChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, metaData); } @@ -82,6 +86,7 @@ public static PublicEventsChatMessage fromProto(bisq.chat.protobuf.ChatMessage b quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 89b1eeac05..07f4a94d6e 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -55,6 +55,7 @@ public abstract class ChatMessage implements Proto { protected final Optional quotation; protected final long date; protected final boolean wasEdited; + protected final MessageType messageType; protected final MetaData metaData; protected ChatMessage(String messageId, @@ -64,6 +65,7 @@ protected ChatMessage(String messageId, Optional quotation, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { this.messageId = messageId; this.channelId = channelId; @@ -72,6 +74,7 @@ protected ChatMessage(String messageId, this.quotation = quotation; this.date = date; this.wasEdited = wasEdited; + this.messageType = messageType; this.metaData = metaData; } @@ -86,6 +89,7 @@ public bisq.chat.protobuf.ChatMessage.Builder getChatMessageBuilder() { .setAuthorId(authorId) .setDate(date) .setWasEdited(wasEdited) + .setMessageType(messageType.toProto()) .setMetaData(metaData.toProto()); quotation.ifPresent(quotedMessage -> builder.setQuotation(quotedMessage.toProto())); optionalText.ifPresent(builder::setText); diff --git a/chat/src/main/java/bisq/chat/message/MessageType.java b/chat/src/main/java/bisq/chat/message/MessageType.java new file mode 100644 index 0000000000..9e3a2de2e2 --- /dev/null +++ b/chat/src/main/java/bisq/chat/message/MessageType.java @@ -0,0 +1,36 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.chat.message; + +import bisq.common.proto.ProtoEnum; +import bisq.common.util.ProtobufUtils; + +public enum MessageType implements ProtoEnum { + TEXT, + LEAVE; + + @Override + public bisq.chat.protobuf.MessageType toProto() { + return bisq.chat.protobuf.MessageType.valueOf(name()); + } + + public static MessageType fromProto(bisq.chat.protobuf.MessageType proto) { + return ProtobufUtils.enumFromProto(MessageType.class, proto.name()); + } + +} diff --git a/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java b/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java index be0b544a3c..87426c447e 100644 --- a/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java @@ -45,6 +45,7 @@ protected PrivateChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { super(messageId, channelId, @@ -53,6 +54,7 @@ protected PrivateChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, metaData); this.receiversId = receiversId; this.sender = sender; diff --git a/chat/src/main/java/bisq/chat/message/PublicChatMessage.java b/chat/src/main/java/bisq/chat/message/PublicChatMessage.java index 9bea46ad88..3b66c7fac7 100644 --- a/chat/src/main/java/bisq/chat/message/PublicChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PublicChatMessage.java @@ -40,8 +40,9 @@ protected PublicChatMessage(String messageId, Optional quotation, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { - super(messageId, channelId, authorId, text, quotation, date, wasEdited, metaData); + super(messageId, channelId, authorId, text, quotation, date, wasEdited, messageType, metaData); } @Override diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java index 2a387bc398..51f1ed0398 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java +++ b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java @@ -17,6 +17,7 @@ package bisq.chat.support.priv; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -50,7 +51,7 @@ private PrivateSupportChannel(String id, UserIdentity myProfile, List chatMessages, ChannelNotificationType channelNotificationType) { - super(id, myProfile, chatMessages, channelNotificationType); + super(id, myProfile, chatMessages, channelNotificationType, ChannelKind.SUPPORT); this.peer = peer; } diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java index 225f4db2c1..52c9eb437e 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java +++ b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java @@ -18,6 +18,7 @@ package bisq.chat.support.priv; import bisq.chat.channel.PrivateChannelService; +import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; import bisq.network.NetworkService; @@ -64,7 +65,8 @@ protected PrivateSupportChatMessage createNewPrivateChatMessage(String messageId String text, Optional quotedMessage, long time, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { return new PrivateSupportChatMessage(messageId, channel.getId(), sender, @@ -72,7 +74,8 @@ protected PrivateSupportChatMessage createNewPrivateChatMessage(String messageId text, quotedMessage, new Date().getTime(), - wasEdited); + wasEdited, + messageType); } @Override diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java index 844518b89c..87466443cb 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java +++ b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.support.priv; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; import bisq.network.p2p.services.data.storage.MetaData; @@ -42,7 +43,8 @@ public PrivateSupportChatMessage(String messageId, String text, Optional quotedMessage, long date, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { super(messageId, channelId, sender, @@ -51,6 +53,7 @@ public PrivateSupportChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, new MetaData(ChatMessage.TTL, 100000, PrivateSupportChatMessage.class.getSimpleName())); } @@ -62,8 +65,9 @@ private PrivateSupportChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, metaData); + super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); } @Override @@ -95,6 +99,7 @@ public static PrivateSupportChatMessage fromProto(bisq.chat.protobuf.ChatMessage quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java index 0674312188..c051a716e0 100644 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java +++ b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java @@ -17,6 +17,7 @@ package bisq.chat.support.pub; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -66,7 +67,7 @@ private PublicSupportChannel(String id, String channelAdminId, List channelModeratorIds, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType); + super(id, channelNotificationType, ChannelKind.SUPPORT); this.channelName = channelName; this.description = description; diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java index dc0c282450..83eddc0645 100644 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java +++ b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.support.pub; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; @@ -45,6 +46,7 @@ public PublicSupportChatMessage(String channelId, quotedMessage, date, wasEdited, + MessageType.TEXT, new MetaData(ChatMessage.TTL, 100000, PublicSupportChatMessage.class.getSimpleName())); } @@ -55,6 +57,7 @@ private PublicSupportChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { super(messageId, channelId, @@ -63,6 +66,7 @@ private PublicSupportChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, metaData); } @@ -82,6 +86,7 @@ public static PublicSupportChatMessage fromProto(bisq.chat.protobuf.ChatMessage quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index 7bb0982394..2eaefd1760 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -17,6 +17,7 @@ package bisq.chat.trade.priv; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -71,14 +72,13 @@ private PrivateTradeChannel(UserProfile peerOrTrader1, UserProfile myUserProfileOrTrader2, UserIdentity myUserIdentity, Optional mediator) { - super(PrivateChannel.createChannelId(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), + this(PrivateChannel.createChannelId(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), + peerOrTrader1, + myUserProfileOrTrader2, myUserIdentity, + mediator, new ArrayList<>(), ChannelNotificationType.ALL); - this.peerOrTrader1 = peerOrTrader1; - this.myUserProfileOrTrader2 = myUserProfileOrTrader2; - this.myUserIdentity = myUserIdentity; - this.mediator = mediator; } private PrivateTradeChannel(String id, @@ -88,7 +88,7 @@ private PrivateTradeChannel(String id, Optional mediator, List chatMessages, ChannelNotificationType channelNotificationType) { - super(id, myUserIdentity, chatMessages, channelNotificationType); + super(id, myUserIdentity, chatMessages, channelNotificationType, ChannelKind.TRADE); this.peerOrTrader1 = peerOrTrader1; this.myUserProfileOrTrader2 = myUserProfileOrTrader2; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index 626ab75cbe..1f1f59cbf9 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -18,6 +18,7 @@ package bisq.chat.trade.priv; import bisq.chat.channel.PrivateChannelService; +import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; import bisq.common.data.Pair; import bisq.common.observable.ObservableArray; @@ -74,7 +75,8 @@ protected PrivateTradeChatMessage createNewPrivateChatMessage(String messageId, String text, Optional quotedMessage, long time, - boolean wasEdited) { + boolean wasEdited, + MessageType messageType) { // We send the mediator only in the first message to the peer. Optional mediator = channel.getChatMessages().isEmpty() ? channel.getMediator() : Optional.empty(); return new PrivateTradeChatMessage( @@ -86,7 +88,8 @@ protected PrivateTradeChatMessage createNewPrivateChatMessage(String messageId, quotedMessage, new Date().getTime(), wasEdited, - mediator); + mediator, + messageType); } @Override @@ -125,6 +128,17 @@ public PrivateTradeChannel traderCreatesNewChannel(UserIdentity myUserIdentity, return channel; } + public void leaveChannel(PrivateTradeChannel channel) { + sendLeaveMessage(channel) + .whenComplete((result, throwable) -> { + if (throwable != null) { + log.warn("Sending leave channel message failed."); + } + getChannels().remove(channel); + persist(); + }); + } + @Override public ObservableArray getChannels() { return persistableStore.getChannels(); @@ -132,26 +146,33 @@ public ObservableArray getChannels() { @Override protected void processMessage(PrivateTradeChatMessage message) { - //todo is proofOfWorkService.verify needed? - if (!userIdentityService.isUserIdentityPresent(message.getAuthorId()) && - proofOfWorkService.verify(message.getSender().getProofOfWork())) { + if (!userIdentityService.isUserIdentityPresent(message.getAuthorId())) { userIdentityService.findUserIdentity(message.getReceiversId()) .flatMap(myUserIdentity -> findChannel(message.getChannelId()) - .or(() -> Optional.of(traderCreatesNewChannel(myUserIdentity, - message.getSender(), - message.getMediator())))) - .ifPresent(channel -> addMessage(message, channel)); + .or(() -> { + if (message.getMessageType() == MessageType.LEAVE) { + return Optional.empty(); + } else { + return Optional.of(traderCreatesNewChannel(myUserIdentity, + message.getSender(), + message.getMediator())); + } + })) + .ifPresent(channel -> { + addMessage(message, channel); + }); } } @Override public CompletableFuture sendPrivateChatMessage(String text, Optional quotedMessage, - PrivateTradeChannel channel) { + PrivateTradeChannel channel, + MessageType messageType) { UserIdentity myUserIdentity = channel.getMyUserIdentity(); String messageId = StringUtils.createShortUid(); if (!channel.getInMediation().get() || channel.getMediator().isEmpty()) { - return super.sendPrivateChatMessage(messageId, text, quotedMessage, channel, myUserIdentity, channel.getPeer()); + return super.sendPrivateChatMessage(messageId, text, quotedMessage, channel, myUserIdentity, channel.getPeer(), messageType); } // If mediation has been activated we send all messages to the 2 other peers UserProfile receiver1, receiver2; @@ -176,7 +197,8 @@ public CompletableFuture sendPrivateChatMessag quotedMessage, date, false, - mediator); + mediator, + messageType); CompletableFuture sendFuture1 = networkService.confidentialSend(message1, receiver1.getNetworkId(), @@ -191,7 +213,8 @@ public CompletableFuture sendPrivateChatMessag quotedMessage, date, false, - mediator); + mediator, + messageType); CompletableFuture sendFuture2 = networkService.confidentialSend(message2, receiver2.getNetworkId(), senderNodeIdAndKeyPair); diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java index d537b539b7..3ca6c67d1e 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.trade.priv; +import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; import bisq.network.p2p.services.data.storage.MetaData; @@ -44,7 +45,8 @@ public PrivateTradeChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, - Optional mediator) { + Optional mediator, + MessageType messageType) { this(messageId, channelId, sender, @@ -54,20 +56,22 @@ public PrivateTradeChatMessage(String messageId, date, wasEdited, mediator, + messageType, new MetaData(TTL, 100000, PrivateTradeChatMessage.class.getSimpleName())); } - private PrivateTradeChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - Optional mediator, - MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, metaData); + public PrivateTradeChatMessage(String messageId, + String channelId, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + Optional mediator, + MessageType messageType, + MetaData metaData) { + super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); this.mediator = mediator; } @@ -106,6 +110,7 @@ public static PrivateTradeChatMessage fromProto(bisq.chat.protobuf.ChatMessage b baseProto.getDate(), baseProto.getWasEdited(), mediator, + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData()) ); } diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index ce51f4543f..4e77176bc0 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -17,6 +17,7 @@ package bisq.chat.trade.pub; +import bisq.chat.ChannelKind; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.common.currency.Market; @@ -38,7 +39,7 @@ public PublicTradeChannel(Market market) { } private PublicTradeChannel(String id, Market market) { - super(id, ChannelNotificationType.MENTION); + super(id, ChannelNotificationType.MENTION, ChannelKind.TRADE); this.market = market; } diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java index 0be917eb2e..fde7595ecc 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java @@ -18,6 +18,7 @@ package bisq.chat.trade.pub; import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; @@ -51,6 +52,7 @@ public PublicTradeChatMessage(String channelId, quotedMessage, date, wasEdited, + MessageType.TEXT, new MetaData(ChatMessage.TTL, 100000, PublicTradeChatMessage.class.getSimpleName())); } @@ -62,6 +64,7 @@ private PublicTradeChatMessage(String messageId, Optional quotedMessage, long date, boolean wasEdited, + MessageType messageType, MetaData metaData) { super(messageId, channelId, @@ -70,6 +73,7 @@ private PublicTradeChatMessage(String messageId, quotedMessage, date, wasEdited, + messageType, metaData); this.tradeChatOffer = tradeChatOffer; } @@ -99,6 +103,7 @@ public static PublicTradeChatMessage fromProto(bisq.chat.protobuf.ChatMessage ba quotedMessage, baseProto.getDate(), baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), MetaData.fromProto(baseProto.getMetaData())); } diff --git a/chat/src/main/proto/chat.proto b/chat/src/main/proto/chat.proto index 4567e086bd..5cc7f2ee09 100644 --- a/chat/src/main/proto/chat.proto +++ b/chat/src/main/proto/chat.proto @@ -41,7 +41,8 @@ message ChatMessage { optional Quotation quotation = 5; uint64 date = 6; bool wasEdited = 7; - network.MetaData metaData = 8; + MessageType messageType = 8; + network.MetaData metaData = 9; oneof message { PrivateTradeChatMessage privateTradeChatMessage = 20; PublicTradeChatMessage publicTradeChatMessage = 21; @@ -56,6 +57,10 @@ message ChatMessage { PublicSupportChatMessage publicSupportChatMessage = 27; } } +enum MessageType { + TEXT = 0; + LEAVE = 1; +} enum ChannelNotificationType { ALL = 0; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index 0a48eb7ed9..c4d75d0dd4 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -19,6 +19,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChannelKind; +import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.discuss.priv.PrivateDiscussionChannel; @@ -35,11 +36,16 @@ import bisq.common.observable.Pin; import bisq.desktop.common.observable.FxBindings; import bisq.desktop.common.threading.UIThread; +import bisq.desktop.common.utils.Icons; +import bisq.desktop.common.utils.Transitions; +import bisq.desktop.components.containers.Spacer; import bisq.desktop.components.controls.BisqTooltip; +import bisq.desktop.components.overlay.Popup; import bisq.desktop.components.robohash.RoboHash; import bisq.i18n.Res; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import de.jensd.fx.fontawesome.AwesomeIcon; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.geometry.Insets; @@ -48,6 +54,7 @@ import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.Tooltip; +import javafx.scene.effect.ColorAdjust; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; @@ -57,6 +64,8 @@ import org.fxmisc.easybind.Subscription; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; @Slf4j public class PrivateChannelSelection extends ChannelSelection { @@ -203,6 +212,36 @@ protected void onSelected(ChannelSelection.View.ChannelItem channelItem) { public void deSelectChannel() { model.selectedChannelItem.set(null); } + + public void onLeaveChannel(PrivateChannel privateChannel) { + new Popup().warning(Res.get("social.privateChannel.leave.warning", privateChannel.getMyUserIdentity().getUserName())) + .closeButtonText(Res.get("cancel")) + .actionButtonText(Res.get("social.privateChannel.leave")) + .onAction(() -> doLeaveChannel(privateChannel)) + .show(); + } + + public void doLeaveChannel(PrivateChannel privateChannel) { + switch (privateChannel.getChannelKind()) { + case TRADE -> { + privateTradeChannelService.leaveChannel((PrivateTradeChannel) privateChannel); + } + case DISCUSSION -> { + //todo + } + case EVENTS -> { + //todo + } + case SUPPORT -> { + //todo + } + } + if (!model.sortedList.isEmpty()) { + tradeChannelSelectionService.selectChannel(model.sortedList.get(0).getChannel()); + } else { + tradeChannelSelectionService.selectChannel(null); + } + } } protected static class Model extends ChannelSelection.Model { @@ -243,11 +282,14 @@ protected String getHeadlineText() { protected ListCell getListCell() { return new ListCell<>() { private Subscription widthSubscription; + final Label removeIcon = Icons.getIcon(AwesomeIcon.MINUS_SIGN_ALT, "14"); final Label label = new Label(); final HBox hBox = new HBox(); final Tooltip tooltip = new BisqTooltip(); final ImageView roboIcon = new ImageView(); final ImageView secondaryRoboIcon = new ImageView(); + final ColorAdjust nonSelectedEffect = new ColorAdjust(); + final ColorAdjust hoverEffect = new ColorAdjust(); @Nullable private Pin inMediationPin; @@ -261,89 +303,144 @@ protected ListCell getListCell() { secondaryRoboIcon.setFitWidth(35); secondaryRoboIcon.setFitHeight(35); + HBox.setMargin(secondaryRoboIcon, new Insets(0, 0, 0, -20)); hBox.setSpacing(10); hBox.setAlignment(Pos.CENTER_LEFT); + + removeIcon.setCursor(Cursor.HAND); + removeIcon.setId("icon-label-grey"); + HBox.setMargin(removeIcon, new Insets(0, 12, 0, -20)); + + nonSelectedEffect.setSaturation(-0.4); + nonSelectedEffect.setBrightness(-0.6); + + hoverEffect.setSaturation(0.2); + hoverEffect.setBrightness(0.2); } @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PrivateChannel) { - UserProfile peer = ((PrivateChannel) item.getChannel()).getPeer(); - roboIcon.setImage(RoboHash.getImage(peer.getPubKeyHash())); - Tooltip.install(this, tooltip); - if (item.getChannel() instanceof PrivateTradeChannel) { - PrivateTradeChannel privateTradeChannel = (PrivateTradeChannel) item.getChannel(); - if (inMediationPin != null) { - inMediationPin.unbind(); - } - inMediationPin = privateTradeChannel.getInMediation().addObserver(e -> - { - UIThread.run(() -> { - hBox.getChildren().clear(); - hBox.getChildren().add(roboIcon); - - if (privateTradeChannel.getMediator().isPresent() && - privateTradeChannel.getInMediation().get()) { - if (privateTradeChannel.isMediator()) { - // We are the mediator - UserProfile trader1 = privateTradeChannel.getPeerOrTrader1(); - UserProfile trader2 = privateTradeChannel.getMyUserProfileOrTrader2(); - roboIcon.setImage(RoboHash.getImage(trader1.getPubKeyHash())); - secondaryRoboIcon.setImage(RoboHash.getImage(trader2.getPubKeyHash())); - tooltip.setText(trader1.getTooltipString() + "\n\n" + trader2.getTooltipString()); - } else { - UserProfile mediator = privateTradeChannel.getMediator().get(); - secondaryRoboIcon.setImage(RoboHash.getImage(mediator.getPubKeyHash())); - tooltip.setText(peer.getTooltipString() + "\n\n" + - Res.get("mediator") + ":\n" + mediator.getTooltipString()); - } - hBox.getChildren().add(secondaryRoboIcon); - } else { - tooltip.setText(peer.getTooltipString()); - } - label.setText(privateTradeChannel.getChannelSelectionDisplayString()); - hBox.getChildren().add(label); - if (widthSubscription != null) { - widthSubscription.unsubscribe(); - } - widthSubscription = EasyBind.subscribe(widthProperty(), w -> { - if (w.doubleValue() > 0) { - if (secondaryRoboIcon.getImage() != null) { - label.setMaxWidth(getWidth() - 120); - } else { - label.setMaxWidth(getWidth() - 75); - } - } - }); - }); - }); - } else { - hBox.getChildren().clear(); - hBox.getChildren().add(roboIcon); - label.setText(item.getDisplayString()); - tooltip.setText(peer.getTooltipString()); - hBox.getChildren().add(label); - widthSubscription = EasyBind.subscribe(widthProperty(), w -> { - if (w.doubleValue() > 0) { - label.setMaxWidth(getWidth() - 75); - } - }); - } - setGraphic(hBox); - } else { - setGraphic(null); + if (item == null || empty) { + label.setGraphic(null); + removeIcon.setOnMouseClicked(null); + hBox.setOnMouseClicked(null); + hBox.setOnMouseEntered(null); + hBox.setOnMouseExited(null); hBox.getChildren().clear(); - Tooltip.install(this, null); if (widthSubscription != null) { widthSubscription.unsubscribe(); } if (inMediationPin != null) { inMediationPin.unbind(); } + Tooltip.install(this, null); + setGraphic(null); + return; + } + + Channel channel = item.getChannel(); + if (!(channel instanceof PrivateChannel)) { + return; } + + PrivateChannel privateChannel = (PrivateChannel) item.getChannel(); + UserProfile peer = privateChannel.getPeer(); + roboIcon.setImage(RoboHash.getImage(peer.getPubKeyHash())); + Tooltip.install(this, tooltip); + List icons = new ArrayList<>(); + icons.add(roboIcon); + + if (privateChannel instanceof PrivateTradeChannel) { + PrivateTradeChannel privateTradeChannel = (PrivateTradeChannel) privateChannel; + if (inMediationPin != null) { + inMediationPin.unbind(); + } + inMediationPin = privateTradeChannel.getInMediation().addObserver(e -> + { + UIThread.run(() -> { + hBox.getChildren().clear(); + hBox.getChildren().add(roboIcon); + + if (privateTradeChannel.getMediator().isPresent() && + privateTradeChannel.getInMediation().get()) { + if (privateTradeChannel.isMediator()) { + // We are the mediator + UserProfile trader1 = privateTradeChannel.getPeerOrTrader1(); + UserProfile trader2 = privateTradeChannel.getMyUserProfileOrTrader2(); + roboIcon.setImage(RoboHash.getImage(trader1.getPubKeyHash())); + secondaryRoboIcon.setImage(RoboHash.getImage(trader2.getPubKeyHash())); + tooltip.setText(trader1.getTooltipString() + "\n\n" + trader2.getTooltipString()); + } else { + UserProfile mediator = privateTradeChannel.getMediator().get(); + secondaryRoboIcon.setImage(RoboHash.getImage(mediator.getPubKeyHash())); + tooltip.setText(peer.getTooltipString() + "\n\n" + + Res.get("mediator") + ":\n" + mediator.getTooltipString()); + } + hBox.getChildren().add(secondaryRoboIcon); + icons.add(secondaryRoboIcon); + } else { + tooltip.setText(peer.getTooltipString()); + } + label.setText(privateTradeChannel.getChannelSelectionDisplayString()); + hBox.getChildren().addAll(label, Spacer.fillHBox(), removeIcon); + + if (widthSubscription != null) { + widthSubscription.unsubscribe(); + } + widthSubscription = EasyBind.subscribe(widthProperty(), w -> { + if (w.doubleValue() > 0) { + if (secondaryRoboIcon.getImage() != null) { + label.setMaxWidth(getWidth() - 120); + } else { + label.setMaxWidth(getWidth() - 95); + } + } + }); + }); + }); + } else { + hBox.getChildren().clear(); + label.setText(item.getDisplayString()); + tooltip.setText(peer.getTooltipString()); + hBox.getChildren().addAll(roboIcon, label, Spacer.fillHBox(), removeIcon); + widthSubscription = EasyBind.subscribe(widthProperty(), w -> { + if (w.doubleValue() > 0) { + label.setMaxWidth(getWidth() - 75); + } + }); + } + removeIcon.setOpacity(0); + removeIcon.setOnMouseClicked(e -> controller.onLeaveChannel(privateChannel)); + setOnMouseClicked(e -> { + Transitions.fadeIn(removeIcon); + }); + setOnMouseEntered(e -> { + Transitions.fadeIn(removeIcon); + applyEffect(icons, item.isSelected(), true); + }); + setOnMouseExited(e -> { + Transitions.fadeOut(removeIcon); + applyEffect(icons, item.isSelected(), false); + }); + applyEffect(icons, item.isSelected(), false); + setGraphic(hBox); + } + + private void applyEffect(List icons, boolean isSelected, boolean isHover) { + icons.forEach(icon -> { + if (isSelected) { + icon.setEffect(null); + } else { + if (isHover) { + icon.setEffect(hoverEffect); + } else { + icon.setEffect(nonSelectedEffect); + } + } + }); } }; } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java index 842762fe16..0875038219 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java @@ -278,7 +278,6 @@ protected ListCell getListCell() { return new ListCell<>() { private Subscription widthSubscription; final Label removeIcon = Icons.getIcon(AwesomeIcon.MINUS_SIGN_ALT, "14"); - final Label label = new Label(); final HBox hBox = new HBox(); final ColorAdjust nonSelectedEffect = new ColorAdjust(); @@ -365,10 +364,8 @@ private void applyEffect(List icons, boolean isSelected, boolean isHo } else { icon.setEffect(nonSelectedEffect); } - } }); - } }; } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index 21012bd696..d417d78ba9 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -104,10 +104,9 @@ public void onDeactivate() { void setChannel(Channel channel) { Set ignoredChatUserIds = new HashSet<>(userProfileService.getIgnoredUserProfileIds()); model.channelName.set(channel.getDisplayString()); - model.members.setAll(channel.getChatMessages().stream() - .flatMap(chatMessage -> userProfileService.findUserProfile(chatMessage.getAuthorId()).stream()) - .distinct() - .map((chatUser -> new ChatUserOverview(chatUser, ignoredChatUserIds.contains(chatUser.getId())))) + model.members.setAll(channel.getMembers().stream() + .flatMap(authorId -> userProfileService.findUserProfile(authorId).stream()) + .map(userProfile -> new ChatUserOverview(userProfile, ignoredChatUserIds.contains(userProfile.getId()))) .sorted() .collect(Collectors.toList())); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 9e60263ab1..6f5d2e5444 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -333,12 +333,16 @@ private void applySelectedChannel(Channel channel) { private void applyUserProfileOrChannelChange() { boolean multipleProfiles = userIdentityService.getUserIdentities().size() > 1; - model.userProfileSelectionVisible.set(multipleProfiles && model.selectedChannel.get() instanceof PublicChannel); + Channel selectedChannel = model.selectedChannel.get(); + model.userProfileSelectionVisible.set(multipleProfiles && selectedChannel instanceof PublicChannel); if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = model.selectedChannel.get().getChatMessages().addChangedListener(this::maybeSwitchUserProfile); + + if (selectedChannel != null) { + chatMessagesPin = selectedChannel.getChatMessages().addChangedListener(this::maybeSwitchUserProfile); + } } private void maybeSwitchUserProfile() { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/overview/TradeOverviewBaseController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/overview/TradeOverviewBaseController.java index 612b230180..08b56a6417 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/overview/TradeOverviewBaseController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/overview/TradeOverviewBaseController.java @@ -58,7 +58,7 @@ public TradeOverviewBaseController(M model) { Res.get("trade.protocols.convenience.info.LIQUID_SWAP"), Res.get("trade.protocols.costs.info.LIQUID_SWAP"), Res.get("trade.protocols.speed.info.LIQUID_SWAP"), - "Q4/22", + "Q1/23", "protocol-liquid" ), /* new ProtocolListItem(SwapProtocol.Type.MONERO_SWAP, @@ -86,7 +86,7 @@ public TradeOverviewBaseController(M model) { Res.get("trade.protocols.convenience.info.BISQ_MULTISIG"), Res.get("trade.protocols.costs.info.BISQ_MULTISIG"), Res.get("trade.protocols.speed.info.BISQ_MULTISIG"), - "Q2/23", + "Q3/23", "protocol-bisq" ), /* new ProtocolListItem(SwapProtocol.Type.LIGHTNING_X, @@ -114,7 +114,7 @@ public TradeOverviewBaseController(M model) { Res.get("trade.protocols.convenience.info.BSQ_SWAP"), Res.get("trade.protocols.costs.info.BSQ_SWAP"), Res.get("trade.protocols.speed.info.BSQ_SWAP"), - "Q3/23", + "Q4/23", "protocol-bsq" ) ); diff --git a/i18n/src/main/resources/default.properties b/i18n/src/main/resources/default.properties index c1e92f85ce..b1f7f3d985 100644 --- a/i18n/src/main/resources/default.properties +++ b/i18n/src/main/resources/default.properties @@ -269,6 +269,11 @@ social.reports=Reports social.reply.headline=Replying to: social.message.wasEdited=(edited) +social.privateChannel.leave=Leave channel +social.privateChannel.leave.message=''{0}'' left that channel. +social.privateChannel.leave.warning=Are you sure you want to leave that private channel with ''{0}''.\n\ + All data will be deleted if you leave the channel. +social.privateChannel.empty=Empty (was ''{0}'') ###################################################### ## Academy @@ -720,7 +725,7 @@ trade.protocols.LIQUID_SWAP.overview=To use Liquid swaps the user need to instal The most widely used asset on Liquid is USDT (Tether) - a stable coin pegged to the USD. While this is not comparable to something like Bitcoin, it has many advantages over Fiat USD which involves usually bank transfers with all the problems and inconvenience of the legacy Fiat system.\n\n\ L-BTC might be used on the other end of the trade which is a substitute of Bitcoin on the Liquid chain. To convert Bitcoin to L-BTC one need to send Bitcoin to a peg-in address and will receive after 102 confirmations L-BTC for that. Going back from L-BTC to Bitcoin (peg-out) works similar but requires authorisation from the Liquid federation which is a group of companies and individuals in the Bitcoin space. So it is not a completely trust-less process.\n\n\ One should avoid comparing Liquid assets to the properties of Bitcoin. It targets other use cases and cannot meet the high level of decentralisation and censorship resistance of Bitcoin. It can be seen rather as an alternative to traditional financial products. By using blockchain technology it avoids classical intermediaries, improves security and privacy and provides a better user experience. -trade.protocols.LIQUID_SWAP.release=Liquid swaps are still in development. It is expected to be released in Q4/2022. +trade.protocols.LIQUID_SWAP.release=Liquid swaps are still in development. It is expected to be released in Q1/2023. trade.protocols.LIQUID_SWAP.tradeOffs=\ + Confidential transactions provide good privacy\n\ + Fast confirmation time of about 1 minute\n\ @@ -735,7 +740,7 @@ trade.protocols.MONERO_SWAP.subHeadline=Atomic cross-chain swap protocol for tra trade.protocols.MONERO_SWAP.overview=Based on the Farcaster project (funded by the Monero community) using hashed time lock contracts (HTLC), adaptor signatures and zero-knowledge proof for atomically swapping Bitcoin and Monero.\n\n\ The user needs to install and run a Bitcoin node, a Monero node and the Farcaster daemon. During the swap, the nodes of both traders need to be online. The extra effort when using that protocol pays off with a very high level of security. \ Though users should make themselves familiar with the details of that concept and be aware that there are edge case carrying some small risks. -trade.protocols.MONERO_SWAP.release=Monero swaps are expected to be ready for release in Q1/2023. +trade.protocols.MONERO_SWAP.release=Monero swaps are expected to be ready for release in Q3/2023. trade.protocols.MONERO_SWAP.tradeOffs=\ + Very secure\n\ + Decent privacy. On the Bitcoin side it inherits Bitcoin's privacy properties. On the Monero side it benefits from the high privacy of Monero.\n\ @@ -752,7 +757,7 @@ trade.protocols.BISQ_MULTISIG.overview=Conceptually it follows the trade protoco - It avoids the maker-fee and taker-fee transactions and reduces by that the total number of involved transactions to 2 (maybe even to 1, but this has to be further investigated).\n\ - Another open research area is to replace the delayed payout transaction by using a Taproot branch.\n\ - The most important aspect though is to replace the manual role of the burningman by a smart contract. There is still not a satisfying solution found in that area, but we hope to be able to solve that. -trade.protocols.BISQ_MULTISIG.release=Bisq Multisig is expected to be ready for release in Q2/2023. +trade.protocols.BISQ_MULTISIG.release=Bisq Multisig is expected to be ready for release in Q3/2023. trade.protocols.BISQ_MULTISIG.tradeOffs=\ + Reasonable good security for medium value trade amounts\n\ + Compared to Bisq Easy the security properties are better and higher amounts can be traded. The higher amounts bring trade prices closer to market rates.\n\ @@ -764,7 +769,7 @@ trade.protocols.BISQ_MULTISIG.tradeOffs=\ trade.protocols.BSQ_SWAP.subHeadline=Atomic swap between BSQ (colored coin on Bitcoin) and Bitcoin trade.protocols.BSQ_SWAP.overview=Same model as used in Bisq 1. As it is based on one single atomic transaction it is very secure.\n\ It will require to run the Bisq 1 node with the DAO API enabled. -trade.protocols.BSQ_SWAP.release=BSQ swaps is expected to be ready for release in Q3/2023. +trade.protocols.BSQ_SWAP.release=BSQ swaps is expected to be ready for release in Q4/2023. trade.protocols.BSQ_SWAP.tradeOffs=\ + Very secure\n\ + Relative fast, thought only after the blockchain confirmation the trade is considered complete\n\ @@ -777,7 +782,7 @@ trade.protocols.LIGHTNING_X.subHeadline=Three-party protocol for trading Fiat wi trade.protocols.LIGHTNING_X.overview=It is based on multiple Lightning payments and splits up the secrets for the HTLCs to construct a secure setup where the 3rd party guarantees that the traders behave fair. It uses garbled circuits to achieve secure multi party computation.\n\n\ The user needs to run a Lightning node which is configured with the Bisq application.\n\n\ Conceptually it is similar to the Bisq Multisig protocol but instead of the Multisig transaction it uses this 3-party set-up and instead of on-chain Bitcoin it uses Bitcoin on Lightning Network. -trade.protocols.LIGHTNING_X.release=Lightning-X is expected to be ready for release in Q2/2023. +trade.protocols.LIGHTNING_X.release=Lightning-X is expected to be ready for release in Q4/2023. trade.protocols.LIGHTNING_X.tradeOffs=\ + Compared to Bisq Easy the security properties are better and higher amounts can be traded. The higher amounts bring trade prices closer to market rates.\n\ + The Bitcoin payments are near instant\n\ diff --git a/user/src/main/java/bisq/user/profile/UserProfileService.java b/user/src/main/java/bisq/user/profile/UserProfileService.java index 87b9f0a0a7..8af93aaec2 100644 --- a/user/src/main/java/bisq/user/profile/UserProfileService.java +++ b/user/src/main/java/bisq/user/profile/UserProfileService.java @@ -147,14 +147,12 @@ public Map getUserProfileById() { } private void processUserProfileAdded(UserProfile userProfile) { - if (proofOfWorkService.verify(userProfile.getProofOfWork())) { - Optional optionalChatUser = findUserProfile(userProfile.getId()); - if (optionalChatUser.isEmpty() || !optionalChatUser.get().equals(userProfile)) { - log.info("We got a new or edited userProfile {}", userProfile); - getUserProfileById().put(userProfile.getId(), userProfile); - notifyObservers(); - persist(); - } + Optional optionalChatUser = findUserProfile(userProfile.getId()); + if (optionalChatUser.isEmpty() || !optionalChatUser.get().equals(userProfile)) { + log.info("We got a new or edited userProfile {}", userProfile); + getUserProfileById().put(userProfile.getId(), userProfile); + notifyObservers(); + persist(); } } From 2de3c00509705119945dac76a438bbc69e89b476 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 12:46:55 -0500 Subject: [PATCH 03/15] Refactor common code from events, support and discussion to PrivateTwoParty* classes --- .../{ChannelKind.java => ChatDomain.java} | 16 ++- chat/src/main/java/bisq/chat/ChatService.java | 25 +++-- .../main/java/bisq/chat/channel/Channel.java | 27 ++--- .../bisq/chat/channel/PrivateChannel.java | 6 +- .../chat/channel/PrivateChannelService.java | 6 +- .../java/bisq/chat/channel/PublicChannel.java | 6 +- .../PrivateTwoPartyChannel.java} | 45 ++++---- .../PrivateTwoPartyChannelService.java} | 56 +++++----- .../PrivateTwoPartyChannelStore.java} | 38 +++---- .../PrivateTwoPartyChatMessage.java} | 56 +++++----- .../DiscussionChannelSelectionService.java | 12 +- .../priv/PrivateDiscussionChannel.java | 101 ----------------- .../priv/PrivateDiscussionChannelService.java | 90 --------------- .../priv/PrivateDiscussionChannelStore.java | 80 ------------- .../priv/PrivateDiscussionChatMessage.java | 105 ------------------ .../discuss/pub/PublicDiscussionChannel.java | 4 +- .../events/EventsChannelSelectionService.java | 12 +- .../priv/PrivateEventsChannelService.java | 90 --------------- .../priv/PrivateEventsChannelStore.java | 80 ------------- .../events/priv/PrivateEventsChatMessage.java | 105 ------------------ .../chat/events/pub/PublicEventsChannel.java | 4 +- .../java/bisq/chat/message/ChatMessage.java | 32 ++---- .../SupportChannelSelectionService.java | 12 +- .../support/priv/PrivateSupportChannel.java | 101 ----------------- .../support/pub/PublicSupportChannel.java | 4 +- .../chat/trade/priv/PrivateTradeChannel.java | 4 +- .../priv/PrivateTradeChannelService.java | 3 +- .../chat/trade/pub/PublicTradeChannel.java | 4 +- chat/src/main/proto/chat.proto | 76 +++++-------- .../java/bisq/common/util/StringUtils.java | 10 ++ .../main/content/chat/ChatController.java | 12 +- .../channels/PrivateChannelSelection.java | 66 ++++++----- .../content/chat/sidebar/ChannelSidebar.java | 52 ++++++++- .../components/ChatMessagesComponent.java | 68 ++++++------ .../components/ChatMessagesListView.java | 74 ++++++------ .../discussion/DiscussionsController.java | 14 +-- .../content/discussion/DiscussionsModel.java | 8 +- .../main/content/events/EventsController.java | 12 +- .../main/content/events/EventsModel.java | 8 +- .../content/support/SupportController.java | 12 +- .../main/content/support/SupportModel.java | 8 +- .../bisqEasy/chat/BisqEasyChatController.java | 8 +- .../bisqEasy/chat/BisqEasyChatModel.java | 8 +- .../dto/PublicDiscussionChannelDto.java | 2 +- 44 files changed, 429 insertions(+), 1133 deletions(-) rename chat/src/main/java/bisq/chat/{ChannelKind.java => ChatDomain.java} (63%) rename chat/src/main/java/bisq/chat/{events/priv/PrivateEventsChannel.java => channel/private_two_party/PrivateTwoPartyChannel.java} (61%) rename chat/src/main/java/bisq/chat/{support/priv/PrivateSupportChannelService.java => channel/private_two_party/PrivateTwoPartyChannelService.java} (58%) rename chat/src/main/java/bisq/chat/{support/priv/PrivateSupportChannelStore.java => channel/private_two_party/PrivateTwoPartyChannelStore.java} (52%) rename chat/src/main/java/bisq/chat/{support/priv/PrivateSupportChatMessage.java => channel/private_two_party/PrivateTwoPartyChatMessage.java} (67%) delete mode 100644 chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java delete mode 100644 chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java delete mode 100644 chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelStore.java delete mode 100644 chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java delete mode 100644 chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java delete mode 100644 chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelStore.java delete mode 100644 chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java delete mode 100644 chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java diff --git a/chat/src/main/java/bisq/chat/ChannelKind.java b/chat/src/main/java/bisq/chat/ChatDomain.java similarity index 63% rename from chat/src/main/java/bisq/chat/ChannelKind.java rename to chat/src/main/java/bisq/chat/ChatDomain.java index ed909c21cd..758fe70396 100644 --- a/chat/src/main/java/bisq/chat/ChannelKind.java +++ b/chat/src/main/java/bisq/chat/ChatDomain.java @@ -17,9 +17,21 @@ package bisq.chat; -public enum ChannelKind { +import bisq.common.proto.ProtoEnum; +import bisq.common.util.ProtobufUtils; + +public enum ChatDomain implements ProtoEnum { TRADE, DISCUSSION, EVENTS, - SUPPORT + SUPPORT; + + @Override + public bisq.chat.protobuf.ChatDomain toProto() { + return bisq.chat.protobuf.ChatDomain.valueOf(name()); + } + + public static ChatDomain fromProto(bisq.chat.protobuf.ChatDomain proto) { + return ProtobufUtils.enumFromProto(ChatDomain.class, proto.name()); + } } diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 88ca2938b4..97ea586d75 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -17,14 +17,12 @@ package bisq.chat; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.priv.PrivateDiscussionChannelService; import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.priv.PrivateEventsChannelService; import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.priv.PrivateSupportChannelService; import bisq.chat.support.pub.PublicSupportChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -45,15 +43,15 @@ @Getter public class ChatService implements Service { private final PrivateTradeChannelService privateTradeChannelService; - private final PrivateDiscussionChannelService privateDiscussionChannelService; + private final PrivateTwoPartyChannelService privateDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final PublicDiscussionChannelService publicDiscussionChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; - private final PrivateSupportChannelService privateSupportChannelService; + private final PrivateTwoPartyChannelService privateSupportChannelService; private final PublicSupportChannelService publicSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; - private final PrivateEventsChannelService privateEventsChannelService; + private final PrivateTwoPartyChannelService privateEventsChannelService; private final PublicEventsChannelService publicEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; @@ -75,10 +73,11 @@ public ChatService(PersistenceService persistenceService, publicTradeChannelService); // Discussion - privateDiscussionChannelService = new PrivateDiscussionChannelService(persistenceService, + privateDiscussionChannelService = new PrivateTwoPartyChannelService(persistenceService, networkService, userIdentityService, - proofOfWorkService); + proofOfWorkService, + ChatDomain.DISCUSSION); publicDiscussionChannelService = new PublicDiscussionChannelService(persistenceService, networkService, userIdentityService); @@ -87,10 +86,11 @@ public ChatService(PersistenceService persistenceService, publicDiscussionChannelService); // Events - privateEventsChannelService = new PrivateEventsChannelService(persistenceService, + privateEventsChannelService = new PrivateTwoPartyChannelService(persistenceService, networkService, userIdentityService, - proofOfWorkService); + proofOfWorkService, + ChatDomain.EVENTS); publicEventsChannelService = new PublicEventsChannelService(persistenceService, networkService, userIdentityService); @@ -99,10 +99,11 @@ public ChatService(PersistenceService persistenceService, publicEventsChannelService); // Support - privateSupportChannelService = new PrivateSupportChannelService(persistenceService, + privateSupportChannelService = new PrivateTwoPartyChannelService(persistenceService, networkService, userIdentityService, - proofOfWorkService); + proofOfWorkService, + ChatDomain.SUPPORT); publicSupportChannelService = new PublicSupportChannelService(persistenceService, networkService, userIdentityService); diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index e11f9461c6..540d7ae499 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -17,14 +17,12 @@ package bisq.chat.channel; -import bisq.chat.ChannelKind; -import bisq.chat.discuss.priv.PrivateDiscussionChannel; +import bisq.chat.ChatDomain; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.discuss.pub.PublicDiscussionChannel; -import bisq.chat.events.priv.PrivateEventsChannel; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; -import bisq.chat.support.priv.PrivateSupportChannel; import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; @@ -46,18 +44,19 @@ public abstract class Channel implements Proto { @EqualsAndHashCode.Include protected final String id; - private final ChannelKind channelKind; + private final ChatDomain chatDomain; protected final Observable channelNotificationType = new Observable<>(); - public Channel(String id, ChannelNotificationType channelNotificationType, ChannelKind channelKind) { + public Channel(String id, ChannelNotificationType channelNotificationType, ChatDomain chatDomain) { this.id = id; - this.channelKind = channelKind; + this.chatDomain = chatDomain; this.channelNotificationType.set(channelNotificationType); } public bisq.chat.protobuf.Channel.Builder getChannelBuilder() { return bisq.chat.protobuf.Channel.newBuilder() .setId(id) + .setChatDomain(chatDomain.toProto()) .setChannelNotificationType(channelNotificationType.get().toProto()); } @@ -65,6 +64,10 @@ public bisq.chat.protobuf.Channel.Builder getChannelBuilder() { public static Channel fromProto(bisq.chat.protobuf.Channel proto) { switch (proto.getMessageCase()) { + case PRIVATETWOPARTYCHANNEL: { + return PrivateTwoPartyChannel.fromProto(proto, proto.getPrivateTwoPartyChannel()); + } + case PRIVATETRADECHANNEL: { return PrivateTradeChannel.fromProto(proto, proto.getPrivateTradeChannel()); } @@ -72,23 +75,15 @@ public static Channel fromProto(bisq.chat.protobuf.Channe return PublicTradeChannel.fromProto(proto, proto.getPublicTradeChannel()); } - case PRIVATEDISCUSSIONCHANNEL: { - return PrivateDiscussionChannel.fromProto(proto, proto.getPrivateDiscussionChannel()); - } + case PUBLICDISCUSSIONCHANNEL: { return PublicDiscussionChannel.fromProto(proto, proto.getPublicDiscussionChannel()); } - case PRIVATEEVENTSCHANNEL: { - return PrivateEventsChannel.fromProto(proto, proto.getPrivateEventsChannel()); - } case PUBLICEVENTSCHANNEL: { return PublicEventsChannel.fromProto(proto, proto.getPublicEventsChannel()); } - case PRIVATESUPPORTCHANNEL: { - return PrivateSupportChannel.fromProto(proto, proto.getPrivateSupportChannel()); - } case PUBLICSUPPORTCHANNEL: { return PublicSupportChannel.fromProto(proto, proto.getPublicSupportChannel()); } diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index 125b21b6cb..ce31814468 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -17,7 +17,7 @@ package bisq.chat.channel; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.message.PrivateChatMessage; import bisq.common.data.ByteArray; import bisq.common.data.Pair; @@ -55,8 +55,8 @@ public PrivateChannel(String id, UserIdentity myUserIdentity, List chatMessages, ChannelNotificationType channelNotificationType, - ChannelKind channelKind) { - super(id, channelNotificationType, channelKind); + ChatDomain chatDomain) { + super(id, channelNotificationType, chatDomain); this.myUserIdentity = myUserIdentity; this.chatMessages.addAll(chatMessages); diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index 11f62428da..9a75c09876 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.channel; +import bisq.chat.ChatDomain; import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; @@ -43,12 +44,15 @@ public abstract class PrivateChannelService, S extends PersistableStore> extends ChannelService implements MessageListener { protected final ProofOfWorkService proofOfWorkService; + protected final ChatDomain chatDomain; public PrivateChannelService(NetworkService networkService, UserIdentityService userIdentityService, - ProofOfWorkService proofOfWorkService) { + ProofOfWorkService proofOfWorkService, + ChatDomain chatDomain) { super(networkService, userIdentityService); this.proofOfWorkService = proofOfWorkService; + this.chatDomain = chatDomain; } diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannel.java b/chat/src/main/java/bisq/chat/channel/PublicChannel.java index ee38b0d267..b43507baa5 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannel.java @@ -17,7 +17,7 @@ package bisq.chat.channel; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.message.PublicChatMessage; import bisq.common.observable.ObservableArray; import lombok.EqualsAndHashCode; @@ -31,7 +31,7 @@ public abstract class PublicChannel extends Channel // We do not persist the messages as they are persisted in the P2P data store. protected transient final ObservableArray chatMessages = new ObservableArray<>(); - public PublicChannel(String id, ChannelNotificationType channelNotificationType, ChannelKind channelKind) { - super(id, channelNotificationType, channelKind); + public PublicChannel(String id, ChannelNotificationType channelNotificationType, ChatDomain chatDomain) { + super(id, channelNotificationType, chatDomain); } } diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java similarity index 61% rename from chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java rename to chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java index a1d488b614..f3658a3358 100644 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannel.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java @@ -15,9 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.chat.events.priv; +package bisq.chat.channel.private_two_party; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -35,62 +35,65 @@ @ToString(callSuper = true) @Getter @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PrivateEventsChannel extends PrivateChannel { +public final class PrivateTwoPartyChannel extends PrivateChannel { private final UserProfile peer; - public PrivateEventsChannel(UserProfile peer, UserIdentity myUserIdentity) { + public PrivateTwoPartyChannel(UserProfile peer, UserIdentity myUserIdentity, ChatDomain chatDomain) { this(PrivateChannel.createChannelId(new Pair<>(peer.getId(), myUserIdentity.getId())), peer, myUserIdentity, new ArrayList<>(), - ChannelNotificationType.ALL); + ChannelNotificationType.ALL, + chatDomain); } - private PrivateEventsChannel(String id, - UserProfile peer, - UserIdentity myProfile, - List chatMessages, - ChannelNotificationType channelNotificationType) { - super(id, myProfile, chatMessages, channelNotificationType, ChannelKind.EVENTS); + private PrivateTwoPartyChannel(String id, + UserProfile peer, + UserIdentity myProfile, + List chatMessages, + ChannelNotificationType channelNotificationType, + ChatDomain chatDomain) { + super(id, myProfile, chatMessages, channelNotificationType, chatDomain); this.peer = peer; } @Override public bisq.chat.protobuf.Channel toProto() { - return getChannelBuilder().setPrivateEventsChannel(bisq.chat.protobuf.PrivateEventsChannel.newBuilder() + return getChannelBuilder().setPrivateTwoPartyChannel(bisq.chat.protobuf.PrivateTwoPartyChannel.newBuilder() .setPeer(peer.toProto()) .setMyUserIdentity(myUserIdentity.toProto()) .addAllChatMessages(chatMessages.stream() - .map(PrivateEventsChatMessage::toChatMessageProto) + .map(PrivateTwoPartyChatMessage::toChatMessageProto) .collect(Collectors.toList()))) .build(); } - public static PrivateEventsChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PrivateEventsChannel proto) { - return new PrivateEventsChannel( + public static PrivateTwoPartyChannel fromProto(bisq.chat.protobuf.Channel baseProto, + bisq.chat.protobuf.PrivateTwoPartyChannel proto) { + return new PrivateTwoPartyChannel( baseProto.getId(), UserProfile.fromProto(proto.getPeer()), UserIdentity.fromProto(proto.getMyUserIdentity()), proto.getChatMessagesList().stream() - .map(PrivateEventsChatMessage::fromProto) + .map(PrivateTwoPartyChatMessage::fromProto) .collect(Collectors.toList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); + ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()), + ChatDomain.fromProto(baseProto.getChatDomain())); } @Override - public void addChatMessage(PrivateEventsChatMessage chatMessage) { + public void addChatMessage(PrivateTwoPartyChatMessage chatMessage) { chatMessages.add(chatMessage); } @Override - public void removeChatMessage(PrivateEventsChatMessage chatMessage) { + public void removeChatMessage(PrivateTwoPartyChatMessage chatMessage) { chatMessages.remove(chatMessage); } @Override - public void removeChatMessages(Collection removeMessages) { + public void removeChatMessages(Collection removeMessages) { chatMessages.removeAll(removeMessages); } diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java similarity index 58% rename from chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java rename to chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java index 52c9eb437e..c0c1674124 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java @@ -15,12 +15,14 @@ * along with Bisq. If not, see . */ -package bisq.chat.support.priv; +package bisq.chat.channel.private_two_party; +import bisq.chat.ChatDomain; import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; +import bisq.common.util.StringUtils; import bisq.network.NetworkService; import bisq.network.p2p.message.NetworkMessage; import bisq.persistence.Persistence; @@ -36,38 +38,42 @@ import java.util.Optional; @Slf4j -public class PrivateSupportChannelService extends PrivateChannelService { +public class PrivateTwoPartyChannelService extends PrivateChannelService { @Getter - private final PrivateSupportChannelStore persistableStore = new PrivateSupportChannelStore(); + private final PrivateTwoPartyChannelStore persistableStore = new PrivateTwoPartyChannelStore(); @Getter - private final Persistence persistence; + private final Persistence persistence; - public PrivateSupportChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService, - ProofOfWorkService proofOfWorkService) { - super(networkService, userIdentityService, proofOfWorkService); - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); + public PrivateTwoPartyChannelService(PersistenceService persistenceService, + NetworkService networkService, + UserIdentityService userIdentityService, + ProofOfWorkService proofOfWorkService, + ChatDomain chatDomain) { + super(networkService, userIdentityService, proofOfWorkService, chatDomain); + persistence = persistenceService.getOrCreatePersistence(this, + "db", + "Private" + StringUtils.capitalize(chatDomain.name()) + "ChannelStore", + persistableStore); } @Override public void onMessage(NetworkMessage networkMessage) { - if (networkMessage instanceof PrivateSupportChatMessage) { - processMessage((PrivateSupportChatMessage) networkMessage); + if (networkMessage instanceof PrivateTwoPartyChatMessage) { + processMessage((PrivateTwoPartyChatMessage) networkMessage); } } @Override - protected PrivateSupportChatMessage createNewPrivateChatMessage(String messageId, - PrivateSupportChannel channel, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long time, - boolean wasEdited, - MessageType messageType) { - return new PrivateSupportChatMessage(messageId, + protected PrivateTwoPartyChatMessage createNewPrivateChatMessage(String messageId, + PrivateTwoPartyChannel channel, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long time, + boolean wasEdited, + MessageType messageType) { + return new PrivateTwoPartyChatMessage(messageId, channel.getId(), sender, receiversId, @@ -79,12 +85,12 @@ protected PrivateSupportChatMessage createNewPrivateChatMessage(String messageId } @Override - protected PrivateSupportChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { - return new PrivateSupportChannel(peer, myUserIdentity); + protected PrivateTwoPartyChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { + return new PrivateTwoPartyChannel(peer, myUserIdentity, chatDomain); } @Override - public ObservableArray getChannels() { + public ObservableArray getChannels() { return persistableStore.getChannels(); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelStore.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelStore.java similarity index 52% rename from chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelStore.java rename to chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelStore.java index f43a5a7fe6..97f55d70c4 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelStore.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.support.priv; +package bisq.chat.channel.private_two_party; import bisq.common.observable.ObservableArray; import bisq.common.proto.ProtoResolver; @@ -28,35 +28,35 @@ import java.util.stream.Collectors; @Getter -public class PrivateSupportChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); +public class PrivateTwoPartyChannelStore implements PersistableStore { + private final ObservableArray channels = new ObservableArray<>(); - public PrivateSupportChannelStore() { + public PrivateTwoPartyChannelStore() { } - private PrivateSupportChannelStore(List privateSupportChannels) { - setAll(privateSupportChannels); + private PrivateTwoPartyChannelStore(List privateTwoPartyChannels) { + setAll(privateTwoPartyChannels); } @Override - public bisq.chat.protobuf.PrivateSupportChannelStore toProto() { - bisq.chat.protobuf.PrivateSupportChannelStore.Builder builder = bisq.chat.protobuf.PrivateSupportChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PrivateSupportChannel::toProto).collect(Collectors.toList())); + public bisq.chat.protobuf.PrivateTwoPartyChannelStore toProto() { + bisq.chat.protobuf.PrivateTwoPartyChannelStore.Builder builder = bisq.chat.protobuf.PrivateTwoPartyChannelStore.newBuilder() + .addAllChannels(channels.stream().map(PrivateTwoPartyChannel::toProto).collect(Collectors.toList())); return builder.build(); } - public static PrivateSupportChannelStore fromProto(bisq.chat.protobuf.PrivateSupportChannelStore proto) { - List privateSupportChannels = proto.getChannelsList().stream() - .map(e -> (PrivateSupportChannel) PrivateSupportChannel.fromProto(e)) + public static PrivateTwoPartyChannelStore fromProto(bisq.chat.protobuf.PrivateTwoPartyChannelStore proto) { + List privateTwoPartyChannels = proto.getChannelsList().stream() + .map(e -> (PrivateTwoPartyChannel) PrivateTwoPartyChannel.fromProto(e)) .collect(Collectors.toList()); - return new PrivateSupportChannelStore(privateSupportChannels); + return new PrivateTwoPartyChannelStore(privateTwoPartyChannels); } @Override public ProtoResolver> getResolver() { return any -> { try { - return fromProto(any.unpack(bisq.chat.protobuf.PrivateSupportChannelStore.class)); + return fromProto(any.unpack(bisq.chat.protobuf.PrivateTwoPartyChannelStore.class)); } catch (InvalidProtocolBufferException e) { throw new UnresolvableProtobufMessageException(e); } @@ -64,17 +64,17 @@ public ProtoResolver> getResolver() { } @Override - public void applyPersisted(PrivateSupportChannelStore chatStore) { + public void applyPersisted(PrivateTwoPartyChannelStore chatStore) { setAll(chatStore.getChannels()); } @Override - public PrivateSupportChannelStore getClone() { - return new PrivateSupportChannelStore(channels); + public PrivateTwoPartyChannelStore getClone() { + return new PrivateTwoPartyChannelStore(channels); } - public void setAll(List privateSupportChannels) { + public void setAll(List privateTwoPartyChannels) { this.channels.clear(); - this.channels.addAll(privateSupportChannels); + this.channels.addAll(privateTwoPartyChannels); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChatMessage.java similarity index 67% rename from chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java rename to chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChatMessage.java index 87466443cb..64a2952b78 100644 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChatMessage.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChatMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.support.priv; +package bisq.chat.channel.private_two_party; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; @@ -35,16 +35,16 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public final class PrivateSupportChatMessage extends PrivateChatMessage { - public PrivateSupportChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType) { +public final class PrivateTwoPartyChatMessage extends PrivateChatMessage { + public PrivateTwoPartyChatMessage(String messageId, + String channelId, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType) { super(messageId, channelId, sender, @@ -54,19 +54,19 @@ public PrivateSupportChatMessage(String messageId, date, wasEdited, messageType, - new MetaData(ChatMessage.TTL, 100000, PrivateSupportChatMessage.class.getSimpleName())); + new MetaData(ChatMessage.TTL, 100000, PrivateTwoPartyChatMessage.class.getSimpleName())); } - private PrivateSupportChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { + private PrivateTwoPartyChatMessage(String messageId, + String channelId, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType, + MetaData metaData) { super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); } @@ -79,22 +79,22 @@ public NetworkMessage toProto() { public bisq.chat.protobuf.ChatMessage toChatMessageProto() { return getChatMessageBuilder() - .setPrivateSupportChatMessage(bisq.chat.protobuf.PrivateSupportChatMessage.newBuilder() + .setPrivateTwoPartyChatMessage(bisq.chat.protobuf.PrivateTwoPartyChatMessage.newBuilder() .setReceiversId(receiversId) .setSender(sender.toProto())) .build(); } - public static PrivateSupportChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { + public static PrivateTwoPartyChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { Optional quotedMessage = baseProto.hasQuotation() ? Optional.of(Quotation.fromProto(baseProto.getQuotation())) : Optional.empty(); - bisq.chat.protobuf.PrivateSupportChatMessage privateSupportChatMessage = baseProto.getPrivateSupportChatMessage(); - return new PrivateSupportChatMessage( + bisq.chat.protobuf.PrivateTwoPartyChatMessage privateTwoPartyChatMessage = baseProto.getPrivateTwoPartyChatMessage(); + return new PrivateTwoPartyChatMessage( baseProto.getMessageId(), baseProto.getChannelId(), - UserProfile.fromProto(privateSupportChatMessage.getSender()), - privateSupportChatMessage.getReceiversId(), + UserProfile.fromProto(privateTwoPartyChatMessage.getSender()), + privateTwoPartyChatMessage.getReceiversId(), baseProto.getText(), quotedMessage, baseProto.getDate(), diff --git a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java index 4f16ecf39f..4b337b3e6c 100644 --- a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java @@ -18,8 +18,8 @@ package bisq.chat.discuss; import bisq.chat.channel.Channel; -import bisq.chat.discuss.priv.PrivateDiscussionChannel; -import bisq.chat.discuss.priv.PrivateDiscussionChannelService; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; @@ -37,11 +37,11 @@ public class DiscussionChannelSelectionService implements PersistenceClient { private final DiscussionChannelSelectionStore persistableStore = new DiscussionChannelSelectionStore(); private final Persistence persistence; - private final PrivateDiscussionChannelService privateChannelService; + private final PrivateTwoPartyChannelService privateChannelService; private final PublicDiscussionChannelService publicChannelService; public DiscussionChannelSelectionService(PersistenceService persistenceService, - PrivateDiscussionChannelService privateChannelService, + PrivateTwoPartyChannelService privateChannelService, PublicDiscussionChannelService publicChannelService) { persistence = persistenceService.getOrCreatePersistence(this, persistableStore); this.privateChannelService = privateChannelService; @@ -60,8 +60,8 @@ public CompletableFuture shutdown() { } public void selectChannel(Channel channel) { - if (channel instanceof PrivateDiscussionChannel) { - privateChannelService.removeExpiredMessages((PrivateDiscussionChannel) channel); + if (channel instanceof PrivateTwoPartyChannel) { + privateChannelService.removeExpiredMessages((PrivateTwoPartyChannel) channel); } getSelectedChannel().set(channel); diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java deleted file mode 100644 index b5515971c7..0000000000 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannel.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.discuss.priv; - -import bisq.chat.ChannelKind; -import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PrivateChannel; -import bisq.common.data.Pair; -import bisq.user.identity.UserIdentity; -import bisq.user.profile.UserProfile; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -@ToString(callSuper = true) -@Getter -@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PrivateDiscussionChannel extends PrivateChannel { - private final UserProfile peer; - - public PrivateDiscussionChannel(UserProfile peer, UserIdentity myUserIdentity) { - this(PrivateChannel.createChannelId(new Pair<>(peer.getId(), myUserIdentity.getId())), - peer, - myUserIdentity, - new ArrayList<>(), - ChannelNotificationType.ALL); - } - - private PrivateDiscussionChannel(String id, - UserProfile peer, - UserIdentity myProfile, - List chatMessages, - ChannelNotificationType channelNotificationType) { - super(id, myProfile, chatMessages, channelNotificationType, ChannelKind.DISCUSSION); - - this.peer = peer; - } - - @Override - public bisq.chat.protobuf.Channel toProto() { - return getChannelBuilder().setPrivateDiscussionChannel(bisq.chat.protobuf.PrivateDiscussionChannel.newBuilder() - .setPeer(peer.toProto()) - .setMyUserIdentity(myUserIdentity.toProto()) - .addAllChatMessages(chatMessages.stream() - .map(PrivateDiscussionChatMessage::toChatMessageProto) - .collect(Collectors.toList()))) - .build(); - } - - public static PrivateDiscussionChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PrivateDiscussionChannel proto) { - return new PrivateDiscussionChannel( - baseProto.getId(), - UserProfile.fromProto(proto.getPeer()), - UserIdentity.fromProto(proto.getMyUserIdentity()), - proto.getChatMessagesList().stream() - .map(PrivateDiscussionChatMessage::fromProto) - .collect(Collectors.toList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); - } - - @Override - public void addChatMessage(PrivateDiscussionChatMessage chatMessage) { - chatMessages.add(chatMessage); - } - - @Override - public void removeChatMessage(PrivateDiscussionChatMessage chatMessage) { - chatMessages.remove(chatMessage); - } - - @Override - public void removeChatMessages(Collection removeMessages) { - chatMessages.removeAll(removeMessages); - } - - @Override - public String getDisplayString() { - return peer.getUserName() + "-" + myUserIdentity.getUserName(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java deleted file mode 100644 index a34681d9e0..0000000000 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelService.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.discuss.priv; - -import bisq.chat.channel.PrivateChannelService; -import bisq.chat.message.MessageType; -import bisq.chat.message.Quotation; -import bisq.common.observable.ObservableArray; -import bisq.network.NetworkService; -import bisq.network.p2p.message.NetworkMessage; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceService; -import bisq.security.pow.ProofOfWorkService; -import bisq.user.identity.UserIdentity; -import bisq.user.identity.UserIdentityService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Date; -import java.util.Optional; - -@Slf4j -public class PrivateDiscussionChannelService extends PrivateChannelService { - @Getter - private final PrivateDiscussionChannelStore persistableStore = new PrivateDiscussionChannelStore(); - @Getter - private final Persistence persistence; - - public PrivateDiscussionChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService, - ProofOfWorkService proofOfWorkService) { - super(networkService, userIdentityService, proofOfWorkService); - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - } - - @Override - public void onMessage(NetworkMessage networkMessage) { - if (networkMessage instanceof PrivateDiscussionChatMessage) { - processMessage((PrivateDiscussionChatMessage) networkMessage); - } - } - - @Override - protected PrivateDiscussionChatMessage createNewPrivateChatMessage(String messageId, - PrivateDiscussionChannel channel, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long time, - boolean wasEdited, - MessageType messageType) { - return new PrivateDiscussionChatMessage(messageId, - channel.getId(), - sender, - receiversId, - text, - quotedMessage, - new Date().getTime(), - wasEdited, - messageType); - } - - @Override - protected PrivateDiscussionChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { - return new PrivateDiscussionChannel(peer, myUserIdentity); - } - - @Override - public ObservableArray getChannels() { - return persistableStore.getChannels(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelStore.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelStore.java deleted file mode 100644 index 8ca63df1f8..0000000000 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChannelStore.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.discuss.priv; - -import bisq.common.observable.ObservableArray; -import bisq.common.proto.ProtoResolver; -import bisq.common.proto.UnresolvableProtobufMessageException; -import bisq.persistence.PersistableStore; -import com.google.protobuf.InvalidProtocolBufferException; -import lombok.Getter; - -import java.util.List; -import java.util.stream.Collectors; - -@Getter -public class PrivateDiscussionChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); - - public PrivateDiscussionChannelStore() { - } - - private PrivateDiscussionChannelStore(List privateDiscussionChannels) { - setAll(privateDiscussionChannels); - } - - @Override - public bisq.chat.protobuf.PrivateDiscussionChannelStore toProto() { - bisq.chat.protobuf.PrivateDiscussionChannelStore.Builder builder = bisq.chat.protobuf.PrivateDiscussionChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PrivateDiscussionChannel::toProto).collect(Collectors.toList())); - return builder.build(); - } - - public static PrivateDiscussionChannelStore fromProto(bisq.chat.protobuf.PrivateDiscussionChannelStore proto) { - List privateDiscussionChannels = proto.getChannelsList().stream() - .map(e -> (PrivateDiscussionChannel) PrivateDiscussionChannel.fromProto(e)) - .collect(Collectors.toList()); - return new PrivateDiscussionChannelStore(privateDiscussionChannels); - } - - @Override - public ProtoResolver> getResolver() { - return any -> { - try { - return fromProto(any.unpack(bisq.chat.protobuf.PrivateDiscussionChannelStore.class)); - } catch (InvalidProtocolBufferException e) { - throw new UnresolvableProtobufMessageException(e); - } - }; - } - - @Override - public void applyPersisted(PrivateDiscussionChannelStore chatStore) { - setAll(chatStore.getChannels()); - } - - @Override - public PrivateDiscussionChannelStore getClone() { - return new PrivateDiscussionChannelStore(channels); - } - - public void setAll(List privateDiscussionChannels) { - this.channels.clear(); - this.channels.addAll(privateDiscussionChannels); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java b/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java deleted file mode 100644 index 0a683650e9..0000000000 --- a/chat/src/main/java/bisq/chat/discuss/priv/PrivateDiscussionChatMessage.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.discuss.priv; - -import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; -import bisq.chat.message.PrivateChatMessage; -import bisq.chat.message.Quotation; -import bisq.network.p2p.services.data.storage.MetaData; -import bisq.network.protobuf.ExternalNetworkMessage; -import bisq.network.protobuf.NetworkMessage; -import bisq.user.profile.UserProfile; -import com.google.protobuf.Any; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.Optional; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public final class PrivateDiscussionChatMessage extends PrivateChatMessage { - public PrivateDiscussionChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType) { - super(messageId, - channelId, - sender, - receiversId, - text, - quotedMessage, - date, - wasEdited, - messageType, - new MetaData(ChatMessage.TTL, 100000, PrivateDiscussionChatMessage.class.getSimpleName())); - } - - private PrivateDiscussionChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); - } - - @Override - public NetworkMessage toProto() { - return getNetworkMessageBuilder() - .setExternalNetworkMessage(ExternalNetworkMessage.newBuilder().setAny(Any.pack(toChatMessageProto()))) - .build(); - } - - public bisq.chat.protobuf.ChatMessage toChatMessageProto() { - return getChatMessageBuilder() - .setPrivateDiscussionChatMessage(bisq.chat.protobuf.PrivateDiscussionChatMessage.newBuilder() - .setReceiversId(receiversId) - .setSender(sender.toProto())) - .build(); - } - - public static PrivateDiscussionChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { - Optional quotedMessage = baseProto.hasQuotation() ? - Optional.of(Quotation.fromProto(baseProto.getQuotation())) : - Optional.empty(); - bisq.chat.protobuf.PrivateDiscussionChatMessage privateDiscussionChatMessage = baseProto.getPrivateDiscussionChatMessage(); - return new PrivateDiscussionChatMessage( - baseProto.getMessageId(), - baseProto.getChannelId(), - UserProfile.fromProto(privateDiscussionChatMessage.getSender()), - privateDiscussionChatMessage.getReceiversId(), - baseProto.getText(), - quotedMessage, - baseProto.getDate(), - baseProto.getWasEdited(), - MessageType.fromProto(baseProto.getMessageType()), - MetaData.fromProto(baseProto.getMetaData())); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java b/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java index a6d1cd0299..a86a045a9e 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java +++ b/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java @@ -17,7 +17,7 @@ package bisq.chat.discuss.pub; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -67,7 +67,7 @@ private PublicDiscussionChannel(String id, String channelAdminId, List channelModeratorIds, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType, ChannelKind.DISCUSSION); + super(id, channelNotificationType, ChatDomain.DISCUSSION); this.channelName = channelName; this.description = description; diff --git a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java index 57da31d596..7ceb06107b 100644 --- a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java @@ -18,8 +18,8 @@ package bisq.chat.events; import bisq.chat.channel.Channel; -import bisq.chat.events.priv.PrivateEventsChannel; -import bisq.chat.events.priv.PrivateEventsChannelService; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; @@ -37,11 +37,11 @@ public class EventsChannelSelectionService implements PersistenceClient { private final EventsChannelSelectionStore persistableStore = new EventsChannelSelectionStore(); private final Persistence persistence; - private final PrivateEventsChannelService privateChannelService; + private final PrivateTwoPartyChannelService privateChannelService; private final PublicEventsChannelService publicChannelService; public EventsChannelSelectionService(PersistenceService persistenceService, - PrivateEventsChannelService privateChannelService, + PrivateTwoPartyChannelService privateChannelService, PublicEventsChannelService publicChannelService) { persistence = persistenceService.getOrCreatePersistence(this, persistableStore); this.privateChannelService = privateChannelService; @@ -60,8 +60,8 @@ public CompletableFuture shutdown() { } public void selectChannel(Channel channel) { - if (channel instanceof PrivateEventsChannel) { - privateChannelService.removeExpiredMessages((PrivateEventsChannel) channel); + if (channel instanceof PrivateTwoPartyChannel) { + privateChannelService.removeExpiredMessages((PrivateTwoPartyChannel) channel); } getSelectedChannel().set(channel); diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java deleted file mode 100644 index 02001089fa..0000000000 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelService.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.priv; - -import bisq.chat.channel.PrivateChannelService; -import bisq.chat.message.MessageType; -import bisq.chat.message.Quotation; -import bisq.common.observable.ObservableArray; -import bisq.network.NetworkService; -import bisq.network.p2p.message.NetworkMessage; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceService; -import bisq.security.pow.ProofOfWorkService; -import bisq.user.identity.UserIdentity; -import bisq.user.identity.UserIdentityService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Date; -import java.util.Optional; - -@Slf4j -public class PrivateEventsChannelService extends PrivateChannelService { - @Getter - private final PrivateEventsChannelStore persistableStore = new PrivateEventsChannelStore(); - @Getter - private final Persistence persistence; - - public PrivateEventsChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService, - ProofOfWorkService proofOfWorkService) { - super(networkService, userIdentityService, proofOfWorkService); - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - } - - @Override - public void onMessage(NetworkMessage networkMessage) { - if (networkMessage instanceof PrivateEventsChatMessage) { - processMessage((PrivateEventsChatMessage) networkMessage); - } - } - - @Override - protected PrivateEventsChatMessage createNewPrivateChatMessage(String messageId, - PrivateEventsChannel channel, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long time, - boolean wasEdited, - MessageType messageType) { - return new PrivateEventsChatMessage(messageId, - channel.getId(), - sender, - receiversId, - text, - quotedMessage, - new Date().getTime(), - wasEdited, - messageType); - } - - @Override - protected PrivateEventsChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { - return new PrivateEventsChannel(peer, myUserIdentity); - } - - @Override - public ObservableArray getChannels() { - return persistableStore.getChannels(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelStore.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelStore.java deleted file mode 100644 index a5dd517734..0000000000 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChannelStore.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.priv; - -import bisq.common.observable.ObservableArray; -import bisq.common.proto.ProtoResolver; -import bisq.common.proto.UnresolvableProtobufMessageException; -import bisq.persistence.PersistableStore; -import com.google.protobuf.InvalidProtocolBufferException; -import lombok.Getter; - -import java.util.List; -import java.util.stream.Collectors; - -@Getter -public class PrivateEventsChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); - - public PrivateEventsChannelStore() { - } - - private PrivateEventsChannelStore(List privateEventsChannels) { - setAll(privateEventsChannels); - } - - @Override - public bisq.chat.protobuf.PrivateEventsChannelStore toProto() { - bisq.chat.protobuf.PrivateEventsChannelStore.Builder builder = bisq.chat.protobuf.PrivateEventsChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PrivateEventsChannel::toProto).collect(Collectors.toList())); - return builder.build(); - } - - public static PrivateEventsChannelStore fromProto(bisq.chat.protobuf.PrivateEventsChannelStore proto) { - List privateEventsChannels = proto.getChannelsList().stream() - .map(e -> (PrivateEventsChannel) PrivateEventsChannel.fromProto(e)) - .collect(Collectors.toList()); - return new PrivateEventsChannelStore(privateEventsChannels); - } - - @Override - public ProtoResolver> getResolver() { - return any -> { - try { - return fromProto(any.unpack(bisq.chat.protobuf.PrivateEventsChannelStore.class)); - } catch (InvalidProtocolBufferException e) { - throw new UnresolvableProtobufMessageException(e); - } - }; - } - - @Override - public void applyPersisted(PrivateEventsChannelStore chatStore) { - setAll(chatStore.getChannels()); - } - - @Override - public PrivateEventsChannelStore getClone() { - return new PrivateEventsChannelStore(channels); - } - - public void setAll(List privateEventsChannels) { - this.channels.clear(); - this.channels.addAll(privateEventsChannels); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java b/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java deleted file mode 100644 index 8d54f64114..0000000000 --- a/chat/src/main/java/bisq/chat/events/priv/PrivateEventsChatMessage.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.priv; - -import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; -import bisq.chat.message.PrivateChatMessage; -import bisq.chat.message.Quotation; -import bisq.network.p2p.services.data.storage.MetaData; -import bisq.network.protobuf.ExternalNetworkMessage; -import bisq.network.protobuf.NetworkMessage; -import bisq.user.profile.UserProfile; -import com.google.protobuf.Any; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.Optional; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public final class PrivateEventsChatMessage extends PrivateChatMessage { - public PrivateEventsChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType) { - super(messageId, - channelId, - sender, - receiversId, - text, - quotedMessage, - date, - wasEdited, - messageType, - new MetaData(ChatMessage.TTL, 100000, PrivateEventsChatMessage.class.getSimpleName())); - } - - private PrivateEventsChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); - } - - @Override - public NetworkMessage toProto() { - return getNetworkMessageBuilder() - .setExternalNetworkMessage(ExternalNetworkMessage.newBuilder().setAny(Any.pack(toChatMessageProto()))) - .build(); - } - - public bisq.chat.protobuf.ChatMessage toChatMessageProto() { - return getChatMessageBuilder() - .setPrivateEventsChatMessage(bisq.chat.protobuf.PrivateEventsChatMessage.newBuilder() - .setReceiversId(receiversId) - .setSender(sender.toProto())) - .build(); - } - - public static PrivateEventsChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { - Optional quotedMessage = baseProto.hasQuotation() ? - Optional.of(Quotation.fromProto(baseProto.getQuotation())) : - Optional.empty(); - bisq.chat.protobuf.PrivateEventsChatMessage privateEventsChatMessage = baseProto.getPrivateEventsChatMessage(); - return new PrivateEventsChatMessage( - baseProto.getMessageId(), - baseProto.getChannelId(), - UserProfile.fromProto(privateEventsChatMessage.getSender()), - privateEventsChatMessage.getReceiversId(), - baseProto.getText(), - quotedMessage, - baseProto.getDate(), - baseProto.getWasEdited(), - MessageType.fromProto(baseProto.getMessageType()), - MetaData.fromProto(baseProto.getMetaData())); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java index bd055ae4b5..593561620f 100644 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java +++ b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java @@ -17,7 +17,7 @@ package bisq.chat.events.pub; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -67,7 +67,7 @@ private PublicEventsChannel(String id, String channelAdminId, List channelModeratorIds, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType, ChannelKind.EVENTS); + super(id, channelNotificationType, ChatDomain.EVENTS); this.channelName = channelName; this.description = description; diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 07f4a94d6e..927bf2ef0f 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -17,11 +17,9 @@ package bisq.chat.message; -import bisq.chat.discuss.priv.PrivateDiscussionChatMessage; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; import bisq.chat.discuss.pub.PublicDiscussionChatMessage; -import bisq.chat.events.priv.PrivateEventsChatMessage; import bisq.chat.events.pub.PublicEventsChatMessage; -import bisq.chat.support.priv.PrivateSupportChatMessage; import bisq.chat.support.pub.PublicSupportChatMessage; import bisq.chat.trade.priv.PrivateTradeChatMessage; import bisq.chat.trade.pub.PublicTradeChatMessage; @@ -98,6 +96,10 @@ public bisq.chat.protobuf.ChatMessage.Builder getChatMessageBuilder() { public static ChatMessage fromProto(bisq.chat.protobuf.ChatMessage proto) { switch (proto.getMessageCase()) { + case PRIVATETWOPARTYCHATMESSAGE: { + return PrivateTwoPartyChatMessage.fromProto(proto); + } + case PUBLICTRADECHATMESSAGE: { return PublicTradeChatMessage.fromProto(proto); } @@ -108,23 +110,15 @@ public static ChatMessage fromProto(bisq.chat.protobuf.ChatMessage proto) { case PUBLICDISCUSSIONCHATMESSAGE: { return PublicDiscussionChatMessage.fromProto(proto); } - case PRIVATEDISCUSSIONCHATMESSAGE: { - return PrivateDiscussionChatMessage.fromProto(proto); - } + case PUBLICEVENTSCHATMESSAGE: { return PublicEventsChatMessage.fromProto(proto); } - case PRIVATEEVENTSCHATMESSAGE: { - return PrivateEventsChatMessage.fromProto(proto); - } case PUBLICSUPPORTCHATMESSAGE: { return PublicSupportChatMessage.fromProto(proto); } - case PRIVATESUPPORTCHATMESSAGE: { - return PrivateSupportChatMessage.fromProto(proto); - } case MESSAGE_NOT_SET: { throw new UnresolvableProtobufMessageException(proto); @@ -166,18 +160,14 @@ public static ProtoResolver getNetworkM try { bisq.chat.protobuf.ChatMessage proto = any.unpack(bisq.chat.protobuf.ChatMessage.class); switch (proto.getMessageCase()) { + case PRIVATETWOPARTYCHATMESSAGE: { + return PrivateTwoPartyChatMessage.fromProto(proto); + } + case PRIVATETRADECHATMESSAGE: { return PrivateTradeChatMessage.fromProto(proto); } - case PRIVATEDISCUSSIONCHATMESSAGE: { - return PrivateDiscussionChatMessage.fromProto(proto); - } - case PRIVATEEVENTSCHATMESSAGE: { - return PrivateEventsChatMessage.fromProto(proto); - } - case PRIVATESUPPORTCHATMESSAGE: { - return PrivateSupportChatMessage.fromProto(proto); - } + case MESSAGE_NOT_SET: { throw new UnresolvableProtobufMessageException(proto); } diff --git a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java index 25a0f31504..5e0ac87785 100644 --- a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java @@ -18,9 +18,9 @@ package bisq.chat.support; import bisq.chat.channel.Channel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.message.ChatMessage; -import bisq.chat.support.priv.PrivateSupportChannel; -import bisq.chat.support.priv.PrivateSupportChannelService; import bisq.chat.support.pub.PublicSupportChannelService; import bisq.common.observable.Observable; import bisq.persistence.Persistence; @@ -37,11 +37,11 @@ public class SupportChannelSelectionService implements PersistenceClient { private final SupportChannelSelectionStore persistableStore = new SupportChannelSelectionStore(); private final Persistence persistence; - private final PrivateSupportChannelService privateChannelService; + private final PrivateTwoPartyChannelService privateChannelService; private final PublicSupportChannelService publicChannelService; public SupportChannelSelectionService(PersistenceService persistenceService, - PrivateSupportChannelService privateChannelService, + PrivateTwoPartyChannelService privateChannelService, PublicSupportChannelService publicChannelService) { persistence = persistenceService.getOrCreatePersistence(this, persistableStore); this.privateChannelService = privateChannelService; @@ -60,8 +60,8 @@ public CompletableFuture shutdown() { } public void selectChannel(Channel channel) { - if (channel instanceof PrivateSupportChannel) { - privateChannelService.removeExpiredMessages((PrivateSupportChannel) channel); + if (channel instanceof PrivateTwoPartyChannel) { + privateChannelService.removeExpiredMessages((PrivateTwoPartyChannel) channel); } getSelectedChannel().set(channel); diff --git a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java b/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java deleted file mode 100644 index 51f1ed0398..0000000000 --- a/chat/src/main/java/bisq/chat/support/priv/PrivateSupportChannel.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support.priv; - -import bisq.chat.ChannelKind; -import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PrivateChannel; -import bisq.common.data.Pair; -import bisq.user.identity.UserIdentity; -import bisq.user.profile.UserProfile; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -@ToString(callSuper = true) -@Getter -@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PrivateSupportChannel extends PrivateChannel { - private final UserProfile peer; - - public PrivateSupportChannel(UserProfile peer, UserIdentity myUserIdentity) { - this(PrivateChannel.createChannelId(new Pair<>(peer.getId(), myUserIdentity.getId())), - peer, - myUserIdentity, - new ArrayList<>(), - ChannelNotificationType.ALL); - } - - private PrivateSupportChannel(String id, - UserProfile peer, - UserIdentity myProfile, - List chatMessages, - ChannelNotificationType channelNotificationType) { - super(id, myProfile, chatMessages, channelNotificationType, ChannelKind.SUPPORT); - - this.peer = peer; - } - - @Override - public bisq.chat.protobuf.Channel toProto() { - return getChannelBuilder().setPrivateSupportChannel(bisq.chat.protobuf.PrivateSupportChannel.newBuilder() - .setPeer(peer.toProto()) - .setMyUserIdentity(myUserIdentity.toProto()) - .addAllChatMessages(chatMessages.stream() - .map(PrivateSupportChatMessage::toChatMessageProto) - .collect(Collectors.toList()))) - .build(); - } - - public static PrivateSupportChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PrivateSupportChannel proto) { - return new PrivateSupportChannel( - baseProto.getId(), - UserProfile.fromProto(proto.getPeer()), - UserIdentity.fromProto(proto.getMyUserIdentity()), - proto.getChatMessagesList().stream() - .map(PrivateSupportChatMessage::fromProto) - .collect(Collectors.toList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); - } - - @Override - public void addChatMessage(PrivateSupportChatMessage chatMessage) { - chatMessages.add(chatMessage); - } - - @Override - public void removeChatMessage(PrivateSupportChatMessage chatMessage) { - chatMessages.remove(chatMessage); - } - - @Override - public void removeChatMessages(Collection removeMessages) { - chatMessages.removeAll(removeMessages); - } - - @Override - public String getDisplayString() { - return peer.getUserName() + "-" + myUserIdentity.getUserName(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java index c051a716e0..1c3c15dc6f 100644 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java +++ b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java @@ -17,7 +17,7 @@ package bisq.chat.support.pub; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -67,7 +67,7 @@ private PublicSupportChannel(String id, String channelAdminId, List channelModeratorIds, ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType, ChannelKind.SUPPORT); + super(id, channelNotificationType, ChatDomain.SUPPORT); this.channelName = channelName; this.description = description; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index 2eaefd1760..53f7081ccc 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -17,7 +17,7 @@ package bisq.chat.trade.priv; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -88,7 +88,7 @@ private PrivateTradeChannel(String id, Optional mediator, List chatMessages, ChannelNotificationType channelNotificationType) { - super(id, myUserIdentity, chatMessages, channelNotificationType, ChannelKind.TRADE); + super(id, myUserIdentity, chatMessages, channelNotificationType, ChatDomain.TRADE); this.peerOrTrader1 = peerOrTrader1; this.myUserProfileOrTrader2 = myUserProfileOrTrader2; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index 1f1f59cbf9..12e3e77f13 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.trade.priv; +import bisq.chat.ChatDomain; import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; @@ -51,7 +52,7 @@ public PrivateTradeChannelService(PersistenceService persistenceService, NetworkService networkService, UserIdentityService userIdentityService, ProofOfWorkService proofOfWorkService) { - super(networkService, userIdentityService, proofOfWorkService); + super(networkService, userIdentityService, proofOfWorkService, ChatDomain.TRADE); persistence = persistenceService.getOrCreatePersistence(this, persistableStore); } diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index 4e77176bc0..b524ed0961 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -17,7 +17,7 @@ package bisq.chat.trade.pub; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.common.currency.Market; @@ -39,7 +39,7 @@ public PublicTradeChannel(Market market) { } private PublicTradeChannel(String id, Market market) { - super(id, ChannelNotificationType.MENTION, ChannelKind.TRADE); + super(id, ChannelNotificationType.MENTION, ChatDomain.TRADE); this.market = market; } diff --git a/chat/src/main/proto/chat.proto b/chat/src/main/proto/chat.proto index 5cc7f2ee09..1a20589850 100644 --- a/chat/src/main/proto/chat.proto +++ b/chat/src/main/proto/chat.proto @@ -44,16 +44,13 @@ message ChatMessage { MessageType messageType = 8; network.MetaData metaData = 9; oneof message { - PrivateTradeChatMessage privateTradeChatMessage = 20; - PublicTradeChatMessage publicTradeChatMessage = 21; + PrivateTwoPartyChatMessage privateTwoPartyChatMessage = 20; - PrivateDiscussionChatMessage privateDiscussionChatMessage = 22; - PublicDiscussionChatMessage publicDiscussionChatMessage = 23; + PrivateTradeChatMessage privateTradeChatMessage = 22; + PublicTradeChatMessage publicTradeChatMessage = 23; - PrivateEventsChatMessage privateEventsChatMessage = 24; + PublicDiscussionChatMessage publicDiscussionChatMessage = 24; PublicEventsChatMessage publicEventsChatMessage = 25; - - PrivateSupportChatMessage privateSupportChatMessage = 26; PublicSupportChatMessage publicSupportChatMessage = 27; } } @@ -68,20 +65,25 @@ enum ChannelNotificationType { NEVER = 2; } +enum ChatDomain { + TRADE = 0; + DISCUSSION = 1; + EVENTS = 2; + SUPPORT = 3; +} + message Channel { string id = 1; ChannelNotificationType channelNotificationType = 2; + ChatDomain chatDomain = 3; oneof message{ - PrivateTradeChannel privateTradeChannel = 10; - PublicTradeChannel publicTradeChannel = 11; + PrivateTwoPartyChannel privateTwoPartyChannel = 10; - PrivateDiscussionChannel privateDiscussionChannel = 12; - PublicDiscussionChannel publicDiscussionChannel = 13; + PrivateTradeChannel privateTradeChannel = 12; + PublicTradeChannel publicTradeChannel = 13; - PrivateEventsChannel privateEventsChannel = 14; + PublicDiscussionChannel publicDiscussionChannel = 14; PublicEventsChannel publicEventsChannel = 15; - - PrivateSupportChannel privateSupportChannel = 16; PublicSupportChannel publicSupportChannel = 17; } } @@ -133,18 +135,23 @@ message PublicTradeChannelStore { repeated string visibleChannelIds = 2; } -// Support -message PrivateDiscussionChatMessage { +// PrivateTwoParty +message PrivateTwoPartyChatMessage { string receiversId = 1; user.UserProfile sender = 2; } -message PublicDiscussionChatMessage { -} -message PrivateDiscussionChannel { +message PrivateTwoPartyChannel { user.UserProfile peer = 1; user.UserIdentity myUserIdentity = 2; repeated ChatMessage chatMessages = 3; } +message PrivateTwoPartyChannelStore { + repeated Channel channels = 1; +} + + +message PublicDiscussionChatMessage { +} message PublicDiscussionChannel { string channelName = 1; @@ -158,26 +165,16 @@ message DiscussionChannelSelectionStore { optional Channel selectedChannel = 1; } -message PrivateDiscussionChannelStore { - repeated Channel channels = 1; -} + message PublicDiscussionChannelStore { repeated Channel channels = 1; } // Events -message PrivateEventsChatMessage { - string receiversId = 1; - user.UserProfile sender = 2; -} message PublicEventsChatMessage { } -message PrivateEventsChannel { - user.UserProfile peer = 1; - user.UserIdentity myUserIdentity = 2; - repeated ChatMessage chatMessages = 3; -} + message PublicEventsChannel { string channelName = 1; @@ -189,26 +186,15 @@ message PublicEventsChannel { message EventsChannelSelectionStore { optional Channel selectedChannel = 1; } -message PrivateEventsChannelStore { - repeated Channel channels = 1; -} message PublicEventsChannelStore { repeated Channel channels = 1; } // Support -message PrivateSupportChatMessage { - string receiversId = 1; - user.UserProfile sender = 2; -} message PublicSupportChatMessage { } -message PrivateSupportChannel { - user.UserProfile peer = 1; - user.UserIdentity myUserIdentity = 2; - repeated ChatMessage chatMessages = 3; -} + message PublicSupportChannel { string channelName = 1; @@ -220,9 +206,7 @@ message PublicSupportChannel { message SupportChannelSelectionStore { optional Channel selectedChannel = 1; } -message PrivateSupportChannelStore { - repeated Channel channels = 1; -} + message PublicSupportChannelStore { repeated Channel channels = 1; diff --git a/common/src/main/java/bisq/common/util/StringUtils.java b/common/src/main/java/bisq/common/util/StringUtils.java index c9216c2628..3662e746b7 100644 --- a/common/src/main/java/bisq/common/util/StringUtils.java +++ b/common/src/main/java/bisq/common/util/StringUtils.java @@ -87,4 +87,14 @@ public static String deriveWordStartingWith(String text, char indicatorSign) { } return null; } + + public static String capitalize(String value) { + if (value == null || value.isEmpty()) { + return value; + } else if (value.length() == 1) { + return value.toUpperCase(); + } else { + return value.substring(0, 1).toUpperCase() + value.substring(1).toLowerCase(); + } + } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java index 34caf72422..9ce3abe63b 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java @@ -18,7 +18,7 @@ package bisq.desktop.primary.main.content.chat; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.ChatService; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; @@ -71,7 +71,7 @@ public abstract class ChatController ex protected Subscription notificationSettingSubscription; private Subscription searchTextPin; - public ChatController(DefaultApplicationService applicationService, ChannelKind channelKind, NavigationTarget host) { + public ChatController(DefaultApplicationService applicationService, ChatDomain chatDomain, NavigationTarget host) { super(host); this.applicationService = applicationService; @@ -79,8 +79,8 @@ public ChatController(DefaultApplicationService applicationService, ChannelKind userIdentityService = applicationService.getUserService().getUserIdentityService(); userProfileService = applicationService.getUserService().getUserProfileService(); reputationService = applicationService.getUserService().getReputationService(); - privateChannelSelection = new PrivateChannelSelection(applicationService, channelKind); - chatMessagesComponent = new ChatMessagesComponent(applicationService, channelKind); + privateChannelSelection = new PrivateChannelSelection(applicationService, chatDomain); + chatMessagesComponent = new ChatMessagesComponent(applicationService, chatDomain); channelSidebar = new ChannelSidebar(applicationService, () -> { onCloseSideBar(); chatMessagesComponent.resetSelectedChatMessage(); @@ -88,13 +88,13 @@ public ChatController(DefaultApplicationService applicationService, ChannelKind quotedMessageBlock = new QuotedMessageBlock(applicationService); createComponents(); - model = getChatModel(channelKind); + model = getChatModel(chatDomain); view = getChatView(); } public abstract void createComponents(); - public abstract M getChatModel(ChannelKind channelKind); + public abstract M getChatModel(ChatDomain chatDomain); public abstract V getChatView(); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index c4d75d0dd4..e8e487e937 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -18,18 +18,14 @@ package bisq.desktop.primary.main.content.chat.channels; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.priv.PrivateDiscussionChannel; -import bisq.chat.discuss.priv.PrivateDiscussionChannelService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.priv.PrivateEventsChannel; -import bisq.chat.events.priv.PrivateEventsChannelService; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.priv.PrivateSupportChannel; -import bisq.chat.support.priv.PrivateSupportChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -71,8 +67,8 @@ public class PrivateChannelSelection extends ChannelSelection { private final Controller controller; - public PrivateChannelSelection(DefaultApplicationService applicationService, ChannelKind channelKind) { - controller = new Controller(applicationService, channelKind); + public PrivateChannelSelection(DefaultApplicationService applicationService, ChatDomain chatDomain) { + controller = new Controller(applicationService, chatDomain); } public Pane getRoot() { @@ -89,16 +85,16 @@ protected static class Controller extends ChannelSelection.Controller { private final View view; private final PrivateTradeChannelService privateTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final PrivateDiscussionChannelService privateDiscussionChannelService; + private final PrivateTwoPartyChannelService privateDiscussionChannelService; private final DiscussionChannelSelectionService discussionChannelSelectionService; - private final PrivateEventsChannelService privateEventsChannelService; - private final PrivateSupportChannelService privateSupportChannelService; + private final PrivateTwoPartyChannelService privateEventsChannelService; + private final PrivateTwoPartyChannelService privateSupportChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; private final SupportChannelSelectionService supportChannelSelectionService; private final UserIdentityService userIdentityService; private Pin inMediationPin; - protected Controller(DefaultApplicationService applicationService, ChannelKind channelKind) { + protected Controller(DefaultApplicationService applicationService, ChatDomain chatDomain) { super(applicationService.getChatService()); privateTradeChannelService = chatService.getPrivateTradeChannelService(); @@ -115,7 +111,7 @@ protected Controller(DefaultApplicationService applicationService, ChannelKind c userIdentityService = applicationService.getUserService().getUserIdentityService(); - model = new Model(channelKind); + model = new Model(chatDomain); view = new View(model, this); model.filteredList.setPredicate(item -> true); @@ -130,7 +126,7 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - if (model.channelKind == ChannelKind.TRADE) { + if (model.chatDomain == ChatDomain.TRADE) { channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateTradeChannelService.getChannels()); @@ -146,40 +142,40 @@ public void onActivate() { inMediationPin = FxBindings.bind(model.mediationActivated).to(((PrivateTradeChannel) channel).getInMediation()); } }); - } else if (model.channelKind == ChannelKind.DISCUSSION) { - channelsPin = FxBindings.bind(model.channelItems) + } else if (model.chatDomain == ChatDomain.DISCUSSION) { + channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateDiscussionChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(discussionChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PrivateDiscussionChannel) { + if (channel instanceof PrivateTwoPartyChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel, userIdentityService)); - userIdentityService.selectChatUserIdentity(((PrivateDiscussionChannel) channel).getMyUserIdentity()); + userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); } }); - } else if (model.channelKind == ChannelKind.EVENTS) { - channelsPin = FxBindings.bind(model.channelItems) + } else if (model.chatDomain == ChatDomain.EVENTS) { + channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateEventsChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(eventsChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PrivateEventsChannel) { + if (channel instanceof PrivateTwoPartyChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel, userIdentityService)); - userIdentityService.selectChatUserIdentity(((PrivateEventsChannel) channel).getMyUserIdentity()); + userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); } }); - } else if (model.channelKind == ChannelKind.SUPPORT) { - channelsPin = FxBindings.bind(model.channelItems) + } else if (model.chatDomain == ChatDomain.SUPPORT) { + channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateSupportChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(supportChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PrivateSupportChannel) { + if (channel instanceof PrivateTwoPartyChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel, userIdentityService)); - userIdentityService.selectChatUserIdentity(((PrivateSupportChannel) channel).getMyUserIdentity()); + userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); } }); } @@ -198,13 +194,13 @@ protected void onSelected(ChannelSelection.View.ChannelItem channelItem) { if (channelItem == null) { return; } - if (model.channelKind == ChannelKind.TRADE) { + if (model.chatDomain == ChatDomain.TRADE) { tradeChannelSelectionService.selectChannel(channelItem.getChannel()); - } else if (model.channelKind == ChannelKind.DISCUSSION) { + } else if (model.chatDomain == ChatDomain.DISCUSSION) { discussionChannelSelectionService.selectChannel(channelItem.getChannel()); - } else if (model.channelKind == ChannelKind.EVENTS) { + } else if (model.chatDomain == ChatDomain.EVENTS) { eventsChannelSelectionService.selectChannel(channelItem.getChannel()); - } else if (model.channelKind == ChannelKind.SUPPORT) { + } else if (model.chatDomain == ChatDomain.SUPPORT) { supportChannelSelectionService.selectChannel(channelItem.getChannel()); } } @@ -222,7 +218,7 @@ public void onLeaveChannel(PrivateChannel privateChannel) { } public void doLeaveChannel(PrivateChannel privateChannel) { - switch (privateChannel.getChannelKind()) { + switch (privateChannel.getChatDomain()) { case TRADE -> { privateTradeChannelService.leaveChannel((PrivateTradeChannel) privateChannel); } @@ -245,11 +241,11 @@ public void doLeaveChannel(PrivateChannel privateChannel) { } protected static class Model extends ChannelSelection.Model { - private final ChannelKind channelKind; + private final ChatDomain chatDomain; private final BooleanProperty mediationActivated = new SimpleBooleanProperty(); - public Model(ChannelKind channelKind) { - this.channelKind = channelKind; + public Model(ChatDomain chatDomain) { + this.chatDomain = chatDomain; } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index d417d78ba9..598516bdab 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -110,7 +110,55 @@ void setChannel(Channel channel) { .sorted() .collect(Collectors.toList())); - if (channel instanceof PublicTradeChannel) { + switch (channel.getChatDomain()) { + case TRADE -> { + model.description.set(((PublicTradeChannel) channel).getDescription()); + model.descriptionVisible.set(true); + model.adminProfile = Optional.empty(); + model.moderators.clear(); + } + case DISCUSSION -> { + PublicDiscussionChannel publicDiscussionChannel = (PublicDiscussionChannel) channel; + model.description.set(publicDiscussionChannel.getDescription()); + model.descriptionVisible.set(true); + model.adminProfile = userProfileService.findUserProfile(publicDiscussionChannel.getChannelAdminId()).map(ChatUserOverview::new); + model.moderators.setAll(publicDiscussionChannel.getChannelModeratorIds().stream() + .flatMap(id -> userProfileService.findUserProfile(id).stream()) + .map(ChatUserOverview::new) + .sorted() + .collect(Collectors.toList())); + } + case EVENTS -> { + PublicEventsChannel publicEventsChannel = (PublicEventsChannel) channel; + model.description.set(publicEventsChannel.getDescription()); + model.descriptionVisible.set(true); + model.adminProfile = userProfileService.findUserProfile(publicEventsChannel.getChannelAdminId()).map(ChatUserOverview::new); + model.moderators.setAll(publicEventsChannel.getChannelModeratorIds().stream() + .flatMap(id -> userProfileService.findUserProfile(id).stream()) + .map(ChatUserOverview::new) + .sorted() + .collect(Collectors.toList())); + } + case SUPPORT -> { + PublicSupportChannel publicSupportChannel = (PublicSupportChannel) channel; + model.description.set(publicSupportChannel.getDescription()); + model.descriptionVisible.set(true); + model.adminProfile = userProfileService.findUserProfile(publicSupportChannel.getChannelAdminId()).map(ChatUserOverview::new); + model.moderators.setAll(publicSupportChannel.getChannelModeratorIds().stream() + .flatMap(id -> userProfileService.findUserProfile(id).stream()) + .map(ChatUserOverview::new) + .sorted() + .collect(Collectors.toList())); + } + default -> { + model.descriptionVisible.set(false); + model.description.set(null); + model.adminProfile = Optional.empty(); + model.moderators.clear(); + } + } + + /* if (channel instanceof PublicTradeChannel) { model.description.set(((PublicTradeChannel) channel).getDescription()); model.descriptionVisible.set(true); model.adminProfile = Optional.empty(); @@ -150,7 +198,7 @@ void setChannel(Channel channel) { model.description.set(null); model.adminProfile = Optional.empty(); model.moderators.clear(); - } + }*/ model.channel.set(channel); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 6f5d2e5444..32c8939435 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -18,25 +18,21 @@ package bisq.desktop.primary.main.content.components; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.ChatService; import bisq.chat.channel.Channel; import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.priv.PrivateDiscussionChannel; -import bisq.chat.discuss.priv.PrivateDiscussionChannelService; import bisq.chat.discuss.pub.PublicDiscussionChannel; import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.priv.PrivateEventsChannel; -import bisq.chat.events.priv.PrivateEventsChannelService; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.message.ChatMessage; import bisq.chat.message.Quotation; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.priv.PrivateSupportChannel; -import bisq.chat.support.priv.PrivateSupportChannelService; import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.support.pub.PublicSupportChannelService; import bisq.chat.trade.TradeChannelSelectionService; @@ -82,8 +78,8 @@ public class ChatMessagesComponent { private final Controller controller; - public ChatMessagesComponent(DefaultApplicationService applicationService, ChannelKind channelKind) { - controller = new Controller(applicationService, channelKind); + public ChatMessagesComponent(DefaultApplicationService applicationService, ChatDomain chatDomain) { + controller = new Controller(applicationService, chatDomain); } public Pane getRoot() { @@ -127,24 +123,24 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final ChatMessagesListView chatMessagesListView; private final UserProfileService userProfileService; private final PrivateTradeChannelService privateTradeChannelService; - private final PrivateDiscussionChannelService privateDiscussionChannelService; + private final PrivateTwoPartyChannelService privateDiscussionChannelService; private final PublicDiscussionChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; private final PublicEventsChannelService publicEventsChannelService; - private final PrivateEventsChannelService privateEventsChannelService; + private final PrivateTwoPartyChannelService privateEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; private final PublicSupportChannelService publicSupportChannelService; - private final PrivateSupportChannelService privateSupportChannelService; + private final PrivateTwoPartyChannelService privateSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; private final UserProfileSelection userProfileSelection; private Pin selectedChannelPin; private Pin chatMessagesPin; private Controller(DefaultApplicationService applicationService, - ChannelKind channelKind) { + ChatDomain chatDomain) { ChatService chatService = applicationService.getChatService(); publicTradeChannelService = chatService.getPublicTradeChannelService(); privateTradeChannelService = chatService.getPrivateTradeChannelService(); @@ -172,9 +168,9 @@ private Controller(DefaultApplicationService applicationService, this::mentionUser, this::showChatUserDetails, this::onReply, - channelKind); + chatDomain); - model = new Model(channelKind); + model = new Model(chatDomain); view = new View(model, this, chatMessagesListView.getRoot(), quotedMessageBlock.getRoot(), @@ -186,13 +182,13 @@ public void onActivate() { model.mentionableUsers.setAll(userProfileService.getUserProfiles()); model.mentionableChannels.setAll(publicDiscussionChannelService.getMentionableChannels()); - if (model.getChannelKind() == ChannelKind.TRADE) { + if (model.getChatDomain() == ChatDomain.TRADE) { selectedChannelPin = tradeChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); - } else if (model.getChannelKind() == ChannelKind.DISCUSSION) { + } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { selectedChannelPin = discussionChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); - } else if (model.getChannelKind() == ChannelKind.EVENTS) { + } else if (model.getChatDomain() == ChatDomain.EVENTS) { selectedChannelPin = eventsChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); - } else if (model.getChannelKind() == ChannelKind.SUPPORT) { + } else if (model.getChatDomain() == ChatDomain.SUPPORT) { selectedChannelPin = supportChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); } @@ -262,16 +258,24 @@ private void doSendMessage(String text) { } } else if (channel instanceof PublicDiscussionChannel) { publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicDiscussionChannel) channel, userIdentity); - } else if (channel instanceof PrivateDiscussionChannel) { - privateDiscussionChannelService.sendPrivateChatMessage(text, quotation, (PrivateDiscussionChannel) channel); + } else if (channel instanceof PrivateTwoPartyChannel) { + switch (channel.getChatDomain()) { + case TRADE -> { + } + case DISCUSSION -> { + privateDiscussionChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); + } + case EVENTS -> { + privateEventsChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); + } + case SUPPORT -> { + privateSupportChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); + } + } } else if (channel instanceof PublicEventsChannel) { publicEventsChannelService.publishChatMessage(text, quotation, (PublicEventsChannel) channel, userIdentity); - } else if (channel instanceof PrivateEventsChannel) { - privateEventsChannelService.sendPrivateChatMessage(text, quotation, (PrivateEventsChannel) channel); } else if (channel instanceof PublicSupportChannel) { publicSupportChannelService.publishChatMessage(text, quotation, (PublicSupportChannel) channel, userIdentity); - } else if (channel instanceof PrivateSupportChannel) { - privateSupportChannelService.sendPrivateChatMessage(text, quotation, (PrivateSupportChannel) channel); } quotedMessageBlock.close(); } @@ -297,16 +301,16 @@ private void fillChannelMention(Channel channel) { } private void createAndSelectPrivateChannel(UserProfile peer) { - if (model.getChannelKind() == ChannelKind.TRADE) { + if (model.getChatDomain() == ChatDomain.TRADE) { privateTradeChannelService.maybeCreateAndAddChannel(peer) .ifPresent(tradeChannelSelectionService::selectChannel); - } else if (model.getChannelKind() == ChannelKind.DISCUSSION) { + } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { privateDiscussionChannelService.maybeCreateAndAddChannel(peer) .ifPresent(discussionChannelSelectionService::selectChannel); - } else if (model.getChannelKind() == ChannelKind.EVENTS) { + } else if (model.getChatDomain() == ChatDomain.EVENTS) { privateEventsChannelService.maybeCreateAndAddChannel(peer) .ifPresent(eventsChannelSelectionService::selectChannel); - } else if (model.getChannelKind() == ChannelKind.SUPPORT) { + } else if (model.getChatDomain() == ChatDomain.SUPPORT) { privateSupportChannelService.maybeCreateAndAddChannel(peer) .ifPresent(supportChannelSelectionService::selectChannel); } @@ -374,13 +378,13 @@ private static class Model implements bisq.desktop.common.view.Model { private final ObjectProperty moreOptionsVisibleMessage = new SimpleObjectProperty<>(null); private final ObservableList mentionableUsers = FXCollections.observableArrayList(); private final ObservableList> mentionableChannels = FXCollections.observableArrayList(); - private final ChannelKind channelKind; + private final ChatDomain chatDomain; @Nullable private ChatMessage selectedChatMessage; private Optional> showChatUserDetailsHandler = Optional.empty(); - private Model(ChannelKind channelKind) { - this.channelKind = channelKind; + private Model(ChatDomain chatDomain) { + this.chatDomain = chatDomain; } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 4302252abd..4959d4dac8 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -18,20 +18,17 @@ package bisq.desktop.primary.main.content.components; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.ChatService; import bisq.chat.channel.Channel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.priv.PrivateDiscussionChannel; -import bisq.chat.discuss.priv.PrivateDiscussionChannelService; -import bisq.chat.discuss.priv.PrivateDiscussionChatMessage; import bisq.chat.discuss.pub.PublicDiscussionChannel; import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.discuss.pub.PublicDiscussionChatMessage; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.priv.PrivateEventsChannel; -import bisq.chat.events.priv.PrivateEventsChannelService; -import bisq.chat.events.priv.PrivateEventsChatMessage; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.events.pub.PublicEventsChatMessage; @@ -39,9 +36,6 @@ import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.priv.PrivateSupportChannel; -import bisq.chat.support.priv.PrivateSupportChannelService; -import bisq.chat.support.priv.PrivateSupportChatMessage; import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.support.pub.PublicSupportChannelService; import bisq.chat.support.pub.PublicSupportChatMessage; @@ -119,12 +113,12 @@ public ChatMessagesListView(DefaultApplicationService applicationService, Consumer mentionUserHandler, Consumer showChatUserDetailsHandler, Consumer replyHandler, - ChannelKind channelKind) { + ChatDomain chatDomain) { controller = new Controller(applicationService, mentionUserHandler, showChatUserDetailsHandler, replyHandler, - channelKind); + chatDomain); } public Pane getRoot() { @@ -169,7 +163,7 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final View view; private final ChatService chatService; private final PrivateTradeChannelService privateTradeChannelService; - private final PrivateDiscussionChannelService privateDiscussionChannelService; + private final PrivateTwoPartyChannelService privateDiscussionChannelService; private final PublicDiscussionChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final UserIdentityService userIdentityService; @@ -181,10 +175,10 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; - private final PrivateEventsChannelService privateEventsChannelService; + private final PrivateTwoPartyChannelService privateEventsChannelService; private final PublicEventsChannelService publicEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; - private final PrivateSupportChannelService privateSupportChannelService; + private final PrivateTwoPartyChannelService privateSupportChannelService; private final PublicSupportChannelService publicSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; private final MediationService mediationService; @@ -195,7 +189,7 @@ private Controller(DefaultApplicationService applicationService, Consumer mentionUserHandler, Consumer showChatUserDetailsHandler, Consumer replyHandler, - ChannelKind channelKind) { + ChatDomain chatDomain) { chatService = applicationService.getChatService(); privateTradeChannelService = chatService.getPrivateTradeChannelService(); @@ -225,7 +219,7 @@ private Controller(DefaultApplicationService applicationService, model = new Model(chatService, userIdentityService, - channelKind); + chatDomain); view = new View(model, this); } @@ -243,7 +237,7 @@ public void onActivate() { model.getSortedChatMessages().setComparator(ChatMessagesListView.ChatMessageListItem::compareTo); - if (model.getChannelKind() == ChannelKind.TRADE) { + if (model.getChatDomain() == ChatDomain.TRADE) { selectedChannelPin = tradeChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (chatMessagesPin != null) { @@ -266,7 +260,7 @@ public void onActivate() { model.chatMessages.clear(); } }); - } else if (model.getChannelKind() == ChannelKind.DISCUSSION) { + } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { selectedChannelPin = discussionChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (channel instanceof PublicDiscussionChannel) { @@ -277,17 +271,17 @@ public void onActivate() { .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) .to(((PublicDiscussionChannel) channel).getChatMessages()); model.allowEditing.set(true); - } else if (channel instanceof PrivateDiscussionChannel) { + } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PrivateDiscussionChannel) channel).getChatMessages()); + .to(((PrivateTwoPartyChannel) channel).getChatMessages()); model.allowEditing.set(false); } }); - } else if (model.getChannelKind() == ChannelKind.EVENTS) { + } else if (model.getChatDomain() == ChatDomain.EVENTS) { selectedChannelPin = eventsChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (channel instanceof PublicEventsChannel) { @@ -298,17 +292,17 @@ public void onActivate() { .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) .to(((PublicEventsChannel) channel).getChatMessages()); model.allowEditing.set(true); - } else if (channel instanceof PrivateEventsChannel) { + } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PrivateEventsChannel) channel).getChatMessages()); + .to(((PrivateTwoPartyChannel) channel).getChatMessages()); model.allowEditing.set(false); } }); - } else if (model.getChannelKind() == ChannelKind.SUPPORT) { + } else if (model.getChatDomain() == ChatDomain.SUPPORT) { selectedChannelPin = supportChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (channel instanceof PublicSupportChannel) { @@ -319,13 +313,13 @@ public void onActivate() { .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) .to(((PublicSupportChannel) channel).getChatMessages()); model.allowEditing.set(true); - } else if (channel instanceof PrivateSupportChannel) { + } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PrivateSupportChannel) channel).getChatMessages()); + .to(((PrivateTwoPartyChannel) channel).getChatMessages()); model.allowEditing.set(false); } }); @@ -499,14 +493,14 @@ private boolean isMyMessage(ChatMessage chatMessage) { } private void createAndSelectPrivateChannel(UserProfile peer) { - if (model.getChannelKind() == ChannelKind.TRADE) { + if (model.getChatDomain() == ChatDomain.TRADE) { PrivateTradeChannel privateTradeChannel = getPrivateTradeChannel(peer); tradeChannelSelectionService.selectChannel(privateTradeChannel); - } else if (model.getChannelKind() == ChannelKind.DISCUSSION) { + } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { privateDiscussionChannelService.maybeCreateAndAddChannel(peer).ifPresent(discussionChannelSelectionService::selectChannel); - } else if (model.getChannelKind() == ChannelKind.EVENTS) { + } else if (model.getChatDomain() == ChatDomain.EVENTS) { privateEventsChannelService.maybeCreateAndAddChannel(peer).ifPresent(eventsChannelSelectionService::selectChannel); - } else if (model.getChannelKind() == ChannelKind.SUPPORT) { + } else if (model.getChatDomain() == ChatDomain.SUPPORT) { privateSupportChannelService.maybeCreateAndAddChannel(peer).ifPresent(supportChannelSelectionService::selectChannel); } } @@ -550,7 +544,7 @@ private static class Model implements bisq.desktop.common.view.Model { private final SortedList> sortedChatMessages = new SortedList<>(filteredChatMessages); private final BooleanProperty allowEditing = new SimpleBooleanProperty(); private final ObjectProperty selectedChatMessageForMoreOptionsPopup = new SimpleObjectProperty<>(null); - private final ChannelKind channelKind; + private final ChatDomain chatDomain; @Setter private Predicate> searchPredicate = e -> true; private Optional createOfferCompleteHandler = Optional.empty(); @@ -559,10 +553,10 @@ private static class Model implements bisq.desktop.common.view.Model { private Model(ChatService chatService, UserIdentityService userIdentityService, - ChannelKind channelKind) { + ChatDomain chatDomain) { this.chatService = chatService; this.userIdentityService = userIdentityService; - this.channelKind = channelKind; + this.chatDomain = chatDomain; } boolean isMyMessage(ChatMessage chatMessage) { @@ -919,7 +913,7 @@ private void handleReactionsBox(ChatMessageListItem item) replyIcon.setOnMouseClicked(e -> controller.onReply(chatMessage)); pmIcon.setOnMouseClicked(e -> controller.onOpenPrivateChannel(chatMessage)); } - + replyIcon.setVisible(!isMyMessage); replyIcon.setManaged(!isMyMessage); @@ -1038,8 +1032,8 @@ public ChatMessageListItem(T chatMessage, UserProfileService userProfileService, if (chatMessage instanceof PrivateTradeChatMessage) { senderUserProfile = Optional.of(((PrivateTradeChatMessage) chatMessage).getSender()); - } else if (chatMessage instanceof PrivateDiscussionChatMessage) { - senderUserProfile = Optional.of(((PrivateDiscussionChatMessage) chatMessage).getSender()); + } else if (chatMessage instanceof PrivateTwoPartyChatMessage) { + senderUserProfile = Optional.of(((PrivateTwoPartyChatMessage) chatMessage).getSender()); } else { senderUserProfile = userProfileService.findUserProfile(chatMessage.getAuthorId()); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index 8b2cca93e1..c393e7cc62 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -18,12 +18,12 @@ package bisq.desktop.primary.main.content.discussion; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.priv.PrivateDiscussionChannel; import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; @@ -37,12 +37,12 @@ @Slf4j public class DiscussionsController extends ChatController implements Controller { - private final PublicDiscussionChannelService publicDiscussionChannelService; private final DiscussionChannelSelectionService discussionChannelSelectionService; + private final PublicDiscussionChannelService publicDiscussionChannelService; private PublicDiscussionChannelSelection publicDiscussionChannelSelection; public DiscussionsController(DefaultApplicationService applicationService) { - super(applicationService, ChannelKind.DISCUSSION, NavigationTarget.NONE); + super(applicationService, ChatDomain.DISCUSSION, NavigationTarget.NONE); publicDiscussionChannelService = chatService.getPublicDiscussionChannelService(); discussionChannelSelectionService = chatService.getDiscussionChannelSelectionService(); @@ -69,8 +69,8 @@ public void createComponents() { } @Override - public DiscussionsModel getChatModel(ChannelKind channelKind) { - return new DiscussionsModel(channelKind); + public DiscussionsModel getChatModel(ChatDomain chatDomain) { + return new DiscussionsModel(chatDomain); } @Override @@ -87,7 +87,7 @@ public DiscussionsView getChatView() { protected void handleChannelChange(Channel channel) { super.handleChannelChange(channel); - if (channel instanceof PrivateDiscussionChannel) { + if (channel instanceof PrivateTwoPartyChannel) { applyPeersIcon((PrivateChannel) channel); publicDiscussionChannelSelection.deSelectChannel(); } else { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsModel.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsModel.java index 39b026ef07..75b9feb102 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsModel.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsModel.java @@ -17,7 +17,7 @@ package bisq.desktop.primary.main.content.discussion; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatModel; import lombok.Getter; @@ -26,10 +26,10 @@ @Slf4j @Getter public class DiscussionsModel extends ChatModel { - private final ChannelKind channelKind; + private final ChatDomain chatDomain; - public DiscussionsModel(ChannelKind channelKind) { - this.channelKind = channelKind; + public DiscussionsModel(ChatDomain chatDomain) { + this.chatDomain = chatDomain; } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index f8764efe2d..d303049d6d 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -18,12 +18,12 @@ package bisq.desktop.primary.main.content.events; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.priv.PrivateEventsChannel; import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; @@ -42,7 +42,7 @@ public class EventsController extends ChatController im private PublicEventsChannelSelection publicEventsChannelSelection; public EventsController(DefaultApplicationService applicationService) { - super(applicationService, ChannelKind.EVENTS, NavigationTarget.NONE); + super(applicationService, ChatDomain.EVENTS, NavigationTarget.NONE); publicEventsChannelService = chatService.getPublicEventsChannelService(); eventsChannelSelectionService = chatService.getEventsChannelSelectionService(); @@ -69,8 +69,8 @@ public void createComponents() { } @Override - public EventsModel getChatModel(ChannelKind channelKind) { - return new EventsModel(channelKind); + public EventsModel getChatModel(ChatDomain chatDomain) { + return new EventsModel(chatDomain); } @Override @@ -87,7 +87,7 @@ public EventsView getChatView() { protected void handleChannelChange(Channel channel) { super.handleChannelChange(channel); - if (channel instanceof PrivateEventsChannel) { + if (channel instanceof PrivateTwoPartyChannel) { applyPeersIcon((PrivateChannel) channel); publicEventsChannelSelection.deSelectChannel(); } else { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java index 4d8ddea656..e1704f3c65 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java @@ -17,7 +17,7 @@ package bisq.desktop.primary.main.content.events; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatModel; import lombok.Getter; @@ -26,10 +26,10 @@ @Slf4j @Getter public class EventsModel extends ChatModel { - private final ChannelKind channelKind; + private final ChatDomain chatDomain; - public EventsModel(ChannelKind channelKind) { - this.channelKind = channelKind; + public EventsModel(ChatDomain chatDomain) { + this.chatDomain = chatDomain; } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index d03f45a96f..e142900118 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -18,13 +18,13 @@ package bisq.desktop.primary.main.content.support; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.message.ChatMessage; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.priv.PrivateSupportChannel; import bisq.chat.support.pub.PublicSupportChannelService; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; @@ -42,7 +42,7 @@ public class SupportController extends ChatController private PublicSupportChannelSelection publicSupportChannelSelection; public SupportController(DefaultApplicationService applicationService) { - super(applicationService, ChannelKind.SUPPORT, NavigationTarget.NONE); + super(applicationService, ChatDomain.SUPPORT, NavigationTarget.NONE); publicSupportChannelService = chatService.getPublicSupportChannelService(); supportChannelSelectionService = chatService.getSupportChannelSelectionService(); @@ -69,8 +69,8 @@ public void createComponents() { } @Override - public SupportModel getChatModel(ChannelKind channelKind) { - return new SupportModel(channelKind); + public SupportModel getChatModel(ChatDomain chatDomain) { + return new SupportModel(chatDomain); } @Override @@ -87,7 +87,7 @@ public SupportView getChatView() { protected void handleChannelChange(Channel channel) { super.handleChannelChange(channel); - if (channel instanceof PrivateSupportChannel) { + if (channel instanceof PrivateTwoPartyChannel) { applyPeersIcon((PrivateChannel) channel); publicSupportChannelSelection.deSelectChannel(); } else { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java index 321b1e56a8..2215f3ff16 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java @@ -17,7 +17,7 @@ package bisq.desktop.primary.main.content.support; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatModel; import lombok.Getter; @@ -26,10 +26,10 @@ @Slf4j @Getter public class SupportModel extends ChatModel { - private final ChannelKind channelKind; + private final ChatDomain chatDomain; - public SupportModel(ChannelKind channelKind) { - this.channelKind = channelKind; + public SupportModel(ChatDomain chatDomain) { + this.chatDomain = chatDomain; } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java index a829dcb6dc..82dfb307ff 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java @@ -18,7 +18,7 @@ package bisq.desktop.primary.main.content.trade.bisqEasy.chat; import bisq.application.DefaultApplicationService; -import bisq.chat.ChannelKind; +import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; import bisq.chat.message.ChatMessage; import bisq.chat.trade.TradeChannelSelectionService; @@ -58,7 +58,7 @@ public class BisqEasyChatController extends ChatController Date: Fri, 23 Dec 2022 13:17:38 -0500 Subject: [PATCH 04/15] Refactor PublicDiscussion* classes to generic PublicModerated* classes --- chat/src/main/java/bisq/chat/ChatService.java | 18 ++++-- .../main/java/bisq/chat/channel/Channel.java | 4 +- .../bisq/chat/channel/ChannelService.java | 7 ++- .../chat/channel/PrivateChannelService.java | 4 +- .../chat/channel/PublicChannelService.java | 20 +++--- .../pub/PublicModeratedChannel.java} | 57 +++++++++-------- .../pub/PublicModeratedChannelService.java} | 61 ++++++++++--------- .../pub/PublicModeratedChannelStore.java} | 28 ++++----- .../pub/PublicModeratedChatMessage.java} | 40 ++++++------ .../DiscussionChannelSelectionService.java | 6 +- .../pub/PublicEventsChannelService.java | 17 +++--- .../java/bisq/chat/message/ChatMessage.java | 6 +- .../pub/PublicSupportChannelService.java | 17 +++--- .../trade/pub/PublicTradeChannelService.java | 17 +++--- .../main/content/chat/ChatController.java | 4 +- .../chat/channels/ChannelSelection.java | 4 +- .../PublicDiscussionChannelSelection.java | 12 ++-- .../content/chat/sidebar/ChannelSidebar.java | 10 +-- .../components/ChatMessagesComponent.java | 10 +-- .../components/ChatMessagesListView.java | 22 +++---- .../discussion/DiscussionsController.java | 4 +- 21 files changed, 193 insertions(+), 175 deletions(-) rename chat/src/main/java/bisq/chat/{discuss/pub/PublicDiscussionChannel.java => channel/pub/PublicModeratedChannel.java} (65%) rename chat/src/main/java/bisq/chat/{discuss/pub/PublicDiscussionChannelService.java => channel/pub/PublicModeratedChannelService.java} (54%) rename chat/src/main/java/bisq/chat/{discuss/pub/PublicDiscussionChannelStore.java => channel/pub/PublicModeratedChannelStore.java} (63%) rename chat/src/main/java/bisq/chat/{discuss/pub/PublicDiscussionChatMessage.java => channel/pub/PublicModeratedChatMessage.java} (70%) diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 97ea586d75..f265b5e24a 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -18,8 +18,9 @@ package bisq.chat; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; +import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.support.SupportChannelSelectionService; @@ -37,6 +38,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import java.util.List; import java.util.concurrent.CompletableFuture; @Slf4j @@ -45,7 +47,7 @@ public class ChatService implements Service { private final PrivateTradeChannelService privateTradeChannelService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; - private final PublicDiscussionChannelService publicDiscussionChannelService; + private final PublicModeratedChannelService publicDiscussionChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; private final PrivateTwoPartyChannelService privateSupportChannelService; @@ -78,9 +80,17 @@ public ChatService(PersistenceService persistenceService, userIdentityService, proofOfWorkService, ChatDomain.DISCUSSION); - publicDiscussionChannelService = new PublicDiscussionChannelService(persistenceService, + publicDiscussionChannelService = new PublicModeratedChannelService(persistenceService, networkService, - userIdentityService); + userIdentityService, + ChatDomain.DISCUSSION, + List.of(new PublicModeratedChannel("bisq", ChatDomain.DISCUSSION), + new PublicModeratedChannel("bitcoin", ChatDomain.DISCUSSION), + /* new PublicModeratedChannel("monero", ChatDomain.DISCUSSION),*/ + new PublicModeratedChannel("markets", ChatDomain.DISCUSSION), + new PublicModeratedChannel("economy", ChatDomain.DISCUSSION), + new PublicModeratedChannel("offTopic", ChatDomain.DISCUSSION))); + discussionChannelSelectionService = new DiscussionChannelSelectionService(persistenceService, privateDiscussionChannelService, publicDiscussionChannelService); diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index 540d7ae499..47d0acc04a 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -19,7 +19,7 @@ import bisq.chat.ChatDomain; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.discuss.pub.PublicDiscussionChannel; +import bisq.chat.channel.pub.PublicModeratedChannel; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; @@ -77,7 +77,7 @@ public static Channel fromProto(bisq.chat.protobuf.Channe case PUBLICDISCUSSIONCHANNEL: { - return PublicDiscussionChannel.fromProto(proto, proto.getPublicDiscussionChannel()); + return PublicModeratedChannel.fromProto(proto, proto.getPublicDiscussionChannel()); } case PUBLICEVENTSCHANNEL: { diff --git a/chat/src/main/java/bisq/chat/channel/ChannelService.java b/chat/src/main/java/bisq/chat/channel/ChannelService.java index a60e27efd3..37a42bc8e7 100644 --- a/chat/src/main/java/bisq/chat/channel/ChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.channel; +import bisq.chat.ChatDomain; import bisq.chat.message.ChatMessage; import bisq.common.application.Service; import bisq.common.observable.ObservableArray; @@ -33,12 +34,12 @@ public abstract class ChannelService implements Service, PersistenceClient { protected final NetworkService networkService; protected final UserIdentityService userIdentityService; + protected final ChatDomain chatDomain; - public ChannelService(NetworkService networkService, - UserIdentityService userIdentityService) { - + public ChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChatDomain chatDomain) { this.networkService = networkService; this.userIdentityService = userIdentityService; + this.chatDomain = chatDomain; } public void setNotificationSetting(Channel channel, ChannelNotificationType channelNotificationType) { diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index 9a75c09876..335373babd 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -44,15 +44,13 @@ public abstract class PrivateChannelService, S extends PersistableStore> extends ChannelService implements MessageListener { protected final ProofOfWorkService proofOfWorkService; - protected final ChatDomain chatDomain; public PrivateChannelService(NetworkService networkService, UserIdentityService userIdentityService, ProofOfWorkService proofOfWorkService, ChatDomain chatDomain) { - super(networkService, userIdentityService); + super(networkService, userIdentityService, chatDomain); this.proofOfWorkService = proofOfWorkService; - this.chatDomain = chatDomain; } diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java index 121910b040..696c2ddb48 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.channel; +import bisq.chat.ChatDomain; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.network.NetworkIdWithKeyPair; @@ -36,9 +37,8 @@ public abstract class PublicChannelService, S extends PersistableStore> extends ChannelService implements DataService.Listener { - public PublicChannelService(NetworkService networkService, - UserIdentityService userIdentityService) { - super(networkService, userIdentityService); + public PublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChatDomain chatDomain) { + super(networkService, userIdentityService, chatDomain); } @@ -72,7 +72,7 @@ public CompletableFuture publishChatMessage(Str Optional quotedMessage, C publicChannel, UserIdentity userIdentity) { - M chatMessage = createNewChatMessage(text, quotedMessage, publicChannel, userIdentity.getUserProfile()); + M chatMessage = createChatMessage(text, quotedMessage, publicChannel, userIdentity.getUserProfile()); return publishChatMessage(chatMessage, userIdentity); } @@ -87,7 +87,7 @@ public CompletableFuture publishEditedChatMessa NetworkIdWithKeyPair nodeIdAndKeyPair = userIdentity.getNodeIdAndKeyPair(); return networkService.removeAuthenticatedData(originalChatMessage, nodeIdAndKeyPair) .thenCompose(result -> { - M chatMessage = createNewChatMessage(originalChatMessage, editedText, userIdentity.getUserProfile()); + M chatMessage = createEditedChatMessage(originalChatMessage, editedText, userIdentity.getUserProfile()); return publishChatMessage(chatMessage, userIdentity); }); } @@ -124,12 +124,12 @@ protected void removeMessage(M message, C channel) { persist(); } - protected abstract M createNewChatMessage(String text, - Optional quotedMessage, - C publicChannel, - UserProfile userProfile); + protected abstract M createChatMessage(String text, + Optional quotedMessage, + C publicChannel, + UserProfile userProfile); - protected abstract M createNewChatMessage(M originalChatMessage, String editedText, UserProfile userProfile); + protected abstract M createEditedChatMessage(M originalChatMessage, String editedText, UserProfile userProfile); protected CompletableFuture publishChatMessage(UserIdentity userIdentity, UserProfile userProfile, diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java similarity index 65% rename from chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java rename to chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java index a86a045a9e..ad91176840 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannel.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.discuss.pub; +package bisq.chat.channel.pub; import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; @@ -33,41 +33,45 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PublicDiscussionChannel extends PublicChannel { +public final class PublicModeratedChannel extends PublicChannel { private final String channelName; private final String description; private final String channelAdminId; private final List channelModeratorIds; - public PublicDiscussionChannel(String id) { + public PublicModeratedChannel(String id, ChatDomain chatDomain) { this(id, - Res.get("discussion." + id + ".name"), - Res.get("discussion." + id + ".description"), + Res.get(chatDomain.name().toLowerCase() + "." + id + ".name"), + Res.get(chatDomain.name().toLowerCase() + "." + id + ".description"), "", new ArrayList<>(), - ChannelNotificationType.MENTION); + ChannelNotificationType.MENTION, + chatDomain); } - public PublicDiscussionChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds) { + public PublicModeratedChannel(String id, + String channelName, + String description, + String channelAdminId, + List channelModeratorIds, + ChatDomain chatDomain) { this(id, channelName, description, channelAdminId, channelModeratorIds, - ChannelNotificationType.MENTION); + ChannelNotificationType.MENTION, + chatDomain); } - private PublicDiscussionChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds, - ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType, ChatDomain.DISCUSSION); + private PublicModeratedChannel(String id, + String channelName, + String description, + String channelAdminId, + List channelModeratorIds, + ChannelNotificationType channelNotificationType, + ChatDomain chatDomain) { + super(id, channelNotificationType, chatDomain); this.channelName = channelName; this.description = description; @@ -87,29 +91,30 @@ public bisq.chat.protobuf.Channel toProto() { .build(); } - public static PublicDiscussionChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PublicDiscussionChannel proto) { - return new PublicDiscussionChannel( + public static PublicModeratedChannel fromProto(bisq.chat.protobuf.Channel baseProto, + bisq.chat.protobuf.PublicDiscussionChannel proto) { + return new PublicModeratedChannel( baseProto.getId(), proto.getChannelName(), proto.getDescription(), proto.getChannelAdminId(), new ArrayList<>(proto.getChannelModeratorIdsList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); + ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()), + ChatDomain.fromProto(baseProto.getChatDomain())); } @Override - public void addChatMessage(PublicDiscussionChatMessage chatMessage) { + public void addChatMessage(PublicModeratedChatMessage chatMessage) { chatMessages.add(chatMessage); } @Override - public void removeChatMessage(PublicDiscussionChatMessage chatMessage) { + public void removeChatMessage(PublicModeratedChatMessage chatMessage) { chatMessages.remove(chatMessage); } @Override - public void removeChatMessages(Collection removeMessages) { + public void removeChatMessages(Collection removeMessages) { chatMessages.removeAll(removeMessages); } diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannelService.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelService.java similarity index 54% rename from chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannelService.java rename to chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelService.java index 1a94f45844..1a438a88e5 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelService.java @@ -15,8 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.chat.discuss.pub; +package bisq.chat.channel.pub; +import bisq.chat.ChatDomain; import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; @@ -31,19 +32,25 @@ import lombok.extern.slf4j.Slf4j; import java.util.Date; +import java.util.List; import java.util.Optional; @Slf4j -public class PublicDiscussionChannelService extends PublicChannelService { +public class PublicModeratedChannelService extends PublicChannelService { @Getter - private final PublicDiscussionChannelStore persistableStore = new PublicDiscussionChannelStore(); + private final PublicModeratedChannelStore persistableStore = new PublicModeratedChannelStore(); @Getter - private final Persistence persistence; + private final Persistence persistence; + private final List defaultChannels; - public PublicDiscussionChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService) { - super(networkService, userIdentityService); + public PublicModeratedChannelService(PersistenceService persistenceService, + NetworkService networkService, + UserIdentityService userIdentityService, + ChatDomain chatDomain, + List defaultChannels) { + super(networkService, userIdentityService, chatDomain); + + this.defaultChannels = defaultChannels; persistence = persistenceService.getOrCreatePersistence(this, persistableStore); } @@ -56,16 +63,16 @@ public PublicDiscussionChannelService(PersistenceService persistenceService, @Override public void onAuthenticatedDataAdded(AuthenticatedData authenticatedData) { DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicDiscussionChatMessage) { - processAddedMessage((PublicDiscussionChatMessage) distributedData); + if (distributedData instanceof PublicModeratedChatMessage) { + processAddedMessage((PublicModeratedChatMessage) distributedData); } } @Override public void onAuthenticatedDataRemoved(AuthenticatedData authenticatedData) { DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicDiscussionChatMessage) { - processRemovedMessage((PublicDiscussionChatMessage) distributedData); + if (distributedData instanceof PublicModeratedChatMessage) { + processRemovedMessage((PublicModeratedChatMessage) distributedData); } } @@ -75,16 +82,16 @@ public void onAuthenticatedDataRemoved(AuthenticatedData authenticatedData) { /////////////////////////////////////////////////////////////////////////////////////////////////// @Override - public ObservableArray getChannels() { + public ObservableArray getChannels() { return persistableStore.getChannels(); } @Override - protected PublicDiscussionChatMessage createNewChatMessage(String text, - Optional quotedMessage, - PublicDiscussionChannel publicChannel, - UserProfile userProfile) { - return new PublicDiscussionChatMessage(publicChannel.getId(), + protected PublicModeratedChatMessage createChatMessage(String text, + Optional quotedMessage, + PublicModeratedChannel publicChannel, + UserProfile userProfile) { + return new PublicModeratedChatMessage(publicChannel.getId(), userProfile.getId(), text, quotedMessage, @@ -93,10 +100,10 @@ protected PublicDiscussionChatMessage createNewChatMessage(String text, } @Override - protected PublicDiscussionChatMessage createNewChatMessage(PublicDiscussionChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { - return new PublicDiscussionChatMessage(originalChatMessage.getChannelId(), + protected PublicModeratedChatMessage createEditedChatMessage(PublicModeratedChatMessage originalChatMessage, + String editedText, + UserProfile userProfile) { + return new PublicModeratedChatMessage(originalChatMessage.getChannelId(), userProfile.getId(), editedText, originalChatMessage.getQuotation(), @@ -109,14 +116,8 @@ protected void maybeAddDefaultChannels() { if (!getChannels().isEmpty()) { return; } - PublicDiscussionChannel defaultDiscussionChannel = new PublicDiscussionChannel("bisq"); - ObservableArray channels = getChannels(); - channels.add(defaultDiscussionChannel); - channels.add(new PublicDiscussionChannel("bitcoin")); - // channels.add(new PublicDiscussionChannel("monero")); - channels.add(new PublicDiscussionChannel("markets")); - channels.add(new PublicDiscussionChannel("economy")); - channels.add(new PublicDiscussionChannel("offTopic")); + + getChannels().addAll(defaultChannels); persist(); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannelStore.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java similarity index 63% rename from chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannelStore.java rename to chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java index 7d19668152..2f34697d02 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.discuss.pub; +package bisq.chat.channel.pub; import bisq.common.observable.ObservableArray; import bisq.common.proto.ProtoResolver; @@ -28,28 +28,28 @@ import java.util.stream.Collectors; @Getter -public class PublicDiscussionChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); +public class PublicModeratedChannelStore implements PersistableStore { + private final ObservableArray channels = new ObservableArray<>(); - public PublicDiscussionChannelStore() { + public PublicModeratedChannelStore() { } - private PublicDiscussionChannelStore(List privateDiscussionChannels) { + private PublicModeratedChannelStore(List privateDiscussionChannels) { setAll(privateDiscussionChannels); } @Override public bisq.chat.protobuf.PublicDiscussionChannelStore toProto() { bisq.chat.protobuf.PublicDiscussionChannelStore.Builder builder = bisq.chat.protobuf.PublicDiscussionChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PublicDiscussionChannel::toProto).collect(Collectors.toList())); + .addAllChannels(channels.stream().map(PublicModeratedChannel::toProto).collect(Collectors.toList())); return builder.build(); } - public static PublicDiscussionChannelStore fromProto(bisq.chat.protobuf.PublicDiscussionChannelStore proto) { - List privateDiscussionChannels = proto.getChannelsList().stream() - .map(e -> (PublicDiscussionChannel) PublicDiscussionChannel.fromProto(e)) + public static PublicModeratedChannelStore fromProto(bisq.chat.protobuf.PublicDiscussionChannelStore proto) { + List privateDiscussionChannels = proto.getChannelsList().stream() + .map(e -> (PublicModeratedChannel) PublicModeratedChannel.fromProto(e)) .collect(Collectors.toList()); - return new PublicDiscussionChannelStore(privateDiscussionChannels); + return new PublicModeratedChannelStore(privateDiscussionChannels); } @Override @@ -64,16 +64,16 @@ public ProtoResolver> getResolver() { } @Override - public void applyPersisted(PublicDiscussionChannelStore chatStore) { + public void applyPersisted(PublicModeratedChannelStore chatStore) { setAll(chatStore.getChannels()); } @Override - public PublicDiscussionChannelStore getClone() { - return new PublicDiscussionChannelStore(channels); + public PublicModeratedChannelStore getClone() { + return new PublicModeratedChannelStore(channels); } - public void setAll(List privateDiscussionChannels) { + public void setAll(List privateDiscussionChannels) { this.channels.clear(); this.channels.addAll(privateDiscussionChannels); } diff --git a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java similarity index 70% rename from chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java rename to chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java index 1a9e44c290..45aeb1985c 100644 --- a/chat/src/main/java/bisq/chat/discuss/pub/PublicDiscussionChatMessage.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.discuss.pub; +package bisq.chat.channel.pub; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; @@ -32,13 +32,13 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public final class PublicDiscussionChatMessage extends PublicChatMessage { - public PublicDiscussionChatMessage(String channelId, - String authorId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited) { +public final class PublicModeratedChatMessage extends PublicChatMessage { + public PublicModeratedChatMessage(String channelId, + String authorId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited) { this(StringUtils.createShortUid(), channelId, authorId, @@ -47,18 +47,18 @@ public PublicDiscussionChatMessage(String channelId, date, wasEdited, MessageType.TEXT, - new MetaData(ChatMessage.TTL, 100000, PublicDiscussionChatMessage.class.getSimpleName())); + new MetaData(ChatMessage.TTL, 100000, PublicModeratedChatMessage.class.getSimpleName())); } - private PublicDiscussionChatMessage(String messageId, - String channelId, - String authorId, - Optional text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { + private PublicModeratedChatMessage(String messageId, + String channelId, + String authorId, + Optional text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType, + MetaData metaData) { super(messageId, channelId, authorId, @@ -74,11 +74,11 @@ public bisq.chat.protobuf.ChatMessage toProto() { return getChatMessageBuilder().setPublicDiscussionChatMessage(bisq.chat.protobuf.PublicDiscussionChatMessage.newBuilder()).build(); } - public static PublicDiscussionChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { + public static PublicModeratedChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { Optional quotedMessage = baseProto.hasQuotation() ? Optional.of(Quotation.fromProto(baseProto.getQuotation())) : Optional.empty(); - return new PublicDiscussionChatMessage( + return new PublicModeratedChatMessage( baseProto.getMessageId(), baseProto.getChannelId(), baseProto.getAuthorId(), diff --git a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java index 4b337b3e6c..4ab4ff9f0a 100644 --- a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java @@ -20,7 +20,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.discuss.pub.PublicDiscussionChannelService; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; @@ -38,11 +38,11 @@ public class DiscussionChannelSelectionService implements PersistenceClient persistence; private final PrivateTwoPartyChannelService privateChannelService; - private final PublicDiscussionChannelService publicChannelService; + private final PublicModeratedChannelService publicChannelService; public DiscussionChannelSelectionService(PersistenceService persistenceService, PrivateTwoPartyChannelService privateChannelService, - PublicDiscussionChannelService publicChannelService) { + PublicModeratedChannelService publicChannelService) { persistence = persistenceService.getOrCreatePersistence(this, persistableStore); this.privateChannelService = privateChannelService; this.publicChannelService = publicChannelService; diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java index 2a5024ace8..4bcfb6e45d 100644 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java +++ b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.events.pub; +import bisq.chat.ChatDomain; import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; @@ -43,7 +44,7 @@ public class PublicEventsChannelService extends PublicChannelService getChannels() { } @Override - protected PublicEventsChatMessage createNewChatMessage(String text, - Optional quotedMessage, - PublicEventsChannel publicChannel, - UserProfile userProfile) { + protected PublicEventsChatMessage createChatMessage(String text, + Optional quotedMessage, + PublicEventsChannel publicChannel, + UserProfile userProfile) { return new PublicEventsChatMessage(publicChannel.getId(), userProfile.getId(), text, @@ -93,9 +94,9 @@ protected PublicEventsChatMessage createNewChatMessage(String text, } @Override - protected PublicEventsChatMessage createNewChatMessage(PublicEventsChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { + protected PublicEventsChatMessage createEditedChatMessage(PublicEventsChatMessage originalChatMessage, + String editedText, + UserProfile userProfile) { return new PublicEventsChatMessage(originalChatMessage.getChannelId(), userProfile.getId(), editedText, diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 927bf2ef0f..3bfadaec40 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -18,7 +18,7 @@ package bisq.chat.message; import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; -import bisq.chat.discuss.pub.PublicDiscussionChatMessage; +import bisq.chat.channel.pub.PublicModeratedChatMessage; import bisq.chat.events.pub.PublicEventsChatMessage; import bisq.chat.support.pub.PublicSupportChatMessage; import bisq.chat.trade.priv.PrivateTradeChatMessage; @@ -108,7 +108,7 @@ public static ChatMessage fromProto(bisq.chat.protobuf.ChatMessage proto) { } case PUBLICDISCUSSIONCHATMESSAGE: { - return PublicDiscussionChatMessage.fromProto(proto); + return PublicModeratedChatMessage.fromProto(proto); } @@ -136,7 +136,7 @@ public static ProtoResolver getDistributedDataResolver() { return PublicTradeChatMessage.fromProto(proto); } case PUBLICDISCUSSIONCHATMESSAGE: { - return PublicDiscussionChatMessage.fromProto(proto); + return PublicModeratedChatMessage.fromProto(proto); } case PUBLICEVENTSCHATMESSAGE: { return PublicEventsChatMessage.fromProto(proto); diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java index 9719a25eaf..20469d68b1 100644 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java +++ b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.support.pub; +import bisq.chat.ChatDomain; import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; @@ -43,7 +44,7 @@ public class PublicSupportChannelService extends PublicChannelService getChannels() { } @Override - protected PublicSupportChatMessage createNewChatMessage(String text, - Optional quotedMessage, - PublicSupportChannel publicChannel, - UserProfile userProfile) { + protected PublicSupportChatMessage createChatMessage(String text, + Optional quotedMessage, + PublicSupportChannel publicChannel, + UserProfile userProfile) { return new PublicSupportChatMessage(publicChannel.getId(), userProfile.getId(), text, @@ -93,9 +94,9 @@ protected PublicSupportChatMessage createNewChatMessage(String text, } @Override - protected PublicSupportChatMessage createNewChatMessage(PublicSupportChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { + protected PublicSupportChatMessage createEditedChatMessage(PublicSupportChatMessage originalChatMessage, + String editedText, + UserProfile userProfile) { return new PublicSupportChatMessage(originalChatMessage.getChannelId(), userProfile.getId(), editedText, diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java index 761c013b76..f035b80b90 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java @@ -17,6 +17,7 @@ package bisq.chat.trade.pub; +import bisq.chat.ChatDomain; import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.currency.Market; @@ -52,7 +53,7 @@ public class PublicTradeChannelService extends PublicChannelService getChannels() { } @Override - protected PublicTradeChatMessage createNewChatMessage(String text, - Optional quotedMessage, - PublicTradeChannel publicChannel, - UserProfile userProfile) { + protected PublicTradeChatMessage createChatMessage(String text, + Optional quotedMessage, + PublicTradeChannel publicChannel, + UserProfile userProfile) { return new PublicTradeChatMessage(publicChannel.getId(), userProfile.getId(), Optional.empty(), @@ -127,9 +128,9 @@ protected PublicTradeChatMessage createNewChatMessage(String text, } @Override - protected PublicTradeChatMessage createNewChatMessage(PublicTradeChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { + protected PublicTradeChatMessage createEditedChatMessage(PublicTradeChatMessage originalChatMessage, + String editedText, + UserProfile userProfile) { return new PublicTradeChatMessage(originalChatMessage.getChannelId(), userProfile.getId(), Optional.empty(), diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java index 9ce3abe63b..f959dc1337 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java @@ -23,7 +23,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; -import bisq.chat.discuss.pub.PublicDiscussionChannel; +import bisq.chat.channel.pub.PublicModeratedChannel; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; import bisq.chat.support.pub.PublicSupportChannel; @@ -213,7 +213,7 @@ protected void applyDefaultPublicChannelIcon(PublicChannel channel) { String type = null; if (channel instanceof PublicEventsChannel) { type = "-events-"; - } else if (channel instanceof PublicDiscussionChannel) { + } else if (channel instanceof PublicModeratedChannel) { type = "-discussion-"; } else if (channel instanceof PublicSupportChannel) { type = "-support-"; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java index 3ae278e319..2f59ad7f34 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java @@ -3,7 +3,7 @@ import bisq.chat.ChatService; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; -import bisq.chat.discuss.pub.PublicDiscussionChannel; +import bisq.chat.channel.pub.PublicModeratedChannel; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.trade.priv.PrivateTradeChannel; @@ -250,7 +250,7 @@ public ChannelItem(Channel channel, @Nullable UserIdentityService userIdentit String type = null; if (channel instanceof PublicEventsChannel) { type = "-events-"; - } else if (channel instanceof PublicDiscussionChannel) { + } else if (channel instanceof PublicModeratedChannel) { type = "-discussion-"; } else if (channel instanceof PublicSupportChannel) { type = "-support-"; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java index b873ffb043..d9ae7ad6ff 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java @@ -19,9 +19,9 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; +import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.pub.PublicDiscussionChannel; -import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; import bisq.i18n.Res; @@ -54,7 +54,7 @@ protected static class Controller extends ChannelSelection.Controller { private final Model model; @Getter private final View view; - private final PublicDiscussionChannelService publicDiscussionChannelService; + private final PublicModeratedChannelService publicDiscussionChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; @@ -80,13 +80,13 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(ChannelSelection.View.ChannelItem::new) .to(publicDiscussionChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(discussionChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PublicDiscussionChannel) { + if (channel instanceof PublicModeratedChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); } }); @@ -134,7 +134,7 @@ protected ListCell getListCell() { @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PublicDiscussionChannel) { + if (item != null && !empty && item.getChannel() instanceof PublicModeratedChannel) { widthSubscription = setupCellBinding(this, item, label, iconImageView); updateCell(this, item, label, iconImageView); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index 598516bdab..c9e13fc9a9 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -20,7 +20,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.discuss.pub.PublicDiscussionChannel; +import bisq.chat.channel.pub.PublicModeratedChannel; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; import bisq.chat.support.pub.PublicSupportChannel; @@ -118,11 +118,11 @@ void setChannel(Channel channel) { model.moderators.clear(); } case DISCUSSION -> { - PublicDiscussionChannel publicDiscussionChannel = (PublicDiscussionChannel) channel; - model.description.set(publicDiscussionChannel.getDescription()); + PublicModeratedChannel publicModeratedChannel = (PublicModeratedChannel) channel; + model.description.set(publicModeratedChannel.getDescription()); model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicDiscussionChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicDiscussionChannel.getChannelModeratorIds().stream() + model.adminProfile = userProfileService.findUserProfile(publicModeratedChannel.getChannelAdminId()).map(ChatUserOverview::new); + model.moderators.setAll(publicModeratedChannel.getChannelModeratorIds().stream() .flatMap(id -> userProfileService.findUserProfile(id).stream()) .map(ChatUserOverview::new) .sorted() diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 32c8939435..6ad81ad435 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -24,9 +24,9 @@ import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; +import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.pub.PublicDiscussionChannel; -import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.events.pub.PublicEventsChannelService; @@ -124,7 +124,7 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final UserProfileService userProfileService; private final PrivateTradeChannelService privateTradeChannelService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; - private final PublicDiscussionChannelService publicDiscussionChannelService; + private final PublicModeratedChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; @@ -256,8 +256,8 @@ private void doSendMessage(String text) { } else { new Popup().information(Res.get("social.chat.sendMsg.tradeRulesNotConfirmed.popup")).show(); } - } else if (channel instanceof PublicDiscussionChannel) { - publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicDiscussionChannel) channel, userIdentity); + } else if (channel instanceof PublicModeratedChannel) { + publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); } else if (channel instanceof PrivateTwoPartyChannel) { switch (channel.getChatDomain()) { case TRADE -> { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 4959d4dac8..44b18c6d5f 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -24,10 +24,10 @@ import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; +import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.pub.PublicModeratedChatMessage; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.pub.PublicDiscussionChannel; -import bisq.chat.discuss.pub.PublicDiscussionChannelService; -import bisq.chat.discuss.pub.PublicDiscussionChatMessage; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.events.pub.PublicEventsChannelService; @@ -164,7 +164,7 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final ChatService chatService; private final PrivateTradeChannelService privateTradeChannelService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; - private final PublicDiscussionChannelService publicDiscussionChannelService; + private final PublicModeratedChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final UserIdentityService userIdentityService; private final Consumer mentionUserHandler; @@ -263,13 +263,13 @@ public void onActivate() { } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { selectedChannelPin = discussionChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); - if (channel instanceof PublicDiscussionChannel) { + if (channel instanceof PublicModeratedChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PublicDiscussionChannel) channel).getChatMessages()); + .to(((PublicModeratedChannel) channel).getChatMessages()); model.allowEditing.set(true); } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { @@ -425,8 +425,8 @@ private void onDeleteMessage(ChatMessage chatMessage) { private void doDeleteMessage(ChatMessage chatMessage, UserIdentity messageAuthor) { if (chatMessage instanceof PublicTradeChatMessage) { publicTradeChannelService.deleteChatMessage((PublicTradeChatMessage) chatMessage, messageAuthor); - } else if (chatMessage instanceof PublicDiscussionChatMessage) { - publicDiscussionChannelService.deleteChatMessage((PublicDiscussionChatMessage) chatMessage, messageAuthor); + } else if (chatMessage instanceof PublicModeratedChatMessage) { + publicDiscussionChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor); } else if (chatMessage instanceof PublicEventsChatMessage) { publicEventsChannelService.deleteChatMessage((PublicEventsChatMessage) chatMessage, messageAuthor); } else if (chatMessage instanceof PublicSupportChatMessage) { @@ -448,9 +448,9 @@ private void onSaveEditedMessage(ChatMessage chatMessage, String editedText) { if (chatMessage instanceof PublicTradeChatMessage) { UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity().get(); publicTradeChannelService.publishEditedChatMessage((PublicTradeChatMessage) chatMessage, editedText, userIdentity); - } else if (chatMessage instanceof PublicDiscussionChatMessage) { + } else if (chatMessage instanceof PublicModeratedChatMessage) { UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity().get(); - publicDiscussionChannelService.publishEditedChatMessage((PublicDiscussionChatMessage) chatMessage, editedText, userIdentity); + publicDiscussionChannelService.publishEditedChatMessage((PublicModeratedChatMessage) chatMessage, editedText, userIdentity); } //todo editing private message not supported yet } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index c393e7cc62..c8b746f6a0 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -23,8 +23,8 @@ import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.discuss.pub.PublicDiscussionChannelService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; @@ -38,7 +38,7 @@ @Slf4j public class DiscussionsController extends ChatController implements Controller { private final DiscussionChannelSelectionService discussionChannelSelectionService; - private final PublicDiscussionChannelService publicDiscussionChannelService; + private final PublicModeratedChannelService publicDiscussionChannelService; private PublicDiscussionChannelSelection publicDiscussionChannelSelection; public DiscussionsController(DefaultApplicationService applicationService) { From 15eb6e34b7ebd60fbf3683cb47c6e18a33855178 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 14:16:17 -0500 Subject: [PATCH 05/15] Refactor events and support classes to generic PublicModerated* classes --- chat/src/main/java/bisq/chat/ChatService.java | 37 ++-- .../main/java/bisq/chat/channel/Channel.java | 24 +-- .../bisq/chat/channel/PrivateChannel.java | 10 +- .../java/bisq/chat/channel/PublicChannel.java | 4 +- .../PrivateTwoPartyChannel.java | 20 ++- .../channel/pub/PublicModeratedChannel.java | 52 +++--- .../pub/PublicModeratedChannelStore.java | 8 +- .../pub/PublicModeratedChatMessage.java | 2 +- .../events/EventsChannelSelectionService.java | 6 +- .../chat/events/pub/PublicEventsChannel.java | 120 ------------- .../pub/PublicEventsChannelService.java | 123 ------------- .../events/pub/PublicEventsChannelStore.java | 80 --------- .../events/pub/PublicEventsChatMessage.java | 92 ---------- .../java/bisq/chat/message/ChatMessage.java | 21 +-- .../SupportChannelSelectionService.java | 6 +- .../support/pub/PublicSupportChannel.java | 121 ------------- .../pub/PublicSupportChannelService.java | 121 ------------- .../pub/PublicSupportChannelStore.java | 80 --------- .../support/pub/PublicSupportChatMessage.java | 92 ---------- .../chat/trade/priv/PrivateTradeChannel.java | 6 +- .../priv/PrivateTradeChannelService.java | 4 +- .../chat/trade/pub/PublicTradeChannel.java | 12 +- chat/src/main/proto/chat.proto | 161 +++++++----------- .../main/content/chat/ChatController.java | 19 +-- .../chat/channels/ChannelSelection.java | 20 +-- .../PublicEventsChannelSelection.java | 12 +- .../PublicSupportChannelSelection.java | 12 +- .../channels/PublicTradeChannelSelection.java | 4 +- .../content/chat/sidebar/ChannelSidebar.java | 84 +-------- .../components/ChatMessagesComponent.java | 27 +-- .../components/ChatMessagesListView.java | 36 ++-- .../main/content/events/EventsController.java | 4 +- .../content/support/SupportController.java | 4 +- .../review/ReviewOfferController.java | 2 +- .../dto/PublicDiscussionChannelDto.java | 4 +- 35 files changed, 224 insertions(+), 1206 deletions(-) delete mode 100644 chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java delete mode 100644 chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java delete mode 100644 chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelStore.java delete mode 100644 chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java delete mode 100644 chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java delete mode 100644 chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java delete mode 100644 chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelStore.java delete mode 100644 chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index f265b5e24a..1a83906f13 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -22,9 +22,7 @@ import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.pub.PublicSupportChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannelService; import bisq.chat.trade.pub.PublicTradeChannelService; @@ -51,10 +49,10 @@ public class ChatService implements Service { private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; private final PrivateTwoPartyChannelService privateSupportChannelService; - private final PublicSupportChannelService publicSupportChannelService; + private final PublicModeratedChannelService publicSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; private final PrivateTwoPartyChannelService privateEventsChannelService; - private final PublicEventsChannelService publicEventsChannelService; + private final PublicModeratedChannelService publicEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; public ChatService(PersistenceService persistenceService, @@ -84,12 +82,12 @@ public ChatService(PersistenceService persistenceService, networkService, userIdentityService, ChatDomain.DISCUSSION, - List.of(new PublicModeratedChannel("bisq", ChatDomain.DISCUSSION), - new PublicModeratedChannel("bitcoin", ChatDomain.DISCUSSION), - /* new PublicModeratedChannel("monero", ChatDomain.DISCUSSION),*/ - new PublicModeratedChannel("markets", ChatDomain.DISCUSSION), - new PublicModeratedChannel("economy", ChatDomain.DISCUSSION), - new PublicModeratedChannel("offTopic", ChatDomain.DISCUSSION))); + List.of(new PublicModeratedChannel(ChatDomain.DISCUSSION, "bisq"), + new PublicModeratedChannel(ChatDomain.DISCUSSION, "bitcoin"), + /* new PublicModeratedChannel(ChatDomain.DISCUSSION,"monero"),*/ + new PublicModeratedChannel(ChatDomain.DISCUSSION, "markets"), + new PublicModeratedChannel(ChatDomain.DISCUSSION, "economy"), + new PublicModeratedChannel(ChatDomain.DISCUSSION, "offTopic"))); discussionChannelSelectionService = new DiscussionChannelSelectionService(persistenceService, privateDiscussionChannelService, @@ -101,9 +99,16 @@ public ChatService(PersistenceService persistenceService, userIdentityService, proofOfWorkService, ChatDomain.EVENTS); - publicEventsChannelService = new PublicEventsChannelService(persistenceService, + publicEventsChannelService = new PublicModeratedChannelService(persistenceService, networkService, - userIdentityService); + userIdentityService, + ChatDomain.EVENTS, + List.of(new PublicModeratedChannel(ChatDomain.EVENTS, "conferences"), + new PublicModeratedChannel(ChatDomain.EVENTS, "meetups"), + new PublicModeratedChannel(ChatDomain.EVENTS, "podcasts"), + new PublicModeratedChannel(ChatDomain.EVENTS, "noKyc"), + new PublicModeratedChannel(ChatDomain.EVENTS, "nodes"), + new PublicModeratedChannel(ChatDomain.EVENTS, "tradeEvents"))); eventsChannelSelectionService = new EventsChannelSelectionService(persistenceService, privateEventsChannelService, publicEventsChannelService); @@ -114,9 +119,13 @@ public ChatService(PersistenceService persistenceService, userIdentityService, proofOfWorkService, ChatDomain.SUPPORT); - publicSupportChannelService = new PublicSupportChannelService(persistenceService, + publicSupportChannelService = new PublicModeratedChannelService(persistenceService, networkService, - userIdentityService); + userIdentityService, + ChatDomain.SUPPORT, + List.of(new PublicModeratedChannel(ChatDomain.SUPPORT, "support"), + new PublicModeratedChannel(ChatDomain.SUPPORT, "questions"), + new PublicModeratedChannel(ChatDomain.SUPPORT, "reports"))); supportChannelSelectionService = new SupportChannelSelectionService(persistenceService, privateSupportChannelService, publicSupportChannelService); diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index 47d0acc04a..b0b4925c6b 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -20,10 +20,8 @@ import bisq.chat.ChatDomain; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; -import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.common.data.Pair; @@ -42,14 +40,16 @@ @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true) public abstract class Channel implements Proto { - @EqualsAndHashCode.Include - protected final String id; private final ChatDomain chatDomain; + protected final String channelName; + @EqualsAndHashCode.Include + private transient final String id; protected final Observable channelNotificationType = new Observable<>(); - public Channel(String id, ChannelNotificationType channelNotificationType, ChatDomain chatDomain) { - this.id = id; + public Channel(ChatDomain chatDomain, String channelName, ChannelNotificationType channelNotificationType) { this.chatDomain = chatDomain; + this.channelName = channelName; + this.id = chatDomain.name().toLowerCase() + "." + channelName; this.channelNotificationType.set(channelNotificationType); } @@ -76,16 +76,8 @@ public static Channel fromProto(bisq.chat.protobuf.Channe } - case PUBLICDISCUSSIONCHANNEL: { - return PublicModeratedChannel.fromProto(proto, proto.getPublicDiscussionChannel()); - } - - case PUBLICEVENTSCHANNEL: { - return PublicEventsChannel.fromProto(proto, proto.getPublicEventsChannel()); - } - - case PUBLICSUPPORTCHANNEL: { - return PublicSupportChannel.fromProto(proto, proto.getPublicSupportChannel()); + case PUBLICMODERATEDCHANNEL: { + return PublicModeratedChannel.fromProto(proto, proto.getPublicModeratedChannel()); } case MESSAGE_NOT_SET: { diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index ce31814468..b49399b4e4 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -36,7 +36,7 @@ @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) public abstract class PrivateChannel extends Channel { - public static String createChannelId(Pair userIds) { + public static String createChannelName(Pair userIds) { String userId1 = userIds.getFirst(); String userId2 = userIds.getSecond(); if (userId1.compareTo(userId2) < 0) { @@ -51,12 +51,12 @@ public static String createChannelId(Pair userIds) { // We persist the messages as they are NOT persisted in the P2P data store. protected final ObservableArray chatMessages = new ObservableArray<>(); - public PrivateChannel(String id, + public PrivateChannel(ChatDomain chatDomain, + String channelName, UserIdentity myUserIdentity, List chatMessages, - ChannelNotificationType channelNotificationType, - ChatDomain chatDomain) { - super(id, channelNotificationType, chatDomain); + ChannelNotificationType channelNotificationType) { + super(chatDomain, channelName, channelNotificationType); this.myUserIdentity = myUserIdentity; this.chatMessages.addAll(chatMessages); diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannel.java b/chat/src/main/java/bisq/chat/channel/PublicChannel.java index b43507baa5..c6cfc21d9e 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannel.java @@ -31,7 +31,7 @@ public abstract class PublicChannel extends Channel // We do not persist the messages as they are persisted in the P2P data store. protected transient final ObservableArray chatMessages = new ObservableArray<>(); - public PublicChannel(String id, ChannelNotificationType channelNotificationType, ChatDomain chatDomain) { - super(id, channelNotificationType, chatDomain); + public PublicChannel(ChatDomain chatDomain, String channelName, ChannelNotificationType channelNotificationType) { + super(chatDomain, channelName, channelNotificationType); } } diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java index f3658a3358..b02518b1eb 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java @@ -39,21 +39,22 @@ public final class PrivateTwoPartyChannel extends PrivateChannel(peer.getId(), myUserIdentity.getId())), + this(chatDomain, + PrivateChannel.createChannelName(new Pair<>(peer.getId(), myUserIdentity.getId())), peer, myUserIdentity, new ArrayList<>(), - ChannelNotificationType.ALL, - chatDomain); + ChannelNotificationType.ALL + ); } - private PrivateTwoPartyChannel(String id, + private PrivateTwoPartyChannel(ChatDomain chatDomain, + String channelName, UserProfile peer, UserIdentity myProfile, List chatMessages, - ChannelNotificationType channelNotificationType, - ChatDomain chatDomain) { - super(id, myProfile, chatMessages, channelNotificationType, chatDomain); + ChannelNotificationType channelNotificationType) { + super(chatDomain, channelName, myProfile, chatMessages, channelNotificationType); this.peer = peer; } @@ -72,14 +73,15 @@ public bisq.chat.protobuf.Channel toProto() { public static PrivateTwoPartyChannel fromProto(bisq.chat.protobuf.Channel baseProto, bisq.chat.protobuf.PrivateTwoPartyChannel proto) { return new PrivateTwoPartyChannel( + ChatDomain.fromProto(baseProto.getChatDomain()), baseProto.getId(), UserProfile.fromProto(proto.getPeer()), UserIdentity.fromProto(proto.getMyUserIdentity()), proto.getChatMessagesList().stream() .map(PrivateTwoPartyChatMessage::fromProto) .collect(Collectors.toList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()), - ChatDomain.fromProto(baseProto.getChatDomain())); + ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()) + ); } @Override diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java index ad91176840..e59274ebc4 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java @@ -34,46 +34,32 @@ @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) public final class PublicModeratedChannel extends PublicChannel { - private final String channelName; + private final String displayName; private final String description; private final String channelAdminId; private final List channelModeratorIds; - public PublicModeratedChannel(String id, ChatDomain chatDomain) { - this(id, - Res.get(chatDomain.name().toLowerCase() + "." + id + ".name"), - Res.get(chatDomain.name().toLowerCase() + "." + id + ".description"), + public PublicModeratedChannel(ChatDomain chatDomain, String channelName) { + this(chatDomain, + channelName, + Res.get(chatDomain.name().toLowerCase() + "." + channelName + ".name"), + Res.get(chatDomain.name().toLowerCase() + "." + channelName + ".description"), "", new ArrayList<>(), - ChannelNotificationType.MENTION, - chatDomain); - } - - public PublicModeratedChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds, - ChatDomain chatDomain) { - this(id, - channelName, - description, - channelAdminId, - channelModeratorIds, - ChannelNotificationType.MENTION, - chatDomain); + ChannelNotificationType.MENTION); } - private PublicModeratedChannel(String id, + private PublicModeratedChannel(ChatDomain chatDomain, String channelName, + String displayName, String description, String channelAdminId, List channelModeratorIds, - ChannelNotificationType channelNotificationType, - ChatDomain chatDomain) { - super(id, channelNotificationType, chatDomain); + ChannelNotificationType channelNotificationType + ) { + super(chatDomain, channelName, channelNotificationType); - this.channelName = channelName; + this.displayName = displayName; this.description = description; this.channelAdminId = channelAdminId; this.channelModeratorIds = channelModeratorIds; @@ -83,8 +69,8 @@ private PublicModeratedChannel(String id, public bisq.chat.protobuf.Channel toProto() { return getChannelBuilder() - .setPublicDiscussionChannel(bisq.chat.protobuf.PublicDiscussionChannel.newBuilder() - .setChannelName(channelName) + .setPublicModeratedChannel(bisq.chat.protobuf.PublicModeratedChannel.newBuilder() + .setChannelName(displayName) .setDescription(description) .setChannelAdminId(channelAdminId) .addAllChannelModeratorIds(channelModeratorIds)) @@ -92,15 +78,15 @@ public bisq.chat.protobuf.Channel toProto() { } public static PublicModeratedChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PublicDiscussionChannel proto) { + bisq.chat.protobuf.PublicModeratedChannel proto) { return new PublicModeratedChannel( + ChatDomain.fromProto(baseProto.getChatDomain()), baseProto.getId(), proto.getChannelName(), proto.getDescription(), proto.getChannelAdminId(), new ArrayList<>(proto.getChannelModeratorIdsList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()), - ChatDomain.fromProto(baseProto.getChatDomain())); + ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); } @Override @@ -120,6 +106,6 @@ public void removeChatMessages(Collection removeMess @Override public String getDisplayString() { - return channelName; + return displayName; } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java index 2f34697d02..3f79248143 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java @@ -39,13 +39,13 @@ private PublicModeratedChannelStore(List privateDiscussi } @Override - public bisq.chat.protobuf.PublicDiscussionChannelStore toProto() { - bisq.chat.protobuf.PublicDiscussionChannelStore.Builder builder = bisq.chat.protobuf.PublicDiscussionChannelStore.newBuilder() + public bisq.chat.protobuf.PublicModeratedChannelStore toProto() { + bisq.chat.protobuf.PublicModeratedChannelStore.Builder builder = bisq.chat.protobuf.PublicModeratedChannelStore.newBuilder() .addAllChannels(channels.stream().map(PublicModeratedChannel::toProto).collect(Collectors.toList())); return builder.build(); } - public static PublicModeratedChannelStore fromProto(bisq.chat.protobuf.PublicDiscussionChannelStore proto) { + public static PublicModeratedChannelStore fromProto(bisq.chat.protobuf.PublicModeratedChannelStore proto) { List privateDiscussionChannels = proto.getChannelsList().stream() .map(e -> (PublicModeratedChannel) PublicModeratedChannel.fromProto(e)) .collect(Collectors.toList()); @@ -56,7 +56,7 @@ public static PublicModeratedChannelStore fromProto(bisq.chat.protobuf.PublicDis public ProtoResolver> getResolver() { return any -> { try { - return fromProto(any.unpack(bisq.chat.protobuf.PublicDiscussionChannelStore.class)); + return fromProto(any.unpack(bisq.chat.protobuf.PublicModeratedChannelStore.class)); } catch (InvalidProtocolBufferException e) { throw new UnresolvableProtobufMessageException(e); } diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java index 45aeb1985c..1035dcf0e8 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java +++ b/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java @@ -71,7 +71,7 @@ private PublicModeratedChatMessage(String messageId, } public bisq.chat.protobuf.ChatMessage toProto() { - return getChatMessageBuilder().setPublicDiscussionChatMessage(bisq.chat.protobuf.PublicDiscussionChatMessage.newBuilder()).build(); + return getChatMessageBuilder().setPublicModeratedChatMessage(bisq.chat.protobuf.PublicModeratedChatMessage.newBuilder()).build(); } public static PublicModeratedChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { diff --git a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java index 7ceb06107b..c0d9eef03f 100644 --- a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java @@ -20,7 +20,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.events.pub.PublicEventsChannelService; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; @@ -38,11 +38,11 @@ public class EventsChannelSelectionService implements PersistenceClient persistence; private final PrivateTwoPartyChannelService privateChannelService; - private final PublicEventsChannelService publicChannelService; + private final PublicModeratedChannelService publicChannelService; public EventsChannelSelectionService(PersistenceService persistenceService, PrivateTwoPartyChannelService privateChannelService, - PublicEventsChannelService publicChannelService) { + PublicModeratedChannelService publicChannelService) { persistence = persistenceService.getOrCreatePersistence(this, persistableStore); this.privateChannelService = privateChannelService; this.publicChannelService = publicChannelService; diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java deleted file mode 100644 index 593561620f..0000000000 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannel.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.pub; - -import bisq.chat.ChatDomain; -import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PublicChannel; -import bisq.i18n.Res; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PublicEventsChannel extends PublicChannel { - private final String channelName; - private final String description; - private final String channelAdminId; - private final List channelModeratorIds; - - public PublicEventsChannel(String id) { - this(id, - Res.get("events." + id + ".name"), - Res.get("events." + id + ".description"), - "", - new ArrayList<>(), - ChannelNotificationType.MENTION); - } - - public PublicEventsChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds) { - this(id, - channelName, - description, - channelAdminId, - channelModeratorIds, - ChannelNotificationType.MENTION); - } - - private PublicEventsChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds, - ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType, ChatDomain.EVENTS); - - this.channelName = channelName; - this.description = description; - this.channelAdminId = channelAdminId; - this.channelModeratorIds = channelModeratorIds; - // We need to sort deterministically as the data is used in the proof of work check - this.channelModeratorIds.sort(Comparator.comparing((String e) -> e)); - } - - public bisq.chat.protobuf.Channel toProto() { - return getChannelBuilder() - .setPublicEventsChannel(bisq.chat.protobuf.PublicEventsChannel.newBuilder() - .setChannelName(channelName) - .setDescription(description) - .setChannelAdminId(channelAdminId) - .addAllChannelModeratorIds(channelModeratorIds)) - .build(); - } - - public static PublicEventsChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PublicEventsChannel proto) { - return new PublicEventsChannel( - baseProto.getId(), - proto.getChannelName(), - proto.getDescription(), - proto.getChannelAdminId(), - new ArrayList<>(proto.getChannelModeratorIdsList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); - } - - @Override - public void addChatMessage(PublicEventsChatMessage chatMessage) { - chatMessages.add(chatMessage); - } - - @Override - public void removeChatMessage(PublicEventsChatMessage chatMessage) { - chatMessages.remove(chatMessage); - } - - @Override - public void removeChatMessages(Collection removeMessages) { - chatMessages.removeAll(removeMessages); - } - - @Override - public String getDisplayString() { - return channelName; - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java deleted file mode 100644 index 4bcfb6e45d..0000000000 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelService.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.pub; - -import bisq.chat.ChatDomain; -import bisq.chat.channel.PublicChannelService; -import bisq.chat.message.Quotation; -import bisq.common.observable.ObservableArray; -import bisq.network.NetworkService; -import bisq.network.p2p.services.data.storage.DistributedData; -import bisq.network.p2p.services.data.storage.auth.AuthenticatedData; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceService; -import bisq.user.identity.UserIdentityService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Date; -import java.util.Optional; - -@Slf4j -public class PublicEventsChannelService extends PublicChannelService { - @Getter - private final PublicEventsChannelStore persistableStore = new PublicEventsChannelStore(); - @Getter - private final Persistence persistence; - - public PublicEventsChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService) { - super(networkService, userIdentityService, ChatDomain.EVENTS); - - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // DataService.Listener - /////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void onAuthenticatedDataAdded(AuthenticatedData authenticatedData) { - DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicEventsChatMessage) { - processAddedMessage((PublicEventsChatMessage) distributedData); - } - } - - @Override - public void onAuthenticatedDataRemoved(AuthenticatedData authenticatedData) { - DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicEventsChatMessage) { - processRemovedMessage((PublicEventsChatMessage) distributedData); - } - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // PublicChannelService - /////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public ObservableArray getChannels() { - return persistableStore.getChannels(); - } - - @Override - protected PublicEventsChatMessage createChatMessage(String text, - Optional quotedMessage, - PublicEventsChannel publicChannel, - UserProfile userProfile) { - return new PublicEventsChatMessage(publicChannel.getId(), - userProfile.getId(), - text, - quotedMessage, - new Date().getTime(), - false); - } - - @Override - protected PublicEventsChatMessage createEditedChatMessage(PublicEventsChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { - return new PublicEventsChatMessage(originalChatMessage.getChannelId(), - userProfile.getId(), - editedText, - originalChatMessage.getQuotation(), - originalChatMessage.getDate(), - true); - } - - @Override - protected void maybeAddDefaultChannels() { - if (!getChannels().isEmpty()) { - return; - } - PublicEventsChannel defaultEventsChannel = new PublicEventsChannel("conferences"); - ObservableArray channels = getChannels(); - channels.add(defaultEventsChannel); - channels.add(new PublicEventsChannel("meetups")); - channels.add(new PublicEventsChannel("podcasts")); - /* channels.add(new PublicEventsChannel("noKyc")); - channels.add(new PublicEventsChannel("nodes"));*/ - channels.add(new PublicEventsChannel("tradeEvents")); - persist(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelStore.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelStore.java deleted file mode 100644 index bb669ff20d..0000000000 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChannelStore.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.pub; - -import bisq.common.observable.ObservableArray; -import bisq.common.proto.ProtoResolver; -import bisq.common.proto.UnresolvableProtobufMessageException; -import bisq.persistence.PersistableStore; -import com.google.protobuf.InvalidProtocolBufferException; -import lombok.Getter; - -import java.util.List; -import java.util.stream.Collectors; - -@Getter -public class PublicEventsChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); - - public PublicEventsChannelStore() { - } - - private PublicEventsChannelStore(List privateEventsChannels) { - setAll(privateEventsChannels); - } - - @Override - public bisq.chat.protobuf.PublicEventsChannelStore toProto() { - bisq.chat.protobuf.PublicEventsChannelStore.Builder builder = bisq.chat.protobuf.PublicEventsChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PublicEventsChannel::toProto).collect(Collectors.toList())); - return builder.build(); - } - - public static PublicEventsChannelStore fromProto(bisq.chat.protobuf.PublicEventsChannelStore proto) { - List privateEventsChannels = proto.getChannelsList().stream() - .map(e -> (PublicEventsChannel) PublicEventsChannel.fromProto(e)) - .collect(Collectors.toList()); - return new PublicEventsChannelStore(privateEventsChannels); - } - - @Override - public ProtoResolver> getResolver() { - return any -> { - try { - return fromProto(any.unpack(bisq.chat.protobuf.PublicEventsChannelStore.class)); - } catch (InvalidProtocolBufferException e) { - throw new UnresolvableProtobufMessageException(e); - } - }; - } - - @Override - public void applyPersisted(PublicEventsChannelStore chatStore) { - setAll(chatStore.getChannels()); - } - - @Override - public PublicEventsChannelStore getClone() { - return new PublicEventsChannelStore(channels); - } - - public void setAll(List privateEventsChannels) { - this.channels.clear(); - this.channels.addAll(privateEventsChannels); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java b/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java deleted file mode 100644 index fdf378ed22..0000000000 --- a/chat/src/main/java/bisq/chat/events/pub/PublicEventsChatMessage.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.events.pub; - -import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; -import bisq.chat.message.PublicChatMessage; -import bisq.chat.message.Quotation; -import bisq.common.util.StringUtils; -import bisq.network.p2p.services.data.storage.MetaData; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.Optional; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public final class PublicEventsChatMessage extends PublicChatMessage { - public PublicEventsChatMessage(String channelId, - String authorId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited) { - this(StringUtils.createShortUid(), - channelId, - authorId, - Optional.of(text), - quotedMessage, - date, - wasEdited, - MessageType.TEXT, - new MetaData(ChatMessage.TTL, 100000, PublicEventsChatMessage.class.getSimpleName())); - } - - private PublicEventsChatMessage(String messageId, - String channelId, - String authorId, - Optional text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, - channelId, - authorId, - text, - quotedMessage, - date, - wasEdited, - messageType, - metaData); - } - - public bisq.chat.protobuf.ChatMessage toProto() { - return getChatMessageBuilder().setPublicEventsChatMessage(bisq.chat.protobuf.PublicEventsChatMessage.newBuilder()).build(); - } - - public static PublicEventsChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { - Optional quotedMessage = baseProto.hasQuotation() ? - Optional.of(Quotation.fromProto(baseProto.getQuotation())) : - Optional.empty(); - return new PublicEventsChatMessage( - baseProto.getMessageId(), - baseProto.getChannelId(), - baseProto.getAuthorId(), - Optional.of(baseProto.getText()), - quotedMessage, - baseProto.getDate(), - baseProto.getWasEdited(), - MessageType.fromProto(baseProto.getMessageType()), - MetaData.fromProto(baseProto.getMetaData())); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 3bfadaec40..c118305f61 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -19,8 +19,6 @@ import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; import bisq.chat.channel.pub.PublicModeratedChatMessage; -import bisq.chat.events.pub.PublicEventsChatMessage; -import bisq.chat.support.pub.PublicSupportChatMessage; import bisq.chat.trade.priv.PrivateTradeChatMessage; import bisq.chat.trade.pub.PublicTradeChatMessage; import bisq.common.proto.Proto; @@ -107,19 +105,10 @@ public static ChatMessage fromProto(bisq.chat.protobuf.ChatMessage proto) { return PrivateTradeChatMessage.fromProto(proto); } - case PUBLICDISCUSSIONCHATMESSAGE: { + case PUBLICMODERATEDCHATMESSAGE: { return PublicModeratedChatMessage.fromProto(proto); } - - case PUBLICEVENTSCHATMESSAGE: { - return PublicEventsChatMessage.fromProto(proto); - } - - case PUBLICSUPPORTCHATMESSAGE: { - return PublicSupportChatMessage.fromProto(proto); - } - case MESSAGE_NOT_SET: { throw new UnresolvableProtobufMessageException(proto); } @@ -135,15 +124,9 @@ public static ProtoResolver getDistributedDataResolver() { case PUBLICTRADECHATMESSAGE: { return PublicTradeChatMessage.fromProto(proto); } - case PUBLICDISCUSSIONCHATMESSAGE: { + case PUBLICMODERATEDCHATMESSAGE: { return PublicModeratedChatMessage.fromProto(proto); } - case PUBLICEVENTSCHATMESSAGE: { - return PublicEventsChatMessage.fromProto(proto); - } - case PUBLICSUPPORTCHATMESSAGE: { - return PublicSupportChatMessage.fromProto(proto); - } case MESSAGE_NOT_SET: { throw new UnresolvableProtobufMessageException(proto); } diff --git a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java index 5e0ac87785..819759ab7a 100644 --- a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java @@ -20,8 +20,8 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; -import bisq.chat.support.pub.PublicSupportChannelService; import bisq.common.observable.Observable; import bisq.persistence.Persistence; import bisq.persistence.PersistenceClient; @@ -38,11 +38,11 @@ public class SupportChannelSelectionService implements PersistenceClient persistence; private final PrivateTwoPartyChannelService privateChannelService; - private final PublicSupportChannelService publicChannelService; + private final PublicModeratedChannelService publicChannelService; public SupportChannelSelectionService(PersistenceService persistenceService, PrivateTwoPartyChannelService privateChannelService, - PublicSupportChannelService publicChannelService) { + PublicModeratedChannelService publicChannelService) { persistence = persistenceService.getOrCreatePersistence(this, persistableStore); this.privateChannelService = privateChannelService; this.publicChannelService = publicChannelService; diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java deleted file mode 100644 index 1c3c15dc6f..0000000000 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannel.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support.pub; - -import bisq.chat.ChatDomain; -import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PublicChannel; -import bisq.i18n.Res; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PublicSupportChannel extends PublicChannel { - private final String channelName; - private final String description; - private final String channelAdminId; - private final List channelModeratorIds; - - public PublicSupportChannel(String id) { - this(id, - Res.get("support." + id + ".name"), - Res.get("support." + id + ".description"), - "", - new ArrayList<>(), - ChannelNotificationType.MENTION); - } - - public PublicSupportChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds) { - this(id, - channelName, - description, - channelAdminId, - channelModeratorIds, - ChannelNotificationType.MENTION); - } - - private PublicSupportChannel(String id, - String channelName, - String description, - String channelAdminId, - List channelModeratorIds, - ChannelNotificationType channelNotificationType) { - super(id, channelNotificationType, ChatDomain.SUPPORT); - - this.channelName = channelName; - this.description = description; - this.channelAdminId = channelAdminId; - this.channelModeratorIds = channelModeratorIds; - // We need to sort deterministically as the data is used in the proof of work check - this.channelModeratorIds.sort(Comparator.comparing((String e) -> e)); - } - - public bisq.chat.protobuf.Channel toProto() { - - return getChannelBuilder() - .setPublicSupportChannel(bisq.chat.protobuf.PublicSupportChannel.newBuilder() - .setChannelName(channelName) - .setDescription(description) - .setChannelAdminId(channelAdminId) - .addAllChannelModeratorIds(channelModeratorIds)) - .build(); - } - - public static PublicSupportChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PublicSupportChannel proto) { - return new PublicSupportChannel( - baseProto.getId(), - proto.getChannelName(), - proto.getDescription(), - proto.getChannelAdminId(), - new ArrayList<>(proto.getChannelModeratorIdsList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType())); - } - - @Override - public void addChatMessage(PublicSupportChatMessage chatMessage) { - chatMessages.add(chatMessage); - } - - @Override - public void removeChatMessage(PublicSupportChatMessage chatMessage) { - chatMessages.remove(chatMessage); - } - - @Override - public void removeChatMessages(Collection removeMessages) { - chatMessages.removeAll(removeMessages); - } - - @Override - public String getDisplayString() { - return channelName; - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java deleted file mode 100644 index 20469d68b1..0000000000 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelService.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support.pub; - -import bisq.chat.ChatDomain; -import bisq.chat.channel.PublicChannelService; -import bisq.chat.message.Quotation; -import bisq.common.observable.ObservableArray; -import bisq.network.NetworkService; -import bisq.network.p2p.services.data.storage.DistributedData; -import bisq.network.p2p.services.data.storage.auth.AuthenticatedData; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceService; -import bisq.user.identity.UserIdentityService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Date; -import java.util.Optional; - -@Slf4j -public class PublicSupportChannelService extends PublicChannelService { - @Getter - private final PublicSupportChannelStore persistableStore = new PublicSupportChannelStore(); - @Getter - private final Persistence persistence; - - public PublicSupportChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService) { - super(networkService, userIdentityService, ChatDomain.SUPPORT); - - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // DataService.Listener - /////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void onAuthenticatedDataAdded(AuthenticatedData authenticatedData) { - DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicSupportChatMessage) { - processAddedMessage((PublicSupportChatMessage) distributedData); - } - } - - @Override - public void onAuthenticatedDataRemoved(AuthenticatedData authenticatedData) { - DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicSupportChatMessage) { - processRemovedMessage((PublicSupportChatMessage) distributedData); - } - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // PublicChannelService - /////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public ObservableArray getChannels() { - return persistableStore.getChannels(); - } - - @Override - protected PublicSupportChatMessage createChatMessage(String text, - Optional quotedMessage, - PublicSupportChannel publicChannel, - UserProfile userProfile) { - return new PublicSupportChatMessage(publicChannel.getId(), - userProfile.getId(), - text, - quotedMessage, - new Date().getTime(), - false); - } - - @Override - protected PublicSupportChatMessage createEditedChatMessage(PublicSupportChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { - return new PublicSupportChatMessage(originalChatMessage.getChannelId(), - userProfile.getId(), - editedText, - originalChatMessage.getQuotation(), - originalChatMessage.getDate(), - true); - } - - @Override - protected void maybeAddDefaultChannels() { - if (!getChannels().isEmpty()) { - return; - } - - PublicSupportChannel defaultSupportChannel = new PublicSupportChannel("support"); - ObservableArray channels = getChannels(); - channels.add(defaultSupportChannel); - channels.add(new PublicSupportChannel("questions")); - channels.add(new PublicSupportChannel("reports")); - persist(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelStore.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelStore.java deleted file mode 100644 index 0577c25e22..0000000000 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChannelStore.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support.pub; - -import bisq.common.observable.ObservableArray; -import bisq.common.proto.ProtoResolver; -import bisq.common.proto.UnresolvableProtobufMessageException; -import bisq.persistence.PersistableStore; -import com.google.protobuf.InvalidProtocolBufferException; -import lombok.Getter; - -import java.util.List; -import java.util.stream.Collectors; - -@Getter -public class PublicSupportChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); - - public PublicSupportChannelStore() { - } - - private PublicSupportChannelStore(List privateSupportChannels) { - setAll(privateSupportChannels); - } - - @Override - public bisq.chat.protobuf.PublicSupportChannelStore toProto() { - bisq.chat.protobuf.PublicSupportChannelStore.Builder builder = bisq.chat.protobuf.PublicSupportChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PublicSupportChannel::toProto).collect(Collectors.toList())); - return builder.build(); - } - - public static PublicSupportChannelStore fromProto(bisq.chat.protobuf.PublicSupportChannelStore proto) { - List privateSupportChannels = proto.getChannelsList().stream() - .map(e -> (PublicSupportChannel) PublicSupportChannel.fromProto(e)) - .collect(Collectors.toList()); - return new PublicSupportChannelStore(privateSupportChannels); - } - - @Override - public ProtoResolver> getResolver() { - return any -> { - try { - return fromProto(any.unpack(bisq.chat.protobuf.PublicSupportChannelStore.class)); - } catch (InvalidProtocolBufferException e) { - throw new UnresolvableProtobufMessageException(e); - } - }; - } - - @Override - public void applyPersisted(PublicSupportChannelStore chatStore) { - setAll(chatStore.getChannels()); - } - - @Override - public PublicSupportChannelStore getClone() { - return new PublicSupportChannelStore(channels); - } - - public void setAll(List privateSupportChannels) { - this.channels.clear(); - this.channels.addAll(privateSupportChannels); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java b/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java deleted file mode 100644 index 83eddc0645..0000000000 --- a/chat/src/main/java/bisq/chat/support/pub/PublicSupportChatMessage.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support.pub; - -import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; -import bisq.chat.message.PublicChatMessage; -import bisq.chat.message.Quotation; -import bisq.common.util.StringUtils; -import bisq.network.p2p.services.data.storage.MetaData; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.Optional; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public final class PublicSupportChatMessage extends PublicChatMessage { - public PublicSupportChatMessage(String channelId, - String authorId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited) { - this(StringUtils.createShortUid(), - channelId, - authorId, - Optional.of(text), - quotedMessage, - date, - wasEdited, - MessageType.TEXT, - new MetaData(ChatMessage.TTL, 100000, PublicSupportChatMessage.class.getSimpleName())); - } - - private PublicSupportChatMessage(String messageId, - String channelId, - String authorId, - Optional text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, - channelId, - authorId, - text, - quotedMessage, - date, - wasEdited, - messageType, - metaData); - } - - public bisq.chat.protobuf.ChatMessage toProto() { - return getChatMessageBuilder().setPublicSupportChatMessage(bisq.chat.protobuf.PublicSupportChatMessage.newBuilder()).build(); - } - - public static PublicSupportChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { - Optional quotedMessage = baseProto.hasQuotation() ? - Optional.of(Quotation.fromProto(baseProto.getQuotation())) : - Optional.empty(); - return new PublicSupportChatMessage( - baseProto.getMessageId(), - baseProto.getChannelId(), - baseProto.getAuthorId(), - Optional.of(baseProto.getText()), - quotedMessage, - baseProto.getDate(), - baseProto.getWasEdited(), - MessageType.fromProto(baseProto.getMessageType()), - MetaData.fromProto(baseProto.getMetaData())); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index 53f7081ccc..b2b4ca9c74 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -72,7 +72,7 @@ private PrivateTradeChannel(UserProfile peerOrTrader1, UserProfile myUserProfileOrTrader2, UserIdentity myUserIdentity, Optional mediator) { - this(PrivateChannel.createChannelId(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), + this(PrivateChannel.createChannelName(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), peerOrTrader1, myUserProfileOrTrader2, myUserIdentity, @@ -81,14 +81,14 @@ private PrivateTradeChannel(UserProfile peerOrTrader1, ChannelNotificationType.ALL); } - private PrivateTradeChannel(String id, + private PrivateTradeChannel(String channelName, UserProfile peerOrTrader1, UserProfile myUserProfileOrTrader2, UserIdentity myUserIdentity, Optional mediator, List chatMessages, ChannelNotificationType channelNotificationType) { - super(id, myUserIdentity, chatMessages, channelNotificationType, ChatDomain.TRADE); + super(ChatDomain.TRADE, channelName, myUserIdentity, chatMessages, channelNotificationType); this.peerOrTrader1 = peerOrTrader1; this.myUserProfileOrTrader2 = myUserProfileOrTrader2; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index 12e3e77f13..b73c9ceec2 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -100,7 +100,7 @@ protected PrivateTradeChannel createNewChannel(UserProfile peer, UserIdentity my } public PrivateTradeChannel mediatorCreatesNewChannel(UserIdentity myUserIdentity, UserProfile trader1, UserProfile trader2) { - String channelId = PrivateTradeChannel.createChannelId(new Pair<>(trader1.getId(), trader2.getId())); + String channelId = PrivateTradeChannel.createChannelName(new Pair<>(trader1.getId(), trader2.getId())); Optional existingChannel = getChannels().stream() .filter(channel -> channel.getId().equals(channelId)) .findAny(); @@ -115,7 +115,7 @@ public PrivateTradeChannel mediatorCreatesNewChannel(UserIdentity myUserIdentity } public PrivateTradeChannel traderCreatesNewChannel(UserIdentity myUserIdentity, UserProfile peersUserProfile, Optional mediator) { - String channelId = PrivateTradeChannel.createChannelId(new Pair<>(myUserIdentity.getUserProfile().getId(), peersUserProfile.getId())); + String channelId = PrivateTradeChannel.createChannelName(new Pair<>(myUserIdentity.getUserProfile().getId(), peersUserProfile.getId())); Optional existingChannel = getChannels().stream() .filter(channel -> channel.getId().equals(channelId)) .findAny(); diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index b524ed0961..206ad4308f 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -35,11 +35,11 @@ public final class PublicTradeChannel extends PublicChannel privateChannel) { } protected void applyDefaultPublicChannelIcon(PublicChannel channel) { - String type = null; - if (channel instanceof PublicEventsChannel) { - type = "-events-"; - } else if (channel instanceof PublicModeratedChannel) { - type = "-discussion-"; - } else if (channel instanceof PublicSupportChannel) { - type = "-support-"; - } - if (type != null) { - // String iconId = "channels" + type + channel.getId() + "-white"; - String iconId = "channels" + type + channel.getId(); - model.getChannelIcon().set(BisqIconButton.createIconButton(iconId)); - } + String domain = "-" + channel.getChatDomain().name().toLowerCase() + "-"; + String iconId = "channels" + domain + channel.getId(); + model.getChannelIcon().set(BisqIconButton.createIconButton(iconId)); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java index 2f59ad7f34..6868382079 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java @@ -3,9 +3,6 @@ import bisq.chat.ChatService; import bisq.chat.channel.Channel; import bisq.chat.channel.PrivateChannel; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.events.pub.PublicEventsChannel; -import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.common.observable.Pin; @@ -247,19 +244,10 @@ public ChannelItem(Channel channel, @Nullable UserIdentityService userIdentit id = channel.getId(); - String type = null; - if (channel instanceof PublicEventsChannel) { - type = "-events-"; - } else if (channel instanceof PublicModeratedChannel) { - type = "-discussion-"; - } else if (channel instanceof PublicSupportChannel) { - type = "-support-"; - } - if (type != null) { - iconIdSelected = "channels" + type + channel.getId(); - iconIdHover = "channels" + type + channel.getId() + "-white"; - iconId = "channels" + type + channel.getId() + "-grey"; - } + String domain = "-" + channel.getChatDomain().name().toLowerCase() + "-"; + iconIdSelected = "channels" + domain + channel.getId(); + iconIdHover = "channels" + domain + channel.getId() + "-white"; + iconId = "channels" + domain + channel.getId() + "-grey"; if (channel instanceof PrivateChannel) { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java index 7ab0db377a..09b09f7438 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java @@ -19,9 +19,9 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; +import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.pub.PublicEventsChannel; -import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; import bisq.i18n.Res; @@ -54,7 +54,7 @@ protected static class Controller extends ChannelSelection.Controller { private final Model model; @Getter private final View view; - private final PublicEventsChannelService publicEventsChannelService; + private final PublicModeratedChannelService publicEventsChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final EventsChannelSelectionService eventsChannelSelectionService; @@ -80,13 +80,13 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(ChannelSelection.View.ChannelItem::new) .to(publicEventsChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(eventsChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PublicEventsChannel) { + if (channel instanceof PublicModeratedChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); } }); @@ -134,7 +134,7 @@ protected ListCell getListCell() { @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PublicEventsChannel) { + if (item != null && !empty && item.getChannel() instanceof PublicModeratedChannel) { widthSubscription = setupCellBinding(this, item, label, iconImageView); updateCell(this, item, label, iconImageView); setGraphic(hBox); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java index ac6eb843ac..245bfc6a86 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java @@ -19,9 +19,9 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; +import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.pub.PublicSupportChannel; -import bisq.chat.support.pub.PublicSupportChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; import bisq.i18n.Res; @@ -54,7 +54,7 @@ protected static class Controller extends ChannelSelection.Controller { private final Model model; @Getter private final View view; - private final PublicSupportChannelService publicSupportChannelService; + private final PublicModeratedChannelService publicSupportChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final SupportChannelSelectionService supportChannelSelectionService; @@ -80,13 +80,13 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(ChannelSelection.View.ChannelItem::new) .to(publicSupportChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(supportChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PublicSupportChannel) { + if (channel instanceof PublicModeratedChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); } }); @@ -135,7 +135,7 @@ protected ListCell getListCell() { @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PublicSupportChannel) { + if (item != null && !empty && item.getChannel() instanceof PublicModeratedChannel) { widthSubscription = setupCellBinding(this, item, label, iconImageView); updateCell(this, item, label, iconImageView); setGraphic(hBox); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java index 0875038219..480a0e3129 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java @@ -160,7 +160,7 @@ public void deSelectChannel() { public void onShowMarket(View.MarketListItem marketListItem) { if (marketListItem != null) { model.allMarkets.remove(marketListItem); - publicTradeChannelService.findChannel(PublicTradeChannel.getId(marketListItem.market)) + publicTradeChannelService.findChannel(PublicTradeChannel.getChannelId(marketListItem.market)) .ifPresent(channel -> { publicTradeChannelService.showChannel(channel); tradeChannelSelectionService.selectChannel(channel); @@ -180,7 +180,7 @@ public void onHideTradeChannel(PublicTradeChannel channel) { } private int getNumMessages(Market market) { - return publicTradeChannelService.findChannel(PublicTradeChannel.getId(market)) + return publicTradeChannelService.findChannel(PublicTradeChannel.getChannelId(market)) .map(e -> e.getChatMessages().size()) .orElse(0); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index c9e13fc9a9..1141e21947 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -21,9 +21,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.events.pub.PublicEventsChannel; import bisq.chat.message.ChatMessage; -import bisq.chat.support.pub.PublicSupportChannel; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.desktop.components.containers.Spacer; import bisq.desktop.components.controls.BisqIconButton; @@ -110,71 +108,8 @@ void setChannel(Channel channel) { .sorted() .collect(Collectors.toList())); - switch (channel.getChatDomain()) { - case TRADE -> { - model.description.set(((PublicTradeChannel) channel).getDescription()); - model.descriptionVisible.set(true); - model.adminProfile = Optional.empty(); - model.moderators.clear(); - } - case DISCUSSION -> { - PublicModeratedChannel publicModeratedChannel = (PublicModeratedChannel) channel; - model.description.set(publicModeratedChannel.getDescription()); - model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicModeratedChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicModeratedChannel.getChannelModeratorIds().stream() - .flatMap(id -> userProfileService.findUserProfile(id).stream()) - .map(ChatUserOverview::new) - .sorted() - .collect(Collectors.toList())); - } - case EVENTS -> { - PublicEventsChannel publicEventsChannel = (PublicEventsChannel) channel; - model.description.set(publicEventsChannel.getDescription()); - model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicEventsChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicEventsChannel.getChannelModeratorIds().stream() - .flatMap(id -> userProfileService.findUserProfile(id).stream()) - .map(ChatUserOverview::new) - .sorted() - .collect(Collectors.toList())); - } - case SUPPORT -> { - PublicSupportChannel publicSupportChannel = (PublicSupportChannel) channel; - model.description.set(publicSupportChannel.getDescription()); - model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicSupportChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicSupportChannel.getChannelModeratorIds().stream() - .flatMap(id -> userProfileService.findUserProfile(id).stream()) - .map(ChatUserOverview::new) - .sorted() - .collect(Collectors.toList())); - } - default -> { - model.descriptionVisible.set(false); - model.description.set(null); - model.adminProfile = Optional.empty(); - model.moderators.clear(); - } - } - - /* if (channel instanceof PublicTradeChannel) { - model.description.set(((PublicTradeChannel) channel).getDescription()); - model.descriptionVisible.set(true); - model.adminProfile = Optional.empty(); - model.moderators.clear(); - } else if (channel instanceof PublicDiscussionChannel) { - PublicDiscussionChannel publicDiscussionChannel = (PublicDiscussionChannel) channel; - model.description.set(publicDiscussionChannel.getDescription()); - model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicDiscussionChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicDiscussionChannel.getChannelModeratorIds().stream() - .flatMap(id -> userProfileService.findUserProfile(id).stream()) - .map(ChatUserOverview::new) - .sorted() - .collect(Collectors.toList())); - } else if (channel instanceof PublicEventsChannel) { - PublicEventsChannel publicEventsChannel = (PublicEventsChannel) channel; + if (channel instanceof PublicModeratedChannel) { + PublicModeratedChannel publicEventsChannel = (PublicModeratedChannel) channel; model.description.set(publicEventsChannel.getDescription()); model.descriptionVisible.set(true); model.adminProfile = userProfileService.findUserProfile(publicEventsChannel.getChannelAdminId()).map(ChatUserOverview::new); @@ -183,22 +118,17 @@ void setChannel(Channel channel) { .map(ChatUserOverview::new) .sorted() .collect(Collectors.toList())); - } else if (channel instanceof PublicSupportChannel) { - PublicSupportChannel publicSupportChannel = (PublicSupportChannel) channel; - model.description.set(publicSupportChannel.getDescription()); + } else if (channel instanceof PublicTradeChannel) { + model.description.set(((PublicTradeChannel) channel).getDescription()); model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicSupportChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicSupportChannel.getChannelModeratorIds().stream() - .flatMap(id -> userProfileService.findUserProfile(id).stream()) - .map(ChatUserOverview::new) - .sorted() - .collect(Collectors.toList())); + model.adminProfile = Optional.empty(); + model.moderators.clear(); } else { model.descriptionVisible.set(false); model.description.set(null); model.adminProfile = Optional.empty(); model.moderators.clear(); - }*/ + } model.channel.set(channel); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 6ad81ad435..63c6a6ce09 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -28,13 +28,9 @@ import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.pub.PublicEventsChannel; -import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.message.ChatMessage; import bisq.chat.message.Quotation; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.pub.PublicSupportChannel; -import bisq.chat.support.pub.PublicSupportChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -129,10 +125,10 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final TradeChannelSelectionService tradeChannelSelectionService; private final DiscussionChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; - private final PublicEventsChannelService publicEventsChannelService; + private final PublicModeratedChannelService publicEventsChannelService; private final PrivateTwoPartyChannelService privateEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; - private final PublicSupportChannelService publicSupportChannelService; + private final PublicModeratedChannelService publicSupportChannelService; private final PrivateTwoPartyChannelService privateSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; private final UserProfileSelection userProfileSelection; @@ -257,7 +253,20 @@ private void doSendMessage(String text) { new Popup().information(Res.get("social.chat.sendMsg.tradeRulesNotConfirmed.popup")).show(); } } else if (channel instanceof PublicModeratedChannel) { - publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + switch (channel.getChatDomain()) { + case TRADE -> { + } + case DISCUSSION -> { + publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + } + case EVENTS -> { + publicEventsChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + } + case SUPPORT -> { + publicSupportChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + } + } + } else if (channel instanceof PrivateTwoPartyChannel) { switch (channel.getChatDomain()) { case TRADE -> { @@ -272,10 +281,6 @@ private void doSendMessage(String text) { privateSupportChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); } } - } else if (channel instanceof PublicEventsChannel) { - publicEventsChannelService.publishChatMessage(text, quotation, (PublicEventsChannel) channel, userIdentity); - } else if (channel instanceof PublicSupportChannel) { - publicSupportChannelService.publishChatMessage(text, quotation, (PublicSupportChannel) channel, userIdentity); } quotedMessageBlock.close(); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 44b18c6d5f..5cbbc50b70 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -29,16 +29,10 @@ import bisq.chat.channel.pub.PublicModeratedChatMessage; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.pub.PublicEventsChannel; -import bisq.chat.events.pub.PublicEventsChannelService; -import bisq.chat.events.pub.PublicEventsChatMessage; import bisq.chat.message.ChatMessage; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.pub.PublicSupportChannel; -import bisq.chat.support.pub.PublicSupportChannelService; -import bisq.chat.support.pub.PublicSupportChatMessage; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -176,10 +170,10 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final DiscussionChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; private final PrivateTwoPartyChannelService privateEventsChannelService; - private final PublicEventsChannelService publicEventsChannelService; + private final PublicModeratedChannelService publicEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; private final PrivateTwoPartyChannelService privateSupportChannelService; - private final PublicSupportChannelService publicSupportChannelService; + private final PublicModeratedChannelService publicSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; private final MediationService mediationService; private Pin selectedChannelPin, chatMessagesPin; @@ -284,13 +278,13 @@ public void onActivate() { } else if (model.getChatDomain() == ChatDomain.EVENTS) { selectedChannelPin = eventsChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); - if (channel instanceof PublicEventsChannel) { + if (channel instanceof PublicModeratedChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PublicEventsChannel) channel).getChatMessages()); + .to(((PublicModeratedChannel) channel).getChatMessages()); model.allowEditing.set(true); } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { @@ -305,13 +299,13 @@ public void onActivate() { } else if (model.getChatDomain() == ChatDomain.SUPPORT) { selectedChannelPin = supportChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); - if (channel instanceof PublicSupportChannel) { + if (channel instanceof PublicModeratedChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PublicSupportChannel) channel).getChatMessages()); + .to(((PublicModeratedChannel) channel).getChatMessages()); model.allowEditing.set(true); } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { @@ -426,11 +420,15 @@ private void doDeleteMessage(ChatMessage chatMessage, UserIdentity messageAuthor if (chatMessage instanceof PublicTradeChatMessage) { publicTradeChannelService.deleteChatMessage((PublicTradeChatMessage) chatMessage, messageAuthor); } else if (chatMessage instanceof PublicModeratedChatMessage) { - publicDiscussionChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor); - } else if (chatMessage instanceof PublicEventsChatMessage) { - publicEventsChannelService.deleteChatMessage((PublicEventsChatMessage) chatMessage, messageAuthor); - } else if (chatMessage instanceof PublicSupportChatMessage) { - publicSupportChannelService.deleteChatMessage((PublicSupportChatMessage) chatMessage, messageAuthor); + + //todo services dont do any domain specific here + // -> networkService.removeAuthenticatedData(chatMessage, userIdentity.getNodeIdAndKeyPair()); + publicDiscussionChannelService.findChannel(chatMessage.getChannelId()) + .ifPresent(c -> publicDiscussionChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor)); + publicEventsChannelService.findChannel(chatMessage.getChannelId()) + .ifPresent(c -> publicEventsChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor)); + publicSupportChannelService.findChannel(chatMessage.getChannelId()) + .ifPresent(c -> publicSupportChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor)); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index d303049d6d..185b90eef3 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -23,8 +23,8 @@ import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.events.pub.PublicEventsChannelService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; @@ -37,7 +37,7 @@ @Slf4j public class EventsController extends ChatController implements Controller { - private final PublicEventsChannelService publicEventsChannelService; + private final PublicModeratedChannelService publicEventsChannelService; private final EventsChannelSelectionService eventsChannelSelectionService; private PublicEventsChannelSelection publicEventsChannelSelection; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index e142900118..d96a52aa3a 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -23,9 +23,9 @@ import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; +import bisq.chat.channel.pub.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.chat.support.SupportChannelSelectionService; -import bisq.chat.support.pub.PublicSupportChannelService; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatController; @@ -37,7 +37,7 @@ @Slf4j public class SupportController extends ChatController implements Controller { - private final PublicSupportChannelService publicSupportChannelService; + private final PublicModeratedChannelService publicSupportChannelService; private final SupportChannelSelectionService supportChannelSelectionService; private PublicSupportChannelSelection publicSupportChannelSelection; diff --git a/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java b/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java index 688ac711df..e234af7b9e 100644 --- a/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java +++ b/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java @@ -124,7 +124,7 @@ public void setShowMatchingOffers(boolean showMatchingOffers) { @Override public void onActivate() { - PublicTradeChannel channel = publicTradeChannelService.findChannel(PublicTradeChannel.getId(model.getMarket())).orElseThrow(); + PublicTradeChannel channel = publicTradeChannelService.findChannel(PublicTradeChannel.getChannelId(model.getMarket())).orElseThrow(); model.setSelectedChannel(channel); model.getShowCreateOfferSuccess().set(false); diff --git a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java index 0bb1977b8f..f4f0a4a6ab 100644 --- a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java +++ b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java @@ -1,6 +1,6 @@ package bisq.restApi.dto; -import bisq.chat.discussion.pub.PublicDiscussionChannel; +import bisq.chat.channel.pub.PublicModeratedChannel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +21,7 @@ public final class PublicDiscussionChannelDto { private String channelAdminId; private List channelModeratorIds; - public static PublicDiscussionChannelDto from(PublicDiscussionChannel publicDiscussionChannel) { + public static PublicDiscussionChannelDto from(PublicModeratedChannel publicDiscussionChannel) { PublicDiscussionChannelDto dto = new PublicDiscussionChannelDto(); dto.id = publicDiscussionChannel.getId(); dto.channelName = publicDiscussionChannel.getChannelName(); From 009fb2b37cef5ad64b17e47d6c9b571f8df2b7b3 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 14:17:01 -0500 Subject: [PATCH 06/15] Refactor: rename package --- chat/src/main/java/bisq/chat/ChatService.java | 4 ++-- chat/src/main/java/bisq/chat/channel/Channel.java | 2 +- .../{pub => public_moderated}/PublicModeratedChannel.java | 2 +- .../PublicModeratedChannelService.java | 2 +- .../PublicModeratedChannelStore.java | 2 +- .../PublicModeratedChatMessage.java | 2 +- .../chat/discuss/DiscussionChannelSelectionService.java | 2 +- .../bisq/chat/events/EventsChannelSelectionService.java | 2 +- chat/src/main/java/bisq/chat/message/ChatMessage.java | 2 +- .../bisq/chat/support/SupportChannelSelectionService.java | 2 +- .../chat/channels/PublicDiscussionChannelSelection.java | 4 ++-- .../content/chat/channels/PublicEventsChannelSelection.java | 4 ++-- .../chat/channels/PublicSupportChannelSelection.java | 4 ++-- .../primary/main/content/chat/sidebar/ChannelSidebar.java | 2 +- .../main/content/components/ChatMessagesComponent.java | 4 ++-- .../main/content/components/ChatMessagesListView.java | 6 +++--- .../main/content/discussion/DiscussionsController.java | 2 +- .../primary/main/content/events/EventsController.java | 2 +- .../primary/main/content/support/SupportController.java | 2 +- .../java/bisq/restApi/dto/PublicDiscussionChannelDto.java | 2 +- 20 files changed, 27 insertions(+), 27 deletions(-) rename chat/src/main/java/bisq/chat/channel/{pub => public_moderated}/PublicModeratedChannel.java (98%) rename chat/src/main/java/bisq/chat/channel/{pub => public_moderated}/PublicModeratedChannelService.java (99%) rename chat/src/main/java/bisq/chat/channel/{pub => public_moderated}/PublicModeratedChannelStore.java (98%) rename chat/src/main/java/bisq/chat/channel/{pub => public_moderated}/PublicModeratedChatMessage.java (98%) diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 1a83906f13..9bec7303e6 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -18,8 +18,8 @@ package bisq.chat; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.support.SupportChannelSelectionService; diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index b0b4925c6b..4f814cb127 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -19,7 +19,7 @@ import bisq.chat.ChatDomain; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; import bisq.chat.trade.priv.PrivateTradeChannel; diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java similarity index 98% rename from chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java rename to chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java index e59274ebc4..1569d6bc6f 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannel.java +++ b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.pub; +package bisq.chat.channel.public_moderated; import bisq.chat.ChatDomain; import bisq.chat.channel.ChannelNotificationType; diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelService.java b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java similarity index 99% rename from chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelService.java rename to chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java index 1a438a88e5..8d717bf937 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.pub; +package bisq.chat.channel.public_moderated; import bisq.chat.ChatDomain; import bisq.chat.channel.PublicChannelService; diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelStore.java similarity index 98% rename from chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java rename to chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelStore.java index 3f79248143..52e60d0d19 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelStore.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.pub; +package bisq.chat.channel.public_moderated; import bisq.common.observable.ObservableArray; import bisq.common.proto.ProtoResolver; diff --git a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChatMessage.java similarity index 98% rename from chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java rename to chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChatMessage.java index 1035dcf0e8..c2efce2fc9 100644 --- a/chat/src/main/java/bisq/chat/channel/pub/PublicModeratedChatMessage.java +++ b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChatMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.pub; +package bisq.chat.channel.public_moderated; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; diff --git a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java index 4ab4ff9f0a..25641fc529 100644 --- a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java @@ -20,7 +20,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; diff --git a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java index c0d9eef03f..97c91fc649 100644 --- a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java @@ -20,7 +20,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index c118305f61..2c518c3b87 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -18,7 +18,7 @@ package bisq.chat.message; import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; -import bisq.chat.channel.pub.PublicModeratedChatMessage; +import bisq.chat.channel.public_moderated.PublicModeratedChatMessage; import bisq.chat.trade.priv.PrivateTradeChatMessage; import bisq.chat.trade.pub.PublicTradeChatMessage; import bisq.common.proto.Proto; diff --git a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java index 819759ab7a..d64a3cdb6e 100644 --- a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java @@ -20,7 +20,7 @@ import bisq.chat.channel.Channel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java index d9ae7ad6ff..1467447e33 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java @@ -19,8 +19,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java index 09b09f7438..f72b5ed319 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java @@ -19,8 +19,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java index 245bfc6a86..1d5a1b8fcc 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java @@ -19,8 +19,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.support.SupportChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index 1141e21947..fdc096d1b9 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -20,7 +20,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; import bisq.chat.message.ChatMessage; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.desktop.components.containers.Spacer; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 63c6a6ce09..6af513fa22 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -24,8 +24,8 @@ import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 5cbbc50b70..8858b50dce 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -24,9 +24,9 @@ import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; -import bisq.chat.channel.pub.PublicModeratedChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; -import bisq.chat.channel.pub.PublicModeratedChatMessage; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChatMessage; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index c8b746f6a0..d95d816d86 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -23,7 +23,7 @@ import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index 185b90eef3..361cbd6a54 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -23,7 +23,7 @@ import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index d96a52aa3a..a9b64e074b 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -23,7 +23,7 @@ import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.pub.PublicModeratedChannelService; +import bisq.chat.channel.public_moderated.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.chat.support.SupportChannelSelectionService; import bisq.desktop.common.view.Controller; diff --git a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java index f4f0a4a6ab..9864982a8a 100644 --- a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java +++ b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java @@ -1,6 +1,6 @@ package bisq.restApi.dto; -import bisq.chat.channel.pub.PublicModeratedChannel; +import bisq.chat.channel.public_moderated.PublicModeratedChannel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; From 62ccb48539ad1849bf4f9763bbd17afbfa3235b3 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 14:21:15 -0500 Subject: [PATCH 07/15] Refactor: rename ChatDomain to ChannelDomain and move to channel package --- chat/src/main/java/bisq/chat/ChatService.java | 42 +++++++++---------- .../main/java/bisq/chat/channel/Channel.java | 11 +++-- .../ChannelDomain.java} | 12 +++--- .../bisq/chat/channel/ChannelService.java | 7 ++-- .../bisq/chat/channel/PrivateChannel.java | 5 +-- .../chat/channel/PrivateChannelService.java | 5 +-- .../java/bisq/chat/channel/PublicChannel.java | 5 +-- .../chat/channel/PublicChannelService.java | 5 +-- .../PrivateTwoPartyChannel.java | 12 +++--- .../PrivateTwoPartyChannelService.java | 10 ++--- .../PublicModeratedChannel.java | 16 +++---- .../PublicModeratedChannelService.java | 6 +-- .../chat/trade/priv/PrivateTradeChannel.java | 4 +- .../priv/PrivateTradeChannelService.java | 4 +- .../chat/trade/pub/PublicTradeChannel.java | 6 +-- .../trade/pub/PublicTradeChannelService.java | 4 +- chat/src/main/proto/chat.proto | 4 +- .../main/content/chat/ChatController.java | 14 +++---- .../chat/channels/ChannelSelection.java | 2 +- .../channels/PrivateChannelSelection.java | 34 +++++++-------- .../components/ChatMessagesComponent.java | 38 ++++++++--------- .../components/ChatMessagesListView.java | 32 +++++++------- .../discussion/DiscussionsController.java | 8 ++-- .../content/discussion/DiscussionsModel.java | 8 ++-- .../main/content/events/EventsController.java | 8 ++-- .../main/content/events/EventsModel.java | 8 ++-- .../content/support/SupportController.java | 8 ++-- .../main/content/support/SupportModel.java | 8 ++-- .../bisqEasy/chat/BisqEasyChatController.java | 8 ++-- .../bisqEasy/chat/BisqEasyChatModel.java | 8 ++-- 30 files changed, 168 insertions(+), 174 deletions(-) rename chat/src/main/java/bisq/chat/{ChatDomain.java => channel/ChannelDomain.java} (70%) diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 9bec7303e6..774820f9e0 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -17,6 +17,7 @@ package bisq.chat; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.channel.public_moderated.PublicModeratedChannel; import bisq.chat.channel.public_moderated.PublicModeratedChannelService; @@ -77,17 +78,16 @@ public ChatService(PersistenceService persistenceService, networkService, userIdentityService, proofOfWorkService, - ChatDomain.DISCUSSION); + ChannelDomain.DISCUSSION); publicDiscussionChannelService = new PublicModeratedChannelService(persistenceService, networkService, userIdentityService, - ChatDomain.DISCUSSION, - List.of(new PublicModeratedChannel(ChatDomain.DISCUSSION, "bisq"), - new PublicModeratedChannel(ChatDomain.DISCUSSION, "bitcoin"), - /* new PublicModeratedChannel(ChatDomain.DISCUSSION,"monero"),*/ - new PublicModeratedChannel(ChatDomain.DISCUSSION, "markets"), - new PublicModeratedChannel(ChatDomain.DISCUSSION, "economy"), - new PublicModeratedChannel(ChatDomain.DISCUSSION, "offTopic"))); + ChannelDomain.DISCUSSION, + List.of(new PublicModeratedChannel(ChannelDomain.DISCUSSION, "bisq"), + new PublicModeratedChannel(ChannelDomain.DISCUSSION, "bitcoin"), + new PublicModeratedChannel(ChannelDomain.DISCUSSION, "markets"), + new PublicModeratedChannel(ChannelDomain.DISCUSSION, "economy"), + new PublicModeratedChannel(ChannelDomain.DISCUSSION, "offTopic"))); discussionChannelSelectionService = new DiscussionChannelSelectionService(persistenceService, privateDiscussionChannelService, @@ -98,17 +98,17 @@ public ChatService(PersistenceService persistenceService, networkService, userIdentityService, proofOfWorkService, - ChatDomain.EVENTS); + ChannelDomain.EVENTS); publicEventsChannelService = new PublicModeratedChannelService(persistenceService, networkService, userIdentityService, - ChatDomain.EVENTS, - List.of(new PublicModeratedChannel(ChatDomain.EVENTS, "conferences"), - new PublicModeratedChannel(ChatDomain.EVENTS, "meetups"), - new PublicModeratedChannel(ChatDomain.EVENTS, "podcasts"), - new PublicModeratedChannel(ChatDomain.EVENTS, "noKyc"), - new PublicModeratedChannel(ChatDomain.EVENTS, "nodes"), - new PublicModeratedChannel(ChatDomain.EVENTS, "tradeEvents"))); + ChannelDomain.EVENTS, + List.of(new PublicModeratedChannel(ChannelDomain.EVENTS, "conferences"), + new PublicModeratedChannel(ChannelDomain.EVENTS, "meetups"), + new PublicModeratedChannel(ChannelDomain.EVENTS, "podcasts"), + new PublicModeratedChannel(ChannelDomain.EVENTS, "noKyc"), + new PublicModeratedChannel(ChannelDomain.EVENTS, "nodes"), + new PublicModeratedChannel(ChannelDomain.EVENTS, "tradeEvents"))); eventsChannelSelectionService = new EventsChannelSelectionService(persistenceService, privateEventsChannelService, publicEventsChannelService); @@ -118,14 +118,14 @@ public ChatService(PersistenceService persistenceService, networkService, userIdentityService, proofOfWorkService, - ChatDomain.SUPPORT); + ChannelDomain.SUPPORT); publicSupportChannelService = new PublicModeratedChannelService(persistenceService, networkService, userIdentityService, - ChatDomain.SUPPORT, - List.of(new PublicModeratedChannel(ChatDomain.SUPPORT, "support"), - new PublicModeratedChannel(ChatDomain.SUPPORT, "questions"), - new PublicModeratedChannel(ChatDomain.SUPPORT, "reports"))); + ChannelDomain.SUPPORT, + List.of(new PublicModeratedChannel(ChannelDomain.SUPPORT, "support"), + new PublicModeratedChannel(ChannelDomain.SUPPORT, "questions"), + new PublicModeratedChannel(ChannelDomain.SUPPORT, "reports"))); supportChannelSelectionService = new SupportChannelSelectionService(persistenceService, privateSupportChannelService, publicSupportChannelService); diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index 4f814cb127..494811d668 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -17,7 +17,6 @@ package bisq.chat.channel; -import bisq.chat.ChatDomain; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.public_moderated.PublicModeratedChannel; import bisq.chat.message.ChatMessage; @@ -40,23 +39,23 @@ @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true) public abstract class Channel implements Proto { - private final ChatDomain chatDomain; + private final ChannelDomain channelDomain; protected final String channelName; @EqualsAndHashCode.Include private transient final String id; protected final Observable channelNotificationType = new Observable<>(); - public Channel(ChatDomain chatDomain, String channelName, ChannelNotificationType channelNotificationType) { - this.chatDomain = chatDomain; + public Channel(ChannelDomain channelDomain, String channelName, ChannelNotificationType channelNotificationType) { + this.channelDomain = channelDomain; this.channelName = channelName; - this.id = chatDomain.name().toLowerCase() + "." + channelName; + this.id = channelDomain.name().toLowerCase() + "." + channelName; this.channelNotificationType.set(channelNotificationType); } public bisq.chat.protobuf.Channel.Builder getChannelBuilder() { return bisq.chat.protobuf.Channel.newBuilder() .setId(id) - .setChatDomain(chatDomain.toProto()) + .setChannelDomain(channelDomain.toProto()) .setChannelNotificationType(channelNotificationType.get().toProto()); } diff --git a/chat/src/main/java/bisq/chat/ChatDomain.java b/chat/src/main/java/bisq/chat/channel/ChannelDomain.java similarity index 70% rename from chat/src/main/java/bisq/chat/ChatDomain.java rename to chat/src/main/java/bisq/chat/channel/ChannelDomain.java index 758fe70396..86f5584af2 100644 --- a/chat/src/main/java/bisq/chat/ChatDomain.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelDomain.java @@ -15,23 +15,23 @@ * along with Bisq. If not, see . */ -package bisq.chat; +package bisq.chat.channel; import bisq.common.proto.ProtoEnum; import bisq.common.util.ProtobufUtils; -public enum ChatDomain implements ProtoEnum { +public enum ChannelDomain implements ProtoEnum { TRADE, DISCUSSION, EVENTS, SUPPORT; @Override - public bisq.chat.protobuf.ChatDomain toProto() { - return bisq.chat.protobuf.ChatDomain.valueOf(name()); + public bisq.chat.protobuf.ChannelDomain toProto() { + return bisq.chat.protobuf.ChannelDomain.valueOf(name()); } - public static ChatDomain fromProto(bisq.chat.protobuf.ChatDomain proto) { - return ProtobufUtils.enumFromProto(ChatDomain.class, proto.name()); + public static ChannelDomain fromProto(bisq.chat.protobuf.ChannelDomain proto) { + return ProtobufUtils.enumFromProto(ChannelDomain.class, proto.name()); } } diff --git a/chat/src/main/java/bisq/chat/channel/ChannelService.java b/chat/src/main/java/bisq/chat/channel/ChannelService.java index 37a42bc8e7..82298cc6e1 100644 --- a/chat/src/main/java/bisq/chat/channel/ChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelService.java @@ -17,7 +17,6 @@ package bisq.chat.channel; -import bisq.chat.ChatDomain; import bisq.chat.message.ChatMessage; import bisq.common.application.Service; import bisq.common.observable.ObservableArray; @@ -34,12 +33,12 @@ public abstract class ChannelService implements Service, PersistenceClient { protected final NetworkService networkService; protected final UserIdentityService userIdentityService; - protected final ChatDomain chatDomain; + protected final ChannelDomain channelDomain; - public ChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChatDomain chatDomain) { + public ChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { this.networkService = networkService; this.userIdentityService = userIdentityService; - this.chatDomain = chatDomain; + this.channelDomain = channelDomain; } public void setNotificationSetting(Channel channel, ChannelNotificationType channelNotificationType) { diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index b49399b4e4..7192c0cd3d 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -17,7 +17,6 @@ package bisq.chat.channel; -import bisq.chat.ChatDomain; import bisq.chat.message.PrivateChatMessage; import bisq.common.data.ByteArray; import bisq.common.data.Pair; @@ -51,12 +50,12 @@ public static String createChannelName(Pair userIds) { // We persist the messages as they are NOT persisted in the P2P data store. protected final ObservableArray chatMessages = new ObservableArray<>(); - public PrivateChannel(ChatDomain chatDomain, + public PrivateChannel(ChannelDomain channelDomain, String channelName, UserIdentity myUserIdentity, List chatMessages, ChannelNotificationType channelNotificationType) { - super(chatDomain, channelName, channelNotificationType); + super(channelDomain, channelName, channelNotificationType); this.myUserIdentity = myUserIdentity; this.chatMessages.addAll(chatMessages); diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index 335373babd..2486216a99 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -17,7 +17,6 @@ package bisq.chat.channel; -import bisq.chat.ChatDomain; import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; @@ -48,8 +47,8 @@ public abstract class PrivateChannelService extends Channel // We do not persist the messages as they are persisted in the P2P data store. protected transient final ObservableArray chatMessages = new ObservableArray<>(); - public PublicChannel(ChatDomain chatDomain, String channelName, ChannelNotificationType channelNotificationType) { - super(chatDomain, channelName, channelNotificationType); + public PublicChannel(ChannelDomain channelDomain, String channelName, ChannelNotificationType channelNotificationType) { + super(channelDomain, channelName, channelNotificationType); } } diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java index 696c2ddb48..a8f0214596 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java @@ -17,7 +17,6 @@ package bisq.chat.channel; -import bisq.chat.ChatDomain; import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.network.NetworkIdWithKeyPair; @@ -37,8 +36,8 @@ public abstract class PublicChannelService, S extends PersistableStore> extends ChannelService implements DataService.Listener { - public PublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChatDomain chatDomain) { - super(networkService, userIdentityService, chatDomain); + public PublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { + super(networkService, userIdentityService, channelDomain); } diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java index b02518b1eb..e855954f28 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java @@ -17,7 +17,7 @@ package bisq.chat.channel.private_two_party; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -38,8 +38,8 @@ public final class PrivateTwoPartyChannel extends PrivateChannel { private final UserProfile peer; - public PrivateTwoPartyChannel(UserProfile peer, UserIdentity myUserIdentity, ChatDomain chatDomain) { - this(chatDomain, + public PrivateTwoPartyChannel(UserProfile peer, UserIdentity myUserIdentity, ChannelDomain channelDomain) { + this(channelDomain, PrivateChannel.createChannelName(new Pair<>(peer.getId(), myUserIdentity.getId())), peer, myUserIdentity, @@ -48,13 +48,13 @@ public PrivateTwoPartyChannel(UserProfile peer, UserIdentity myUserIdentity, Cha ); } - private PrivateTwoPartyChannel(ChatDomain chatDomain, + private PrivateTwoPartyChannel(ChannelDomain channelDomain, String channelName, UserProfile peer, UserIdentity myProfile, List chatMessages, ChannelNotificationType channelNotificationType) { - super(chatDomain, channelName, myProfile, chatMessages, channelNotificationType); + super(channelDomain, channelName, myProfile, chatMessages, channelNotificationType); this.peer = peer; } @@ -73,7 +73,7 @@ public bisq.chat.protobuf.Channel toProto() { public static PrivateTwoPartyChannel fromProto(bisq.chat.protobuf.Channel baseProto, bisq.chat.protobuf.PrivateTwoPartyChannel proto) { return new PrivateTwoPartyChannel( - ChatDomain.fromProto(baseProto.getChatDomain()), + ChannelDomain.fromProto(baseProto.getChannelDomain()), baseProto.getId(), UserProfile.fromProto(proto.getPeer()), UserIdentity.fromProto(proto.getMyUserIdentity()), diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java index c0c1674124..b25287dfd6 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java @@ -17,7 +17,7 @@ package bisq.chat.channel.private_two_party; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; @@ -48,11 +48,11 @@ public PrivateTwoPartyChannelService(PersistenceService persistenceService, NetworkService networkService, UserIdentityService userIdentityService, ProofOfWorkService proofOfWorkService, - ChatDomain chatDomain) { - super(networkService, userIdentityService, proofOfWorkService, chatDomain); + ChannelDomain channelDomain) { + super(networkService, userIdentityService, proofOfWorkService, channelDomain); persistence = persistenceService.getOrCreatePersistence(this, "db", - "Private" + StringUtils.capitalize(chatDomain.name()) + "ChannelStore", + "Private" + StringUtils.capitalize(channelDomain.name()) + "ChannelStore", persistableStore); } @@ -86,7 +86,7 @@ protected PrivateTwoPartyChatMessage createNewPrivateChatMessage(String messageI @Override protected PrivateTwoPartyChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { - return new PrivateTwoPartyChannel(peer, myUserIdentity, chatDomain); + return new PrivateTwoPartyChannel(peer, myUserIdentity, channelDomain); } @Override diff --git a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java index 1569d6bc6f..9e03d747a9 100644 --- a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java +++ b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java @@ -17,7 +17,7 @@ package bisq.chat.channel.public_moderated; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.i18n.Res; @@ -39,17 +39,17 @@ public final class PublicModeratedChannel extends PublicChannel channelModeratorIds; - public PublicModeratedChannel(ChatDomain chatDomain, String channelName) { - this(chatDomain, + public PublicModeratedChannel(ChannelDomain channelDomain, String channelName) { + this(channelDomain, channelName, - Res.get(chatDomain.name().toLowerCase() + "." + channelName + ".name"), - Res.get(chatDomain.name().toLowerCase() + "." + channelName + ".description"), + Res.get(channelDomain.name().toLowerCase() + "." + channelName + ".name"), + Res.get(channelDomain.name().toLowerCase() + "." + channelName + ".description"), "", new ArrayList<>(), ChannelNotificationType.MENTION); } - private PublicModeratedChannel(ChatDomain chatDomain, + private PublicModeratedChannel(ChannelDomain channelDomain, String channelName, String displayName, String description, @@ -57,7 +57,7 @@ private PublicModeratedChannel(ChatDomain chatDomain, List channelModeratorIds, ChannelNotificationType channelNotificationType ) { - super(chatDomain, channelName, channelNotificationType); + super(channelDomain, channelName, channelNotificationType); this.displayName = displayName; this.description = description; @@ -80,7 +80,7 @@ public bisq.chat.protobuf.Channel toProto() { public static PublicModeratedChannel fromProto(bisq.chat.protobuf.Channel baseProto, bisq.chat.protobuf.PublicModeratedChannel proto) { return new PublicModeratedChannel( - ChatDomain.fromProto(baseProto.getChatDomain()), + ChannelDomain.fromProto(baseProto.getChannelDomain()), baseProto.getId(), proto.getChannelName(), proto.getDescription(), diff --git a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java index 8d717bf937..3f2dfe8f11 100644 --- a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java @@ -17,7 +17,7 @@ package bisq.chat.channel.public_moderated; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; @@ -46,9 +46,9 @@ public class PublicModeratedChannelService extends PublicChannelService defaultChannels) { - super(networkService, userIdentityService, chatDomain); + super(networkService, userIdentityService, channelDomain); this.defaultChannels = defaultChannels; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index b2b4ca9c74..b88f69d124 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -17,7 +17,7 @@ package bisq.chat.trade.priv; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; @@ -88,7 +88,7 @@ private PrivateTradeChannel(String channelName, Optional mediator, List chatMessages, ChannelNotificationType channelNotificationType) { - super(ChatDomain.TRADE, channelName, myUserIdentity, chatMessages, channelNotificationType); + super(ChannelDomain.TRADE, channelName, myUserIdentity, chatMessages, channelNotificationType); this.peerOrTrader1 = peerOrTrader1; this.myUserProfileOrTrader2 = myUserProfileOrTrader2; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index b73c9ceec2..a49b3cb37a 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -17,7 +17,7 @@ package bisq.chat.trade.priv; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; @@ -52,7 +52,7 @@ public PrivateTradeChannelService(PersistenceService persistenceService, NetworkService networkService, UserIdentityService userIdentityService, ProofOfWorkService proofOfWorkService) { - super(networkService, userIdentityService, proofOfWorkService, ChatDomain.TRADE); + super(networkService, userIdentityService, proofOfWorkService, ChannelDomain.TRADE); persistence = persistenceService.getOrCreatePersistence(this, persistableStore); } diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index 206ad4308f..d1ba0eb740 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -17,7 +17,7 @@ package bisq.chat.trade.pub; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; import bisq.chat.channel.PublicChannel; import bisq.common.currency.Market; @@ -39,7 +39,7 @@ public PublicTradeChannel(Market market) { } private PublicTradeChannel(String channelName, Market market) { - super(ChatDomain.TRADE, channelName, ChannelNotificationType.MENTION); + super(ChannelDomain.TRADE, channelName, ChannelNotificationType.MENTION); this.market = market; } @@ -85,6 +85,6 @@ private static String getChannelName(Market market) { } public static String getChannelId(Market market) { - return ChatDomain.TRADE.name().toLowerCase() + "." + getChannelName(market); + return ChannelDomain.TRADE.name().toLowerCase() + "." + getChannelName(market); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java index f035b80b90..459d9d2e38 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java @@ -17,7 +17,7 @@ package bisq.chat.trade.pub; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.currency.Market; @@ -53,7 +53,7 @@ public class PublicTradeChannelService extends PublicChannelService ex protected Subscription notificationSettingSubscription; private Subscription searchTextPin; - public ChatController(DefaultApplicationService applicationService, ChatDomain chatDomain, NavigationTarget host) { + public ChatController(DefaultApplicationService applicationService, ChannelDomain channelDomain, NavigationTarget host) { super(host); this.applicationService = applicationService; @@ -76,8 +76,8 @@ public ChatController(DefaultApplicationService applicationService, ChatDomain c userIdentityService = applicationService.getUserService().getUserIdentityService(); userProfileService = applicationService.getUserService().getUserProfileService(); reputationService = applicationService.getUserService().getReputationService(); - privateChannelSelection = new PrivateChannelSelection(applicationService, chatDomain); - chatMessagesComponent = new ChatMessagesComponent(applicationService, chatDomain); + privateChannelSelection = new PrivateChannelSelection(applicationService, channelDomain); + chatMessagesComponent = new ChatMessagesComponent(applicationService, channelDomain); channelSidebar = new ChannelSidebar(applicationService, () -> { onCloseSideBar(); chatMessagesComponent.resetSelectedChatMessage(); @@ -85,13 +85,13 @@ public ChatController(DefaultApplicationService applicationService, ChatDomain c quotedMessageBlock = new QuotedMessageBlock(applicationService); createComponents(); - model = getChatModel(chatDomain); + model = getChatModel(channelDomain); view = getChatView(); } public abstract void createComponents(); - public abstract M getChatModel(ChatDomain chatDomain); + public abstract M getChatModel(ChannelDomain channelDomain); public abstract V getChatView(); @@ -207,7 +207,7 @@ protected void applyPeersIcon(PrivateChannel privateChannel) { } protected void applyDefaultPublicChannelIcon(PublicChannel channel) { - String domain = "-" + channel.getChatDomain().name().toLowerCase() + "-"; + String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; String iconId = "channels" + domain + channel.getId(); model.getChannelIcon().set(BisqIconButton.createIconButton(iconId)); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java index 6868382079..5ee1287c20 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java @@ -244,7 +244,7 @@ public ChannelItem(Channel channel, @Nullable UserIdentityService userIdentit id = channel.getId(); - String domain = "-" + channel.getChatDomain().name().toLowerCase() + "-"; + String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; iconIdSelected = "channels" + domain + channel.getId(); iconIdHover = "channels" + domain + channel.getId() + "-white"; iconId = "channels" + domain + channel.getId() + "-grey"; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index e8e487e937..6fcdee9d99 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -18,8 +18,8 @@ package bisq.desktop.primary.main.content.chat.channels; import bisq.application.DefaultApplicationService; -import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; @@ -67,8 +67,8 @@ public class PrivateChannelSelection extends ChannelSelection { private final Controller controller; - public PrivateChannelSelection(DefaultApplicationService applicationService, ChatDomain chatDomain) { - controller = new Controller(applicationService, chatDomain); + public PrivateChannelSelection(DefaultApplicationService applicationService, ChannelDomain channelDomain) { + controller = new Controller(applicationService, channelDomain); } public Pane getRoot() { @@ -94,7 +94,7 @@ protected static class Controller extends ChannelSelection.Controller { private final UserIdentityService userIdentityService; private Pin inMediationPin; - protected Controller(DefaultApplicationService applicationService, ChatDomain chatDomain) { + protected Controller(DefaultApplicationService applicationService, ChannelDomain channelDomain) { super(applicationService.getChatService()); privateTradeChannelService = chatService.getPrivateTradeChannelService(); @@ -111,7 +111,7 @@ protected Controller(DefaultApplicationService applicationService, ChatDomain ch userIdentityService = applicationService.getUserService().getUserIdentityService(); - model = new Model(chatDomain); + model = new Model(channelDomain); view = new View(model, this); model.filteredList.setPredicate(item -> true); @@ -126,7 +126,7 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - if (model.chatDomain == ChatDomain.TRADE) { + if (model.channelDomain == ChannelDomain.TRADE) { channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateTradeChannelService.getChannels()); @@ -142,7 +142,7 @@ public void onActivate() { inMediationPin = FxBindings.bind(model.mediationActivated).to(((PrivateTradeChannel) channel).getInMediation()); } }); - } else if (model.chatDomain == ChatDomain.DISCUSSION) { + } else if (model.channelDomain == ChannelDomain.DISCUSSION) { channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateDiscussionChannelService.getChannels()); @@ -154,7 +154,7 @@ public void onActivate() { userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); } }); - } else if (model.chatDomain == ChatDomain.EVENTS) { + } else if (model.channelDomain == ChannelDomain.EVENTS) { channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateEventsChannelService.getChannels()); @@ -166,7 +166,7 @@ public void onActivate() { userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); } }); - } else if (model.chatDomain == ChatDomain.SUPPORT) { + } else if (model.channelDomain == ChannelDomain.SUPPORT) { channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateSupportChannelService.getChannels()); @@ -194,13 +194,13 @@ protected void onSelected(ChannelSelection.View.ChannelItem channelItem) { if (channelItem == null) { return; } - if (model.chatDomain == ChatDomain.TRADE) { + if (model.channelDomain == ChannelDomain.TRADE) { tradeChannelSelectionService.selectChannel(channelItem.getChannel()); - } else if (model.chatDomain == ChatDomain.DISCUSSION) { + } else if (model.channelDomain == ChannelDomain.DISCUSSION) { discussionChannelSelectionService.selectChannel(channelItem.getChannel()); - } else if (model.chatDomain == ChatDomain.EVENTS) { + } else if (model.channelDomain == ChannelDomain.EVENTS) { eventsChannelSelectionService.selectChannel(channelItem.getChannel()); - } else if (model.chatDomain == ChatDomain.SUPPORT) { + } else if (model.channelDomain == ChannelDomain.SUPPORT) { supportChannelSelectionService.selectChannel(channelItem.getChannel()); } } @@ -218,7 +218,7 @@ public void onLeaveChannel(PrivateChannel privateChannel) { } public void doLeaveChannel(PrivateChannel privateChannel) { - switch (privateChannel.getChatDomain()) { + switch (privateChannel.getChannelDomain()) { case TRADE -> { privateTradeChannelService.leaveChannel((PrivateTradeChannel) privateChannel); } @@ -241,11 +241,11 @@ public void doLeaveChannel(PrivateChannel privateChannel) { } protected static class Model extends ChannelSelection.Model { - private final ChatDomain chatDomain; + private final ChannelDomain channelDomain; private final BooleanProperty mediationActivated = new SimpleBooleanProperty(); - public Model(ChatDomain chatDomain) { - this.chatDomain = chatDomain; + public Model(ChannelDomain channelDomain) { + this.channelDomain = channelDomain; } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 6af513fa22..3ef79cedf6 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -18,9 +18,9 @@ package bisq.desktop.primary.main.content.components; import bisq.application.DefaultApplicationService; -import bisq.chat.ChatDomain; import bisq.chat.ChatService; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; @@ -74,8 +74,8 @@ public class ChatMessagesComponent { private final Controller controller; - public ChatMessagesComponent(DefaultApplicationService applicationService, ChatDomain chatDomain) { - controller = new Controller(applicationService, chatDomain); + public ChatMessagesComponent(DefaultApplicationService applicationService, ChannelDomain channelDomain) { + controller = new Controller(applicationService, channelDomain); } public Pane getRoot() { @@ -136,7 +136,7 @@ private static class Controller implements bisq.desktop.common.view.Controller { private Pin chatMessagesPin; private Controller(DefaultApplicationService applicationService, - ChatDomain chatDomain) { + ChannelDomain channelDomain) { ChatService chatService = applicationService.getChatService(); publicTradeChannelService = chatService.getPublicTradeChannelService(); privateTradeChannelService = chatService.getPrivateTradeChannelService(); @@ -164,9 +164,9 @@ private Controller(DefaultApplicationService applicationService, this::mentionUser, this::showChatUserDetails, this::onReply, - chatDomain); + channelDomain); - model = new Model(chatDomain); + model = new Model(channelDomain); view = new View(model, this, chatMessagesListView.getRoot(), quotedMessageBlock.getRoot(), @@ -178,13 +178,13 @@ public void onActivate() { model.mentionableUsers.setAll(userProfileService.getUserProfiles()); model.mentionableChannels.setAll(publicDiscussionChannelService.getMentionableChannels()); - if (model.getChatDomain() == ChatDomain.TRADE) { + if (model.getChannelDomain() == ChannelDomain.TRADE) { selectedChannelPin = tradeChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); - } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { + } else if (model.getChannelDomain() == ChannelDomain.DISCUSSION) { selectedChannelPin = discussionChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); - } else if (model.getChatDomain() == ChatDomain.EVENTS) { + } else if (model.getChannelDomain() == ChannelDomain.EVENTS) { selectedChannelPin = eventsChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); - } else if (model.getChatDomain() == ChatDomain.SUPPORT) { + } else if (model.getChannelDomain() == ChannelDomain.SUPPORT) { selectedChannelPin = supportChannelSelectionService.getSelectedChannel().addObserver(this::applySelectedChannel); } @@ -253,7 +253,7 @@ private void doSendMessage(String text) { new Popup().information(Res.get("social.chat.sendMsg.tradeRulesNotConfirmed.popup")).show(); } } else if (channel instanceof PublicModeratedChannel) { - switch (channel.getChatDomain()) { + switch (channel.getChannelDomain()) { case TRADE -> { } case DISCUSSION -> { @@ -268,7 +268,7 @@ private void doSendMessage(String text) { } } else if (channel instanceof PrivateTwoPartyChannel) { - switch (channel.getChatDomain()) { + switch (channel.getChannelDomain()) { case TRADE -> { } case DISCUSSION -> { @@ -306,16 +306,16 @@ private void fillChannelMention(Channel channel) { } private void createAndSelectPrivateChannel(UserProfile peer) { - if (model.getChatDomain() == ChatDomain.TRADE) { + if (model.getChannelDomain() == ChannelDomain.TRADE) { privateTradeChannelService.maybeCreateAndAddChannel(peer) .ifPresent(tradeChannelSelectionService::selectChannel); - } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { + } else if (model.getChannelDomain() == ChannelDomain.DISCUSSION) { privateDiscussionChannelService.maybeCreateAndAddChannel(peer) .ifPresent(discussionChannelSelectionService::selectChannel); - } else if (model.getChatDomain() == ChatDomain.EVENTS) { + } else if (model.getChannelDomain() == ChannelDomain.EVENTS) { privateEventsChannelService.maybeCreateAndAddChannel(peer) .ifPresent(eventsChannelSelectionService::selectChannel); - } else if (model.getChatDomain() == ChatDomain.SUPPORT) { + } else if (model.getChannelDomain() == ChannelDomain.SUPPORT) { privateSupportChannelService.maybeCreateAndAddChannel(peer) .ifPresent(supportChannelSelectionService::selectChannel); } @@ -383,13 +383,13 @@ private static class Model implements bisq.desktop.common.view.Model { private final ObjectProperty moreOptionsVisibleMessage = new SimpleObjectProperty<>(null); private final ObservableList mentionableUsers = FXCollections.observableArrayList(); private final ObservableList> mentionableChannels = FXCollections.observableArrayList(); - private final ChatDomain chatDomain; + private final ChannelDomain channelDomain; @Nullable private ChatMessage selectedChatMessage; private Optional> showChatUserDetailsHandler = Optional.empty(); - private Model(ChatDomain chatDomain) { - this.chatDomain = chatDomain; + private Model(ChannelDomain channelDomain) { + this.channelDomain = channelDomain; } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 8858b50dce..a008f14efe 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -18,9 +18,9 @@ package bisq.desktop.primary.main.content.components; import bisq.application.DefaultApplicationService; -import bisq.chat.ChatDomain; import bisq.chat.ChatService; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; @@ -107,12 +107,12 @@ public ChatMessagesListView(DefaultApplicationService applicationService, Consumer mentionUserHandler, Consumer showChatUserDetailsHandler, Consumer replyHandler, - ChatDomain chatDomain) { + ChannelDomain channelDomain) { controller = new Controller(applicationService, mentionUserHandler, showChatUserDetailsHandler, replyHandler, - chatDomain); + channelDomain); } public Pane getRoot() { @@ -183,7 +183,7 @@ private Controller(DefaultApplicationService applicationService, Consumer mentionUserHandler, Consumer showChatUserDetailsHandler, Consumer replyHandler, - ChatDomain chatDomain) { + ChannelDomain channelDomain) { chatService = applicationService.getChatService(); privateTradeChannelService = chatService.getPrivateTradeChannelService(); @@ -213,7 +213,7 @@ private Controller(DefaultApplicationService applicationService, model = new Model(chatService, userIdentityService, - chatDomain); + channelDomain); view = new View(model, this); } @@ -231,7 +231,7 @@ public void onActivate() { model.getSortedChatMessages().setComparator(ChatMessagesListView.ChatMessageListItem::compareTo); - if (model.getChatDomain() == ChatDomain.TRADE) { + if (model.getChannelDomain() == ChannelDomain.TRADE) { selectedChannelPin = tradeChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (chatMessagesPin != null) { @@ -254,7 +254,7 @@ public void onActivate() { model.chatMessages.clear(); } }); - } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { + } else if (model.getChannelDomain() == ChannelDomain.DISCUSSION) { selectedChannelPin = discussionChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (channel instanceof PublicModeratedChannel) { @@ -275,7 +275,7 @@ public void onActivate() { model.allowEditing.set(false); } }); - } else if (model.getChatDomain() == ChatDomain.EVENTS) { + } else if (model.getChannelDomain() == ChannelDomain.EVENTS) { selectedChannelPin = eventsChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (channel instanceof PublicModeratedChannel) { @@ -296,7 +296,7 @@ public void onActivate() { model.allowEditing.set(false); } }); - } else if (model.getChatDomain() == ChatDomain.SUPPORT) { + } else if (model.getChannelDomain() == ChannelDomain.SUPPORT) { selectedChannelPin = supportChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); if (channel instanceof PublicModeratedChannel) { @@ -491,14 +491,14 @@ private boolean isMyMessage(ChatMessage chatMessage) { } private void createAndSelectPrivateChannel(UserProfile peer) { - if (model.getChatDomain() == ChatDomain.TRADE) { + if (model.getChannelDomain() == ChannelDomain.TRADE) { PrivateTradeChannel privateTradeChannel = getPrivateTradeChannel(peer); tradeChannelSelectionService.selectChannel(privateTradeChannel); - } else if (model.getChatDomain() == ChatDomain.DISCUSSION) { + } else if (model.getChannelDomain() == ChannelDomain.DISCUSSION) { privateDiscussionChannelService.maybeCreateAndAddChannel(peer).ifPresent(discussionChannelSelectionService::selectChannel); - } else if (model.getChatDomain() == ChatDomain.EVENTS) { + } else if (model.getChannelDomain() == ChannelDomain.EVENTS) { privateEventsChannelService.maybeCreateAndAddChannel(peer).ifPresent(eventsChannelSelectionService::selectChannel); - } else if (model.getChatDomain() == ChatDomain.SUPPORT) { + } else if (model.getChannelDomain() == ChannelDomain.SUPPORT) { privateSupportChannelService.maybeCreateAndAddChannel(peer).ifPresent(supportChannelSelectionService::selectChannel); } } @@ -542,7 +542,7 @@ private static class Model implements bisq.desktop.common.view.Model { private final SortedList> sortedChatMessages = new SortedList<>(filteredChatMessages); private final BooleanProperty allowEditing = new SimpleBooleanProperty(); private final ObjectProperty selectedChatMessageForMoreOptionsPopup = new SimpleObjectProperty<>(null); - private final ChatDomain chatDomain; + private final ChannelDomain channelDomain; @Setter private Predicate> searchPredicate = e -> true; private Optional createOfferCompleteHandler = Optional.empty(); @@ -551,10 +551,10 @@ private static class Model implements bisq.desktop.common.view.Model { private Model(ChatService chatService, UserIdentityService userIdentityService, - ChatDomain chatDomain) { + ChannelDomain channelDomain) { this.chatService = chatService; this.userIdentityService = userIdentityService; - this.chatDomain = chatDomain; + this.channelDomain = channelDomain; } boolean isMyMessage(ChatMessage chatMessage) { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index d95d816d86..3565853ac2 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -18,8 +18,8 @@ package bisq.desktop.primary.main.content.discussion; import bisq.application.DefaultApplicationService; -import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; @@ -42,7 +42,7 @@ public class DiscussionsController extends ChatController im private PublicEventsChannelSelection publicEventsChannelSelection; public EventsController(DefaultApplicationService applicationService) { - super(applicationService, ChatDomain.EVENTS, NavigationTarget.NONE); + super(applicationService, ChannelDomain.EVENTS, NavigationTarget.NONE); publicEventsChannelService = chatService.getPublicEventsChannelService(); eventsChannelSelectionService = chatService.getEventsChannelSelectionService(); @@ -69,8 +69,8 @@ public void createComponents() { } @Override - public EventsModel getChatModel(ChatDomain chatDomain) { - return new EventsModel(chatDomain); + public EventsModel getChatModel(ChannelDomain channelDomain) { + return new EventsModel(channelDomain); } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java index e1704f3c65..b67ec3381d 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsModel.java @@ -17,7 +17,7 @@ package bisq.desktop.primary.main.content.events; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatModel; import lombok.Getter; @@ -26,10 +26,10 @@ @Slf4j @Getter public class EventsModel extends ChatModel { - private final ChatDomain chatDomain; + private final ChannelDomain channelDomain; - public EventsModel(ChatDomain chatDomain) { - this.chatDomain = chatDomain; + public EventsModel(ChannelDomain channelDomain) { + this.channelDomain = channelDomain; } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index a9b64e074b..3288d9be36 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -18,8 +18,8 @@ package bisq.desktop.primary.main.content.support; import bisq.application.DefaultApplicationService; -import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PrivateChannel; import bisq.chat.channel.PublicChannel; import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; @@ -42,7 +42,7 @@ public class SupportController extends ChatController private PublicSupportChannelSelection publicSupportChannelSelection; public SupportController(DefaultApplicationService applicationService) { - super(applicationService, ChatDomain.SUPPORT, NavigationTarget.NONE); + super(applicationService, ChannelDomain.SUPPORT, NavigationTarget.NONE); publicSupportChannelService = chatService.getPublicSupportChannelService(); supportChannelSelectionService = chatService.getSupportChannelSelectionService(); @@ -69,8 +69,8 @@ public void createComponents() { } @Override - public SupportModel getChatModel(ChatDomain chatDomain) { - return new SupportModel(chatDomain); + public SupportModel getChatModel(ChannelDomain channelDomain) { + return new SupportModel(channelDomain); } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java index 2215f3ff16..6ec21731a4 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportModel.java @@ -17,7 +17,7 @@ package bisq.desktop.primary.main.content.support; -import bisq.chat.ChatDomain; +import bisq.chat.channel.ChannelDomain; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatModel; import lombok.Getter; @@ -26,10 +26,10 @@ @Slf4j @Getter public class SupportModel extends ChatModel { - private final ChatDomain chatDomain; + private final ChannelDomain channelDomain; - public SupportModel(ChatDomain chatDomain) { - this.chatDomain = chatDomain; + public SupportModel(ChannelDomain channelDomain) { + this.channelDomain = channelDomain; } @Override diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java index 82dfb307ff..6b6084991b 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java @@ -18,8 +18,8 @@ package bisq.desktop.primary.main.content.trade.bisqEasy.chat; import bisq.application.DefaultApplicationService; -import bisq.chat.ChatDomain; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.message.ChatMessage; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; @@ -58,7 +58,7 @@ public class BisqEasyChatController extends ChatController Date: Fri, 23 Dec 2022 14:23:25 -0500 Subject: [PATCH 08/15] Refactor: remove packages, move message class --- chat/src/main/java/bisq/chat/ChatService.java | 6 +++--- chat/src/main/java/bisq/chat/channel/Channel.java | 2 -- .../PrivateTwoPartyChannel.java | 6 ++---- .../PrivateTwoPartyChannelService.java | 5 ++--- .../PrivateTwoPartyChannelStore.java | 2 +- .../PublicModeratedChannel.java | 6 ++---- .../PublicModeratedChannelService.java | 5 ++--- .../PublicModeratedChannelStore.java | 2 +- .../discuss/DiscussionChannelSelectionService.java | 6 +++--- .../chat/events/EventsChannelSelectionService.java | 6 +++--- .../main/java/bisq/chat/message/ChatMessage.java | 2 -- .../PrivateTwoPartyChatMessage.java | 6 +----- .../PublicModeratedChatMessage.java | 6 +----- .../support/SupportChannelSelectionService.java | 6 +++--- .../chat/channels/PrivateChannelSelection.java | 6 +----- .../channels/PublicDiscussionChannelSelection.java | 4 ++-- .../chat/channels/PublicEventsChannelSelection.java | 4 ++-- .../channels/PublicSupportChannelSelection.java | 4 ++-- .../main/content/chat/sidebar/ChannelSidebar.java | 2 +- .../content/components/ChatMessagesComponent.java | 8 +------- .../content/components/ChatMessagesListView.java | 13 ++----------- .../content/discussion/DiscussionsController.java | 7 +------ .../main/content/events/EventsController.java | 7 +------ .../main/content/support/SupportController.java | 7 +------ .../restApi/dto/PublicDiscussionChannelDto.java | 2 +- 25 files changed, 39 insertions(+), 91 deletions(-) rename chat/src/main/java/bisq/chat/channel/{private_two_party => }/PrivateTwoPartyChannel.java (95%) rename chat/src/main/java/bisq/chat/channel/{private_two_party => }/PrivateTwoPartyChannelService.java (96%) rename chat/src/main/java/bisq/chat/channel/{private_two_party => }/PrivateTwoPartyChannelStore.java (98%) rename chat/src/main/java/bisq/chat/channel/{public_moderated => }/PublicModeratedChannel.java (96%) rename chat/src/main/java/bisq/chat/channel/{public_moderated => }/PublicModeratedChannelService.java (97%) rename chat/src/main/java/bisq/chat/channel/{public_moderated => }/PublicModeratedChannelStore.java (98%) rename chat/src/main/java/bisq/chat/{channel/private_two_party => message}/PrivateTwoPartyChatMessage.java (95%) rename chat/src/main/java/bisq/chat/{channel/public_moderated => message}/PublicModeratedChatMessage.java (94%) diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 774820f9e0..0c9147c607 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -18,9 +18,9 @@ package bisq.chat; import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PrivateTwoPartyChannelService; +import bisq.chat.channel.PublicModeratedChannel; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.support.SupportChannelSelectionService; diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index 494811d668..4bc2f71381 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -17,8 +17,6 @@ package bisq.chat.channel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; import bisq.chat.trade.priv.PrivateTradeChannel; diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java similarity index 95% rename from chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java rename to chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java index e855954f28..47a901907b 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java @@ -15,11 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.private_two_party; +package bisq.chat.channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PrivateChannel; +import bisq.chat.message.PrivateTwoPartyChatMessage; import bisq.common.data.Pair; import bisq.user.identity.UserIdentity; import bisq.user.profile.UserProfile; diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java similarity index 96% rename from chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java rename to chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java index b25287dfd6..dec2a3818b 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java @@ -15,11 +15,10 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.private_two_party; +package bisq.chat.channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.MessageType; +import bisq.chat.message.PrivateTwoPartyChatMessage; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; import bisq.common.util.StringUtils; diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelStore.java b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelStore.java similarity index 98% rename from chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelStore.java rename to chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelStore.java index 97f55d70c4..969423c3a6 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelStore.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.private_two_party; +package bisq.chat.channel; import bisq.common.observable.ObservableArray; import bisq.common.proto.ProtoResolver; diff --git a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java similarity index 96% rename from chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java rename to chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java index 9e03d747a9..88357c476f 100644 --- a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java @@ -15,11 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.public_moderated; +package bisq.chat.channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PublicChannel; +import bisq.chat.message.PublicModeratedChatMessage; import bisq.i18n.Res; import lombok.EqualsAndHashCode; import lombok.Getter; diff --git a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java similarity index 97% rename from chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java rename to chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java index 3f2dfe8f11..a22465f170 100644 --- a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java @@ -15,10 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.public_moderated; +package bisq.chat.channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PublicChannelService; +import bisq.chat.message.PublicModeratedChatMessage; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; import bisq.network.NetworkService; diff --git a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelStore.java b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelStore.java similarity index 98% rename from chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelStore.java rename to chat/src/main/java/bisq/chat/channel/PublicModeratedChannelStore.java index 52e60d0d19..f0d9c4d69e 100644 --- a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelStore.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.public_moderated; +package bisq.chat.channel; import bisq.common.observable.ObservableArray; import bisq.common.proto.ProtoResolver; diff --git a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java index 25641fc529..30e8b6ea54 100644 --- a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java @@ -18,9 +18,9 @@ package bisq.chat.discuss; import bisq.chat.channel.Channel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PrivateTwoPartyChannel; +import bisq.chat.channel.PrivateTwoPartyChannelService; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; diff --git a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java index 97c91fc649..e7538178b3 100644 --- a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java @@ -18,9 +18,9 @@ package bisq.chat.events; import bisq.chat.channel.Channel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PrivateTwoPartyChannel; +import bisq.chat.channel.PrivateTwoPartyChannelService; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 2c518c3b87..ebee6d26eb 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -17,8 +17,6 @@ package bisq.chat.message; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; -import bisq.chat.channel.public_moderated.PublicModeratedChatMessage; import bisq.chat.trade.priv.PrivateTradeChatMessage; import bisq.chat.trade.pub.PublicTradeChatMessage; import bisq.common.proto.Proto; diff --git a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChatMessage.java b/chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java similarity index 95% rename from chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChatMessage.java rename to chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java index 64a2952b78..b5436776b1 100644 --- a/chat/src/main/java/bisq/chat/channel/private_two_party/PrivateTwoPartyChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java @@ -15,12 +15,8 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.private_two_party; +package bisq.chat.message; -import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; -import bisq.chat.message.PrivateChatMessage; -import bisq.chat.message.Quotation; import bisq.network.p2p.services.data.storage.MetaData; import bisq.network.protobuf.ExternalNetworkMessage; import bisq.network.protobuf.NetworkMessage; diff --git a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChatMessage.java b/chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java similarity index 94% rename from chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChatMessage.java rename to chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java index c2efce2fc9..7e5ea4e04f 100644 --- a/chat/src/main/java/bisq/chat/channel/public_moderated/PublicModeratedChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java @@ -15,12 +15,8 @@ * along with Bisq. If not, see . */ -package bisq.chat.channel.public_moderated; +package bisq.chat.message; -import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; -import bisq.chat.message.PublicChatMessage; -import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; import bisq.network.p2p.services.data.storage.MetaData; import lombok.EqualsAndHashCode; diff --git a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java index d64a3cdb6e..714dae043f 100644 --- a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java @@ -18,9 +18,9 @@ package bisq.chat.support; import bisq.chat.channel.Channel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PrivateTwoPartyChannel; +import bisq.chat.channel.PrivateTwoPartyChannelService; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.persistence.Persistence; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index 6fcdee9d99..e447b5e7d9 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -18,11 +18,7 @@ package bisq.desktop.primary.main.content.chat.channels; import bisq.application.DefaultApplicationService; -import bisq.chat.channel.Channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; +import bisq.chat.channel.*; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.support.SupportChannelSelectionService; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java index 1467447e33..900a92a711 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java @@ -19,8 +19,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PublicModeratedChannel; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java index f72b5ed319..0bb838c9f6 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java @@ -19,8 +19,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PublicModeratedChannel; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java index 1d5a1b8fcc..289242d8a4 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java @@ -19,8 +19,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.PublicModeratedChannel; +import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.support.SupportChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index fdc096d1b9..e4973db029 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -20,7 +20,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.PublicModeratedChannel; import bisq.chat.message.ChatMessage; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.desktop.components.containers.Spacer; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 3ef79cedf6..eeb65ec723 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -19,13 +19,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.Channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PublicChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.*; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index a008f14efe..25b35b5ca3 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -19,19 +19,10 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.Channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannelService; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChatMessage; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; -import bisq.chat.channel.public_moderated.PublicModeratedChatMessage; +import bisq.chat.channel.*; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.message.ChatMessage; -import bisq.chat.message.PublicChatMessage; -import bisq.chat.message.Quotation; +import bisq.chat.message.*; import bisq.chat.support.SupportChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index 3565853ac2..dca5cca9c0 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -18,12 +18,7 @@ package bisq.desktop.primary.main.content.discussion; import bisq.application.DefaultApplicationService; -import bisq.chat.channel.Channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannel; -import bisq.chat.channel.PublicChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.*; import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index c8842b4390..b049b2c67e 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -18,12 +18,7 @@ package bisq.desktop.primary.main.content.events; import bisq.application.DefaultApplicationService; -import bisq.chat.channel.Channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannel; -import bisq.chat.channel.PublicChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.*; import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index 3288d9be36..f85fb206c8 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -18,12 +18,7 @@ package bisq.desktop.primary.main.content.support; import bisq.application.DefaultApplicationService; -import bisq.chat.channel.Channel; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannel; -import bisq.chat.channel.PublicChannel; -import bisq.chat.channel.private_two_party.PrivateTwoPartyChannel; -import bisq.chat.channel.public_moderated.PublicModeratedChannelService; +import bisq.chat.channel.*; import bisq.chat.message.ChatMessage; import bisq.chat.support.SupportChannelSelectionService; import bisq.desktop.common.view.Controller; diff --git a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java index 9864982a8a..4069201644 100644 --- a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java +++ b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java @@ -1,6 +1,6 @@ package bisq.restApi.dto; -import bisq.chat.channel.public_moderated.PublicModeratedChannel; +import bisq.chat.channel.PublicModeratedChannel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; From e4d17afee1b42990a1e732cf2170b15e114b7e1a Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 17:03:07 -0500 Subject: [PATCH 09/15] Refactor: rename PublicChannel to BasePublicChannel --- .../channel/{PublicChannel.java => BasePublicChannel.java} | 6 +++--- .../main/java/bisq/chat/channel/PublicChannelService.java | 2 +- .../main/java/bisq/chat/channel/PublicModeratedChannel.java | 2 +- .../main/java/bisq/chat/trade/pub/PublicTradeChannel.java | 4 ++-- .../desktop/primary/main/content/chat/ChatController.java | 4 ++-- .../main/content/components/ChatMessagesComponent.java | 4 ++-- .../main/content/discussion/DiscussionsController.java | 2 +- .../primary/main/content/events/EventsController.java | 2 +- .../primary/main/content/support/SupportController.java | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) rename chat/src/main/java/bisq/chat/channel/{PublicChannel.java => BasePublicChannel.java} (78%) diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannel.java b/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java similarity index 78% rename from chat/src/main/java/bisq/chat/channel/PublicChannel.java rename to chat/src/main/java/bisq/chat/channel/BasePublicChannel.java index a5b0663b78..2cb24d8b83 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java @@ -26,11 +26,11 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public abstract class PublicChannel extends Channel { - // We do not persist the messages as they are persisted in the P2P data store. +public abstract class BasePublicChannel extends Channel { + // Transient because we do not persist the messages as they are persisted in the P2P data store. protected transient final ObservableArray chatMessages = new ObservableArray<>(); - public PublicChannel(ChannelDomain channelDomain, String channelName, ChannelNotificationType channelNotificationType) { + public BasePublicChannel(ChannelDomain channelDomain, String channelName, ChannelNotificationType channelNotificationType) { super(channelDomain, channelName, channelNotificationType); } } diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java index a8f0214596..f956ba265b 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java @@ -33,7 +33,7 @@ import java.util.concurrent.CompletableFuture; @Slf4j -public abstract class PublicChannelService, S extends PersistableStore> +public abstract class PublicChannelService, S extends PersistableStore> extends ChannelService implements DataService.Listener { public PublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { diff --git a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java index 88357c476f..b99e5d9a94 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java @@ -31,7 +31,7 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PublicModeratedChannel extends PublicChannel { +public final class PublicModeratedChannel extends BasePublicChannel { private final String displayName; private final String description; private final String channelAdminId; diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index d1ba0eb740..490dd3bb76 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -17,9 +17,9 @@ package bisq.chat.trade.pub; +import bisq.chat.channel.BasePublicChannel; import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PublicChannel; import bisq.common.currency.Market; import bisq.i18n.Res; import lombok.EqualsAndHashCode; @@ -31,7 +31,7 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PublicTradeChannel extends PublicChannel { +public final class PublicTradeChannel extends BasePublicChannel { private final Market market; public PublicTradeChannel(Market market) { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java index 7699d04482..d16beeb830 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java @@ -19,10 +19,10 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; +import bisq.chat.channel.BasePublicChannel; import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PrivateChannel; -import bisq.chat.channel.PublicChannel; import bisq.chat.message.ChatMessage; import bisq.common.observable.Pin; import bisq.desktop.common.threading.UIThread; @@ -206,7 +206,7 @@ protected void applyPeersIcon(PrivateChannel privateChannel) { model.getChannelIcon().set(imageView); } - protected void applyDefaultPublicChannelIcon(PublicChannel channel) { + protected void applyDefaultPublicChannelIcon(BasePublicChannel channel) { String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; String iconId = "channels" + domain + channel.getId(); model.getChannelIcon().set(BisqIconButton.createIconButton(iconId)); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index eeb65ec723..3de7a15978 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -206,7 +206,7 @@ private void onSendMessage(String text) { return; } - if (model.selectedChannel.get() instanceof PublicChannel) { + if (model.selectedChannel.get() instanceof BasePublicChannel) { List myUserProfilesInChannel = getMyUserProfilesInChannel(); if (myUserProfilesInChannel.size() > 0) { UserIdentity lastUsedUserProfile = myUserProfilesInChannel.get(0); @@ -337,7 +337,7 @@ private void applySelectedChannel(Channel channel) { private void applyUserProfileOrChannelChange() { boolean multipleProfiles = userIdentityService.getUserIdentities().size() > 1; Channel selectedChannel = model.selectedChannel.get(); - model.userProfileSelectionVisible.set(multipleProfiles && selectedChannel instanceof PublicChannel); + model.userProfileSelectionVisible.set(multipleProfiles && selectedChannel instanceof BasePublicChannel); if (chatMessagesPin != null) { chatMessagesPin.unbind(); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index dca5cca9c0..db49d34cb3 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -86,7 +86,7 @@ protected void handleChannelChange(Channel channel) { applyPeersIcon((PrivateChannel) channel); publicDiscussionChannelSelection.deSelectChannel(); } else { - applyDefaultPublicChannelIcon((PublicChannel) channel); + applyDefaultPublicChannelIcon((BasePublicChannel) channel); privateChannelSelection.deSelectChannel(); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index b049b2c67e..87ea1c867e 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -86,7 +86,7 @@ protected void handleChannelChange(Channel channel) { applyPeersIcon((PrivateChannel) channel); publicEventsChannelSelection.deSelectChannel(); } else { - applyDefaultPublicChannelIcon((PublicChannel) channel); + applyDefaultPublicChannelIcon((BasePublicChannel) channel); privateChannelSelection.deSelectChannel(); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index f85fb206c8..18e76e5ae4 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -86,7 +86,7 @@ protected void handleChannelChange(Channel channel) { applyPeersIcon((PrivateChannel) channel); publicSupportChannelSelection.deSelectChannel(); } else { - applyDefaultPublicChannelIcon((PublicChannel) channel); + applyDefaultPublicChannelIcon((BasePublicChannel) channel); privateChannelSelection.deSelectChannel(); } } From 35465a9517594941e82cb577844fee2cc748c534 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 17:20:37 -0500 Subject: [PATCH 10/15] Various refactorings --- chat/src/main/java/bisq/chat/ChatService.java | 69 ++++---- .../bisq/chat/channel/BasePublicChannel.java | 4 +- .../channel/BasePublicChannelService.java | 142 ++++++++++++++++ .../main/java/bisq/chat/channel/Channel.java | 4 +- .../ChannelSelectionService.java} | 27 ++-- .../ChannelSelectionStore.java} | 25 ++- ...deratedChannel.java => PublicChannel.java} | 34 ++-- .../chat/channel/PublicChannelService.java | 152 ++++++++---------- ...nnelStore.java => PublicChannelStore.java} | 32 ++-- .../PublicModeratedChannelService.java | 122 -------------- .../DiscussionChannelSelectionService.java | 86 ---------- .../DiscussionChannelSelectionStore.java | 76 --------- .../chat/message/BasePublicChatMessage.java | 55 +++++++ .../java/bisq/chat/message/ChatMessage.java | 8 +- .../bisq/chat/message/PublicChatMessage.java | 81 +++++++--- .../message/PublicModeratedChatMessage.java | 88 ---------- .../SupportChannelSelectionService.java | 86 ---------- .../support/SupportChannelSelectionStore.java | 76 --------- .../trade/pub/PublicTradeChannelService.java | 4 +- .../trade/pub/PublicTradeChatMessage.java | 4 +- chat/src/main/proto/chat.proto | 18 ++- .../channels/PrivateChannelSelection.java | 9 +- .../PublicDiscussionChannelSelection.java | 16 +- .../PublicEventsChannelSelection.java | 16 +- .../PublicSupportChannelSelection.java | 16 +- .../content/chat/sidebar/ChannelSidebar.java | 6 +- .../components/ChatMessagesComponent.java | 23 ++- .../components/ChatMessagesListView.java | 51 +++--- .../discussion/DiscussionsController.java | 5 +- .../main/content/events/EventsController.java | 5 +- .../content/support/SupportController.java | 5 +- .../dto/PublicDiscussionChannelDto.java | 4 +- 32 files changed, 506 insertions(+), 843 deletions(-) create mode 100644 chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java rename chat/src/main/java/bisq/chat/{events/EventsChannelSelectionService.java => channel/ChannelSelectionService.java} (74%) rename chat/src/main/java/bisq/chat/{events/EventsChannelSelectionStore.java => channel/ChannelSelectionStore.java} (63%) rename chat/src/main/java/bisq/chat/channel/{PublicModeratedChannel.java => PublicChannel.java} (70%) rename chat/src/main/java/bisq/chat/channel/{PublicModeratedChannelStore.java => PublicChannelStore.java} (56%) delete mode 100644 chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java delete mode 100644 chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java delete mode 100644 chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionStore.java create mode 100644 chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java delete mode 100644 chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java delete mode 100644 chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java delete mode 100644 chat/src/main/java/bisq/chat/support/SupportChannelSelectionStore.java diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 0c9147c607..05d79b8d83 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -17,13 +17,7 @@ package bisq.chat; -import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateTwoPartyChannelService; -import bisq.chat.channel.PublicModeratedChannel; -import bisq.chat.channel.PublicModeratedChannelService; -import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.support.SupportChannelSelectionService; +import bisq.chat.channel.*; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannelService; import bisq.chat.trade.pub.PublicTradeChannelService; @@ -46,15 +40,15 @@ public class ChatService implements Service { private final PrivateTradeChannelService privateTradeChannelService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; - private final PublicModeratedChannelService publicDiscussionChannelService; + private final PublicChannelService publicDiscussionChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final DiscussionChannelSelectionService discussionChannelSelectionService; + private final ChannelSelectionService discussionChannelSelectionService; private final PrivateTwoPartyChannelService privateSupportChannelService; - private final PublicModeratedChannelService publicSupportChannelService; - private final SupportChannelSelectionService supportChannelSelectionService; + private final PublicChannelService publicSupportChannelService; + private final ChannelSelectionService supportChannelSelectionService; private final PrivateTwoPartyChannelService privateEventsChannelService; - private final PublicModeratedChannelService publicEventsChannelService; - private final EventsChannelSelectionService eventsChannelSelectionService; + private final PublicChannelService publicEventsChannelService; + private final ChannelSelectionService eventsChannelSelectionService; public ChatService(PersistenceService persistenceService, ProofOfWorkService proofOfWorkService, @@ -79,19 +73,20 @@ public ChatService(PersistenceService persistenceService, userIdentityService, proofOfWorkService, ChannelDomain.DISCUSSION); - publicDiscussionChannelService = new PublicModeratedChannelService(persistenceService, + publicDiscussionChannelService = new PublicChannelService(persistenceService, networkService, userIdentityService, ChannelDomain.DISCUSSION, - List.of(new PublicModeratedChannel(ChannelDomain.DISCUSSION, "bisq"), - new PublicModeratedChannel(ChannelDomain.DISCUSSION, "bitcoin"), - new PublicModeratedChannel(ChannelDomain.DISCUSSION, "markets"), - new PublicModeratedChannel(ChannelDomain.DISCUSSION, "economy"), - new PublicModeratedChannel(ChannelDomain.DISCUSSION, "offTopic"))); + List.of(new PublicChannel(ChannelDomain.DISCUSSION, "bisq"), + new PublicChannel(ChannelDomain.DISCUSSION, "bitcoin"), + new PublicChannel(ChannelDomain.DISCUSSION, "markets"), + new PublicChannel(ChannelDomain.DISCUSSION, "economy"), + new PublicChannel(ChannelDomain.DISCUSSION, "offTopic"))); - discussionChannelSelectionService = new DiscussionChannelSelectionService(persistenceService, + discussionChannelSelectionService = new ChannelSelectionService(persistenceService, privateDiscussionChannelService, - publicDiscussionChannelService); + publicDiscussionChannelService, + ChannelDomain.DISCUSSION); // Events privateEventsChannelService = new PrivateTwoPartyChannelService(persistenceService, @@ -99,19 +94,20 @@ public ChatService(PersistenceService persistenceService, userIdentityService, proofOfWorkService, ChannelDomain.EVENTS); - publicEventsChannelService = new PublicModeratedChannelService(persistenceService, + publicEventsChannelService = new PublicChannelService(persistenceService, networkService, userIdentityService, ChannelDomain.EVENTS, - List.of(new PublicModeratedChannel(ChannelDomain.EVENTS, "conferences"), - new PublicModeratedChannel(ChannelDomain.EVENTS, "meetups"), - new PublicModeratedChannel(ChannelDomain.EVENTS, "podcasts"), - new PublicModeratedChannel(ChannelDomain.EVENTS, "noKyc"), - new PublicModeratedChannel(ChannelDomain.EVENTS, "nodes"), - new PublicModeratedChannel(ChannelDomain.EVENTS, "tradeEvents"))); - eventsChannelSelectionService = new EventsChannelSelectionService(persistenceService, + List.of(new PublicChannel(ChannelDomain.EVENTS, "conferences"), + new PublicChannel(ChannelDomain.EVENTS, "meetups"), + new PublicChannel(ChannelDomain.EVENTS, "podcasts"), + new PublicChannel(ChannelDomain.EVENTS, "noKyc"), + new PublicChannel(ChannelDomain.EVENTS, "nodes"), + new PublicChannel(ChannelDomain.EVENTS, "tradeEvents"))); + eventsChannelSelectionService = new ChannelSelectionService(persistenceService, privateEventsChannelService, - publicEventsChannelService); + publicEventsChannelService, + ChannelDomain.EVENTS); // Support privateSupportChannelService = new PrivateTwoPartyChannelService(persistenceService, @@ -119,16 +115,17 @@ public ChatService(PersistenceService persistenceService, userIdentityService, proofOfWorkService, ChannelDomain.SUPPORT); - publicSupportChannelService = new PublicModeratedChannelService(persistenceService, + publicSupportChannelService = new PublicChannelService(persistenceService, networkService, userIdentityService, ChannelDomain.SUPPORT, - List.of(new PublicModeratedChannel(ChannelDomain.SUPPORT, "support"), - new PublicModeratedChannel(ChannelDomain.SUPPORT, "questions"), - new PublicModeratedChannel(ChannelDomain.SUPPORT, "reports"))); - supportChannelSelectionService = new SupportChannelSelectionService(persistenceService, + List.of(new PublicChannel(ChannelDomain.SUPPORT, "support"), + new PublicChannel(ChannelDomain.SUPPORT, "questions"), + new PublicChannel(ChannelDomain.SUPPORT, "reports"))); + supportChannelSelectionService = new ChannelSelectionService(persistenceService, privateSupportChannelService, - publicSupportChannelService); + publicSupportChannelService, + ChannelDomain.SUPPORT); } @Override diff --git a/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java b/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java index 2cb24d8b83..593cb7cca2 100644 --- a/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java @@ -17,7 +17,7 @@ package bisq.chat.channel; -import bisq.chat.message.PublicChatMessage; +import bisq.chat.message.BasePublicChatMessage; import bisq.common.observable.ObservableArray; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +26,7 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public abstract class BasePublicChannel extends Channel { +public abstract class BasePublicChannel extends Channel { // Transient because we do not persist the messages as they are persisted in the P2P data store. protected transient final ObservableArray chatMessages = new ObservableArray<>(); diff --git a/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java b/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java new file mode 100644 index 0000000000..0440937950 --- /dev/null +++ b/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java @@ -0,0 +1,142 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.chat.channel; + +import bisq.chat.message.BasePublicChatMessage; +import bisq.chat.message.Quotation; +import bisq.network.NetworkIdWithKeyPair; +import bisq.network.NetworkService; +import bisq.network.p2p.services.data.DataService; +import bisq.persistence.PersistableStore; +import bisq.user.identity.UserIdentity; +import bisq.user.identity.UserIdentityService; +import bisq.user.profile.UserProfile; +import lombok.extern.slf4j.Slf4j; + +import java.util.Collection; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +@Slf4j +public abstract class BasePublicChannelService, S extends PersistableStore> + extends ChannelService implements DataService.Listener { + + public BasePublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { + super(networkService, userIdentityService, channelDomain); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Service + /////////////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public CompletableFuture initialize() { + log.info("initialize"); + networkService.addDataServiceListener(this); + networkService.getDataService().ifPresent(dataService -> + dataService.getAllAuthenticatedPayload().forEach(this::onAuthenticatedDataAdded)); + maybeAddDefaultChannels(); + return CompletableFuture.completedFuture(true); + } + + @Override + public CompletableFuture shutdown() { + log.info("shutdown"); + networkService.removeDataServiceListener(this); + return CompletableFuture.completedFuture(true); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////////////// + + public CompletableFuture publishChatMessage(String text, + Optional quotedMessage, + C publicChannel, + UserIdentity userIdentity) { + M chatMessage = createChatMessage(text, quotedMessage, publicChannel, userIdentity.getUserProfile()); + return publishChatMessage(chatMessage, userIdentity); + } + + public CompletableFuture publishChatMessage(M chatMessage, + UserIdentity userIdentity) { + return publishChatMessage(userIdentity, userIdentity.getUserProfile(), chatMessage); + } + + public CompletableFuture publishEditedChatMessage(M originalChatMessage, + String editedText, + UserIdentity userIdentity) { + NetworkIdWithKeyPair nodeIdAndKeyPair = userIdentity.getNodeIdAndKeyPair(); + return networkService.removeAuthenticatedData(originalChatMessage, nodeIdAndKeyPair) + .thenCompose(result -> { + M chatMessage = createEditedChatMessage(originalChatMessage, editedText, userIdentity.getUserProfile()); + return publishChatMessage(chatMessage, userIdentity); + }); + } + + public CompletableFuture deleteChatMessage(M chatMessage, + UserIdentity userIdentity) { + return networkService.removeAuthenticatedData(chatMessage, userIdentity.getNodeIdAndKeyPair()); + } + + public Collection getMentionableChannels() { + // TODO: implement logic + return getChannels(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Protected + /////////////////////////////////////////////////////////////////////////////////////////////////// + + protected void processAddedMessage(M message) { + findChannel(message.getChannelId()) + .ifPresent(channel -> addMessage(message, channel)); + } + + protected void processRemovedMessage(M message) { + findChannel(message.getChannelId()) + .ifPresent(channel -> removeMessage(message, channel)); + } + + protected void removeMessage(M message, C channel) { + synchronized (getPersistableStore()) { + channel.removeChatMessage(message); + } + persist(); + } + + protected abstract M createChatMessage(String text, + Optional quotedMessage, + C publicChannel, + UserProfile userProfile); + + protected abstract M createEditedChatMessage(M originalChatMessage, String editedText, UserProfile userProfile); + + protected CompletableFuture publishChatMessage(UserIdentity userIdentity, + UserProfile userProfile, + M publicChatMessage) { + NetworkIdWithKeyPair nodeIdAndKeyPair = userIdentity.getNodeIdAndKeyPair(); + return userIdentityService.maybePublicUserProfile(userProfile, nodeIdAndKeyPair) + .thenCompose(result -> networkService.publishAuthenticatedData(publicChatMessage, nodeIdAndKeyPair)); + } + + protected abstract void maybeAddDefaultChannels(); +} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index 4bc2f71381..cc84bd67c8 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -73,8 +73,8 @@ public static Channel fromProto(bisq.chat.protobuf.Channe } - case PUBLICMODERATEDCHANNEL: { - return PublicModeratedChannel.fromProto(proto, proto.getPublicModeratedChannel()); + case PUBLICCHANNEL: { + return PublicChannel.fromProto(proto, proto.getPublicChannel()); } case MESSAGE_NOT_SET: { diff --git a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java b/chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java similarity index 74% rename from chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java rename to chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java index e7538178b3..16d88569d4 100644 --- a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java @@ -15,14 +15,11 @@ * along with Bisq. If not, see . */ -package bisq.chat.events; +package bisq.chat.channel; -import bisq.chat.channel.Channel; -import bisq.chat.channel.PrivateTwoPartyChannel; -import bisq.chat.channel.PrivateTwoPartyChannelService; -import bisq.chat.channel.PublicModeratedChannelService; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; +import bisq.common.util.StringUtils; import bisq.persistence.Persistence; import bisq.persistence.PersistenceClient; import bisq.persistence.PersistenceService; @@ -34,16 +31,20 @@ @Slf4j @Getter -public class EventsChannelSelectionService implements PersistenceClient { - private final EventsChannelSelectionStore persistableStore = new EventsChannelSelectionStore(); - private final Persistence persistence; +public class ChannelSelectionService implements PersistenceClient { + private final ChannelSelectionStore persistableStore = new ChannelSelectionStore(); + private final Persistence persistence; private final PrivateTwoPartyChannelService privateChannelService; - private final PublicModeratedChannelService publicChannelService; + private final PublicChannelService publicChannelService; - public EventsChannelSelectionService(PersistenceService persistenceService, - PrivateTwoPartyChannelService privateChannelService, - PublicModeratedChannelService publicChannelService) { - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); + public ChannelSelectionService(PersistenceService persistenceService, + PrivateTwoPartyChannelService privateChannelService, + PublicChannelService publicChannelService, + ChannelDomain channelDomain) { + persistence = persistenceService.getOrCreatePersistence(this, + "db", + StringUtils.capitalize(channelDomain.name()) + "ChannelSelectionStore", + persistableStore); this.privateChannelService = privateChannelService; this.publicChannelService = publicChannelService; } diff --git a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionStore.java b/chat/src/main/java/bisq/chat/channel/ChannelSelectionStore.java similarity index 63% rename from chat/src/main/java/bisq/chat/events/EventsChannelSelectionStore.java rename to chat/src/main/java/bisq/chat/channel/ChannelSelectionStore.java index 6a1be543c2..727477719c 100644 --- a/chat/src/main/java/bisq/chat/events/EventsChannelSelectionStore.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelSelectionStore.java @@ -15,9 +15,8 @@ * along with Bisq. If not, see . */ -package bisq.chat.events; +package bisq.chat.channel; -import bisq.chat.channel.Channel; import bisq.chat.message.ChatMessage; import bisq.common.observable.Observable; import bisq.common.proto.ProtoResolver; @@ -31,25 +30,25 @@ @Slf4j @Getter -public final class EventsChannelSelectionStore implements PersistableStore { +public final class ChannelSelectionStore implements PersistableStore { private final Observable> selectedChannel = new Observable<>(); - public EventsChannelSelectionStore() { + public ChannelSelectionStore() { } - private EventsChannelSelectionStore(Channel selectedChannel) { + private ChannelSelectionStore(Channel selectedChannel) { this.selectedChannel.set(selectedChannel); } @Override - public bisq.chat.protobuf.EventsChannelSelectionStore toProto() { - bisq.chat.protobuf.EventsChannelSelectionStore.Builder builder = bisq.chat.protobuf.EventsChannelSelectionStore.newBuilder(); + public bisq.chat.protobuf.ChannelSelectionStore toProto() { + bisq.chat.protobuf.ChannelSelectionStore.Builder builder = bisq.chat.protobuf.ChannelSelectionStore.newBuilder(); Optional.ofNullable(selectedChannel.get()).ifPresent(selectedChannel -> builder.setSelectedChannel(selectedChannel.toProto())); return builder.build(); } - public static EventsChannelSelectionStore fromProto(bisq.chat.protobuf.EventsChannelSelectionStore proto) { - return new EventsChannelSelectionStore(proto.hasSelectedChannel() ? Channel.fromProto(proto.getSelectedChannel()) : null); + public static ChannelSelectionStore fromProto(bisq.chat.protobuf.ChannelSelectionStore proto) { + return new ChannelSelectionStore(proto.hasSelectedChannel() ? Channel.fromProto(proto.getSelectedChannel()) : null); } @@ -57,7 +56,7 @@ public static EventsChannelSelectionStore fromProto(bisq.chat.protobuf.EventsCha public ProtoResolver> getResolver() { return any -> { try { - return fromProto(any.unpack(bisq.chat.protobuf.EventsChannelSelectionStore.class)); + return fromProto(any.unpack(bisq.chat.protobuf.ChannelSelectionStore.class)); } catch (InvalidProtocolBufferException e) { throw new UnresolvableProtobufMessageException(e); } @@ -65,12 +64,12 @@ public ProtoResolver> getResolver() { } @Override - public void applyPersisted(EventsChannelSelectionStore persisted) { + public void applyPersisted(ChannelSelectionStore persisted) { this.selectedChannel.set(persisted.selectedChannel.get()); } @Override - public EventsChannelSelectionStore getClone() { - return new EventsChannelSelectionStore(selectedChannel.get()); + public ChannelSelectionStore getClone() { + return new ChannelSelectionStore(selectedChannel.get()); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java b/chat/src/main/java/bisq/chat/channel/PublicChannel.java similarity index 70% rename from chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java rename to chat/src/main/java/bisq/chat/channel/PublicChannel.java index b99e5d9a94..433d4b3328 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannel.java @@ -17,7 +17,7 @@ package bisq.chat.channel; -import bisq.chat.message.PublicModeratedChatMessage; +import bisq.chat.message.PublicChatMessage; import bisq.i18n.Res; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -31,13 +31,13 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PublicModeratedChannel extends BasePublicChannel { +public final class PublicChannel extends BasePublicChannel { private final String displayName; private final String description; private final String channelAdminId; private final List channelModeratorIds; - public PublicModeratedChannel(ChannelDomain channelDomain, String channelName) { + public PublicChannel(ChannelDomain channelDomain, String channelName) { this(channelDomain, channelName, Res.get(channelDomain.name().toLowerCase() + "." + channelName + ".name"), @@ -47,13 +47,13 @@ public PublicModeratedChannel(ChannelDomain channelDomain, String channelName) { ChannelNotificationType.MENTION); } - private PublicModeratedChannel(ChannelDomain channelDomain, - String channelName, - String displayName, - String description, - String channelAdminId, - List channelModeratorIds, - ChannelNotificationType channelNotificationType + private PublicChannel(ChannelDomain channelDomain, + String channelName, + String displayName, + String description, + String channelAdminId, + List channelModeratorIds, + ChannelNotificationType channelNotificationType ) { super(channelDomain, channelName, channelNotificationType); @@ -67,7 +67,7 @@ private PublicModeratedChannel(ChannelDomain channelDomain, public bisq.chat.protobuf.Channel toProto() { return getChannelBuilder() - .setPublicModeratedChannel(bisq.chat.protobuf.PublicModeratedChannel.newBuilder() + .setPublicChannel(bisq.chat.protobuf.PublicChannel.newBuilder() .setChannelName(displayName) .setDescription(description) .setChannelAdminId(channelAdminId) @@ -75,9 +75,9 @@ public bisq.chat.protobuf.Channel toProto() { .build(); } - public static PublicModeratedChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PublicModeratedChannel proto) { - return new PublicModeratedChannel( + public static PublicChannel fromProto(bisq.chat.protobuf.Channel baseProto, + bisq.chat.protobuf.PublicChannel proto) { + return new PublicChannel( ChannelDomain.fromProto(baseProto.getChannelDomain()), baseProto.getId(), proto.getChannelName(), @@ -88,17 +88,17 @@ public static PublicModeratedChannel fromProto(bisq.chat.protobuf.Channel basePr } @Override - public void addChatMessage(PublicModeratedChatMessage chatMessage) { + public void addChatMessage(PublicChatMessage chatMessage) { chatMessages.add(chatMessage); } @Override - public void removeChatMessage(PublicModeratedChatMessage chatMessage) { + public void removeChatMessage(PublicChatMessage chatMessage) { chatMessages.remove(chatMessage); } @Override - public void removeChatMessages(Collection removeMessages) { + public void removeChatMessages(Collection removeMessages) { chatMessages.removeAll(removeMessages); } diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java index f956ba265b..14bbf6b69f 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java @@ -19,124 +19,104 @@ import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; -import bisq.network.NetworkIdWithKeyPair; +import bisq.common.observable.ObservableArray; import bisq.network.NetworkService; -import bisq.network.p2p.services.data.DataService; -import bisq.persistence.PersistableStore; -import bisq.user.identity.UserIdentity; +import bisq.network.p2p.services.data.storage.DistributedData; +import bisq.network.p2p.services.data.storage.auth.AuthenticatedData; +import bisq.persistence.Persistence; +import bisq.persistence.PersistenceService; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import java.util.Collection; +import java.util.Date; +import java.util.List; import java.util.Optional; -import java.util.concurrent.CompletableFuture; @Slf4j -public abstract class PublicChannelService, S extends PersistableStore> - extends ChannelService implements DataService.Listener { - - public PublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { +public class PublicChannelService extends BasePublicChannelService { + @Getter + private final PublicChannelStore persistableStore = new PublicChannelStore(); + @Getter + private final Persistence persistence; + private final List defaultChannels; + + public PublicChannelService(PersistenceService persistenceService, + NetworkService networkService, + UserIdentityService userIdentityService, + ChannelDomain channelDomain, + List defaultChannels) { super(networkService, userIdentityService, channelDomain); + + this.defaultChannels = defaultChannels; + + persistence = persistenceService.getOrCreatePersistence(this, persistableStore); } /////////////////////////////////////////////////////////////////////////////////////////////////// - // Service + // DataService.Listener /////////////////////////////////////////////////////////////////////////////////////////////////// @Override - public CompletableFuture initialize() { - log.info("initialize"); - networkService.addDataServiceListener(this); - networkService.getDataService().ifPresent(dataService -> - dataService.getAllAuthenticatedPayload().forEach(this::onAuthenticatedDataAdded)); - maybeAddDefaultChannels(); - return CompletableFuture.completedFuture(true); + public void onAuthenticatedDataAdded(AuthenticatedData authenticatedData) { + DistributedData distributedData = authenticatedData.getDistributedData(); + if (distributedData instanceof PublicChatMessage) { + processAddedMessage((PublicChatMessage) distributedData); + } } @Override - public CompletableFuture shutdown() { - log.info("shutdown"); - networkService.removeDataServiceListener(this); - return CompletableFuture.completedFuture(true); + public void onAuthenticatedDataRemoved(AuthenticatedData authenticatedData) { + DistributedData distributedData = authenticatedData.getDistributedData(); + if (distributedData instanceof PublicChatMessage) { + processRemovedMessage((PublicChatMessage) distributedData); + } } /////////////////////////////////////////////////////////////////////////////////////////////////// - // API + // PublicChannelService /////////////////////////////////////////////////////////////////////////////////////////////////// - public CompletableFuture publishChatMessage(String text, - Optional quotedMessage, - C publicChannel, - UserIdentity userIdentity) { - M chatMessage = createChatMessage(text, quotedMessage, publicChannel, userIdentity.getUserProfile()); - return publishChatMessage(chatMessage, userIdentity); - } - - public CompletableFuture publishChatMessage(M chatMessage, - UserIdentity userIdentity) { - return publishChatMessage(userIdentity, userIdentity.getUserProfile(), chatMessage); - } - - public CompletableFuture publishEditedChatMessage(M originalChatMessage, - String editedText, - UserIdentity userIdentity) { - NetworkIdWithKeyPair nodeIdAndKeyPair = userIdentity.getNodeIdAndKeyPair(); - return networkService.removeAuthenticatedData(originalChatMessage, nodeIdAndKeyPair) - .thenCompose(result -> { - M chatMessage = createEditedChatMessage(originalChatMessage, editedText, userIdentity.getUserProfile()); - return publishChatMessage(chatMessage, userIdentity); - }); - } - - public CompletableFuture deleteChatMessage(M chatMessage, - UserIdentity userIdentity) { - return networkService.removeAuthenticatedData(chatMessage, userIdentity.getNodeIdAndKeyPair()); - } - - public Collection getMentionableChannels() { - // TODO: implement logic - return getChannels(); + @Override + public ObservableArray getChannels() { + return persistableStore.getChannels(); } - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // Protected - /////////////////////////////////////////////////////////////////////////////////////////////////// - - protected void processAddedMessage(M message) { - findChannel(message.getChannelId()) - .ifPresent(channel -> addMessage(message, channel)); + @Override + protected PublicChatMessage createChatMessage(String text, + Optional quotedMessage, + PublicChannel publicChannel, + UserProfile userProfile) { + return new PublicChatMessage(publicChannel.getId(), + userProfile.getId(), + text, + quotedMessage, + new Date().getTime(), + false); } - protected void processRemovedMessage(M message) { - findChannel(message.getChannelId()) - .ifPresent(channel -> removeMessage(message, channel)); + @Override + protected PublicChatMessage createEditedChatMessage(PublicChatMessage originalChatMessage, + String editedText, + UserProfile userProfile) { + return new PublicChatMessage(originalChatMessage.getChannelId(), + userProfile.getId(), + editedText, + originalChatMessage.getQuotation(), + originalChatMessage.getDate(), + true); } - protected void removeMessage(M message, C channel) { - synchronized (getPersistableStore()) { - channel.removeChatMessage(message); + @Override + protected void maybeAddDefaultChannels() { + if (!getChannels().isEmpty()) { + return; } - persist(); - } - - protected abstract M createChatMessage(String text, - Optional quotedMessage, - C publicChannel, - UserProfile userProfile); - protected abstract M createEditedChatMessage(M originalChatMessage, String editedText, UserProfile userProfile); - - protected CompletableFuture publishChatMessage(UserIdentity userIdentity, - UserProfile userProfile, - M publicChatMessage) { - NetworkIdWithKeyPair nodeIdAndKeyPair = userIdentity.getNodeIdAndKeyPair(); - return userIdentityService.maybePublicUserProfile(userProfile, nodeIdAndKeyPair) - .thenCompose(result -> networkService.publishAuthenticatedData(publicChatMessage, nodeIdAndKeyPair)); + getChannels().addAll(defaultChannels); + persist(); } - - protected abstract void maybeAddDefaultChannels(); } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelStore.java b/chat/src/main/java/bisq/chat/channel/PublicChannelStore.java similarity index 56% rename from chat/src/main/java/bisq/chat/channel/PublicModeratedChannelStore.java rename to chat/src/main/java/bisq/chat/channel/PublicChannelStore.java index f0d9c4d69e..f3289c2db7 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannelStore.java @@ -28,35 +28,35 @@ import java.util.stream.Collectors; @Getter -public class PublicModeratedChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); +public class PublicChannelStore implements PersistableStore { + private final ObservableArray channels = new ObservableArray<>(); - public PublicModeratedChannelStore() { + public PublicChannelStore() { } - private PublicModeratedChannelStore(List privateDiscussionChannels) { + private PublicChannelStore(List privateDiscussionChannels) { setAll(privateDiscussionChannels); } @Override - public bisq.chat.protobuf.PublicModeratedChannelStore toProto() { - bisq.chat.protobuf.PublicModeratedChannelStore.Builder builder = bisq.chat.protobuf.PublicModeratedChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PublicModeratedChannel::toProto).collect(Collectors.toList())); + public bisq.chat.protobuf.PublicChannelStore toProto() { + bisq.chat.protobuf.PublicChannelStore.Builder builder = bisq.chat.protobuf.PublicChannelStore.newBuilder() + .addAllChannels(channels.stream().map(PublicChannel::toProto).collect(Collectors.toList())); return builder.build(); } - public static PublicModeratedChannelStore fromProto(bisq.chat.protobuf.PublicModeratedChannelStore proto) { - List privateDiscussionChannels = proto.getChannelsList().stream() - .map(e -> (PublicModeratedChannel) PublicModeratedChannel.fromProto(e)) + public static PublicChannelStore fromProto(bisq.chat.protobuf.PublicChannelStore proto) { + List privateDiscussionChannels = proto.getChannelsList().stream() + .map(e -> (PublicChannel) PublicChannel.fromProto(e)) .collect(Collectors.toList()); - return new PublicModeratedChannelStore(privateDiscussionChannels); + return new PublicChannelStore(privateDiscussionChannels); } @Override public ProtoResolver> getResolver() { return any -> { try { - return fromProto(any.unpack(bisq.chat.protobuf.PublicModeratedChannelStore.class)); + return fromProto(any.unpack(bisq.chat.protobuf.PublicChannelStore.class)); } catch (InvalidProtocolBufferException e) { throw new UnresolvableProtobufMessageException(e); } @@ -64,16 +64,16 @@ public ProtoResolver> getResolver() { } @Override - public void applyPersisted(PublicModeratedChannelStore chatStore) { + public void applyPersisted(PublicChannelStore chatStore) { setAll(chatStore.getChannels()); } @Override - public PublicModeratedChannelStore getClone() { - return new PublicModeratedChannelStore(channels); + public PublicChannelStore getClone() { + return new PublicChannelStore(channels); } - public void setAll(List privateDiscussionChannels) { + public void setAll(List privateDiscussionChannels) { this.channels.clear(); this.channels.addAll(privateDiscussionChannels); } diff --git a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java deleted file mode 100644 index a22465f170..0000000000 --- a/chat/src/main/java/bisq/chat/channel/PublicModeratedChannelService.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.channel; - -import bisq.chat.message.PublicModeratedChatMessage; -import bisq.chat.message.Quotation; -import bisq.common.observable.ObservableArray; -import bisq.network.NetworkService; -import bisq.network.p2p.services.data.storage.DistributedData; -import bisq.network.p2p.services.data.storage.auth.AuthenticatedData; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceService; -import bisq.user.identity.UserIdentityService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Date; -import java.util.List; -import java.util.Optional; - -@Slf4j -public class PublicModeratedChannelService extends PublicChannelService { - @Getter - private final PublicModeratedChannelStore persistableStore = new PublicModeratedChannelStore(); - @Getter - private final Persistence persistence; - private final List defaultChannels; - - public PublicModeratedChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService, - ChannelDomain channelDomain, - List defaultChannels) { - super(networkService, userIdentityService, channelDomain); - - this.defaultChannels = defaultChannels; - - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // DataService.Listener - /////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void onAuthenticatedDataAdded(AuthenticatedData authenticatedData) { - DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicModeratedChatMessage) { - processAddedMessage((PublicModeratedChatMessage) distributedData); - } - } - - @Override - public void onAuthenticatedDataRemoved(AuthenticatedData authenticatedData) { - DistributedData distributedData = authenticatedData.getDistributedData(); - if (distributedData instanceof PublicModeratedChatMessage) { - processRemovedMessage((PublicModeratedChatMessage) distributedData); - } - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // PublicChannelService - /////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public ObservableArray getChannels() { - return persistableStore.getChannels(); - } - - @Override - protected PublicModeratedChatMessage createChatMessage(String text, - Optional quotedMessage, - PublicModeratedChannel publicChannel, - UserProfile userProfile) { - return new PublicModeratedChatMessage(publicChannel.getId(), - userProfile.getId(), - text, - quotedMessage, - new Date().getTime(), - false); - } - - @Override - protected PublicModeratedChatMessage createEditedChatMessage(PublicModeratedChatMessage originalChatMessage, - String editedText, - UserProfile userProfile) { - return new PublicModeratedChatMessage(originalChatMessage.getChannelId(), - userProfile.getId(), - editedText, - originalChatMessage.getQuotation(), - originalChatMessage.getDate(), - true); - } - - @Override - protected void maybeAddDefaultChannels() { - if (!getChannels().isEmpty()) { - return; - } - - getChannels().addAll(defaultChannels); - persist(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java deleted file mode 100644 index 30e8b6ea54..0000000000 --- a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionService.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.discuss; - -import bisq.chat.channel.Channel; -import bisq.chat.channel.PrivateTwoPartyChannel; -import bisq.chat.channel.PrivateTwoPartyChannelService; -import bisq.chat.channel.PublicModeratedChannelService; -import bisq.chat.message.ChatMessage; -import bisq.common.observable.Observable; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceClient; -import bisq.persistence.PersistenceService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.CompletableFuture; - -@Slf4j -@Getter -public class DiscussionChannelSelectionService implements PersistenceClient { - private final DiscussionChannelSelectionStore persistableStore = new DiscussionChannelSelectionStore(); - private final Persistence persistence; - private final PrivateTwoPartyChannelService privateChannelService; - private final PublicModeratedChannelService publicChannelService; - - public DiscussionChannelSelectionService(PersistenceService persistenceService, - PrivateTwoPartyChannelService privateChannelService, - PublicModeratedChannelService publicChannelService) { - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - this.privateChannelService = privateChannelService; - this.publicChannelService = publicChannelService; - } - - public CompletableFuture initialize() { - log.info("initialize"); - maybeSelectChannels(); - return CompletableFuture.completedFuture(true); - } - - public CompletableFuture shutdown() { - log.info("shutdown"); - return CompletableFuture.completedFuture(true); - } - - public void selectChannel(Channel channel) { - if (channel instanceof PrivateTwoPartyChannel) { - privateChannelService.removeExpiredMessages((PrivateTwoPartyChannel) channel); - } - - getSelectedChannel().set(channel); - persist(); - } - - public Observable> getSelectedChannel() { - return persistableStore.getSelectedChannel(); - } - - public void reportUserProfile(UserProfile userProfile, String reason) { - //todo report user to admin and moderators, add reason - log.info("called reportChatUser {} {}", userProfile, reason); - } - - private void maybeSelectChannels() { - if (getSelectedChannel().get() == null) { - publicChannelService.getChannels().stream().findAny().ifPresent(this::selectChannel); - } - persist(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionStore.java b/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionStore.java deleted file mode 100644 index 839b7a65b0..0000000000 --- a/chat/src/main/java/bisq/chat/discuss/DiscussionChannelSelectionStore.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.discuss; - -import bisq.chat.channel.Channel; -import bisq.chat.message.ChatMessage; -import bisq.common.observable.Observable; -import bisq.common.proto.ProtoResolver; -import bisq.common.proto.UnresolvableProtobufMessageException; -import bisq.persistence.PersistableStore; -import com.google.protobuf.InvalidProtocolBufferException; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Optional; - -@Slf4j -@Getter -public final class DiscussionChannelSelectionStore implements PersistableStore { - private final Observable> selectedChannel = new Observable<>(); - - public DiscussionChannelSelectionStore() { - } - - private DiscussionChannelSelectionStore(Channel selectedChannel) { - this.selectedChannel.set(selectedChannel); - } - - @Override - public bisq.chat.protobuf.DiscussionChannelSelectionStore toProto() { - bisq.chat.protobuf.DiscussionChannelSelectionStore.Builder builder = bisq.chat.protobuf.DiscussionChannelSelectionStore.newBuilder(); - Optional.ofNullable(selectedChannel.get()).ifPresent(selectedChannel -> builder.setSelectedChannel(selectedChannel.toProto())); - return builder.build(); - } - - public static DiscussionChannelSelectionStore fromProto(bisq.chat.protobuf.DiscussionChannelSelectionStore proto) { - return new DiscussionChannelSelectionStore(proto.hasSelectedChannel() ? Channel.fromProto(proto.getSelectedChannel()) : null); - } - - - @Override - public ProtoResolver> getResolver() { - return any -> { - try { - return fromProto(any.unpack(bisq.chat.protobuf.DiscussionChannelSelectionStore.class)); - } catch (InvalidProtocolBufferException e) { - throw new UnresolvableProtobufMessageException(e); - } - }; - } - - @Override - public void applyPersisted(DiscussionChannelSelectionStore persisted) { - this.selectedChannel.set(persisted.selectedChannel.get()); - } - - @Override - public DiscussionChannelSelectionStore getClone() { - return new DiscussionChannelSelectionStore(selectedChannel.get()); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java b/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java new file mode 100644 index 0000000000..fb9cef314c --- /dev/null +++ b/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java @@ -0,0 +1,55 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.chat.message; + +import bisq.common.encoding.Hex; +import bisq.network.p2p.services.data.storage.DistributedData; +import bisq.network.p2p.services.data.storage.MetaData; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +import java.util.Optional; + +/** + * PublicChatMessage is added as public data to the distributed network storage. + */ +@Slf4j +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public abstract class BasePublicChatMessage extends ChatMessage implements DistributedData { + protected BasePublicChatMessage(String messageId, + String channelId, + String authorId, + Optional text, + Optional quotation, + long date, + boolean wasEdited, + MessageType messageType, + MetaData metaData) { + super(messageId, channelId, authorId, text, quotation, date, wasEdited, messageType, metaData); + } + + @Override + public boolean isDataInvalid(byte[] pubKeyHash) { + // AuthorId must be pubKeyHash. We get pubKeyHash passed from the data storage layer where the signature is + // verified as well, so we can be sure it's the sender of the message. This check prevents against + // impersonation attack. + return !authorId.equals(Hex.encode(pubKeyHash)); + } +} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index ebee6d26eb..41b8c875c2 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -103,8 +103,8 @@ public static ChatMessage fromProto(bisq.chat.protobuf.ChatMessage proto) { return PrivateTradeChatMessage.fromProto(proto); } - case PUBLICMODERATEDCHATMESSAGE: { - return PublicModeratedChatMessage.fromProto(proto); + case PUBLICCHATMESSAGE: { + return PublicChatMessage.fromProto(proto); } case MESSAGE_NOT_SET: { @@ -122,8 +122,8 @@ public static ProtoResolver getDistributedDataResolver() { case PUBLICTRADECHATMESSAGE: { return PublicTradeChatMessage.fromProto(proto); } - case PUBLICMODERATEDCHATMESSAGE: { - return PublicModeratedChatMessage.fromProto(proto); + case PUBLICCHATMESSAGE: { + return PublicChatMessage.fromProto(proto); } case MESSAGE_NOT_SET: { throw new UnresolvableProtobufMessageException(proto); diff --git a/chat/src/main/java/bisq/chat/message/PublicChatMessage.java b/chat/src/main/java/bisq/chat/message/PublicChatMessage.java index 3b66c7fac7..3e1897e67f 100644 --- a/chat/src/main/java/bisq/chat/message/PublicChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PublicChatMessage.java @@ -17,39 +17,72 @@ package bisq.chat.message; -import bisq.common.encoding.Hex; -import bisq.network.p2p.services.data.storage.DistributedData; +import bisq.common.util.StringUtils; import bisq.network.p2p.services.data.storage.MetaData; import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.ToString; -import lombok.extern.slf4j.Slf4j; import java.util.Optional; -/** - * PublicChatMessage is added as public data to the distributed network storage. - */ -@Slf4j +@Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public abstract class PublicChatMessage extends ChatMessage implements DistributedData { - protected PublicChatMessage(String messageId, - String channelId, - String authorId, - Optional text, - Optional quotation, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, channelId, authorId, text, quotation, date, wasEdited, messageType, metaData); +public final class PublicChatMessage extends BasePublicChatMessage { + public PublicChatMessage(String channelId, + String authorId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited) { + this(StringUtils.createShortUid(), + channelId, + authorId, + Optional.of(text), + quotedMessage, + date, + wasEdited, + MessageType.TEXT, + new MetaData(ChatMessage.TTL, 100000, PublicChatMessage.class.getSimpleName())); + } + + private PublicChatMessage(String messageId, + String channelId, + String authorId, + Optional text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType, + MetaData metaData) { + super(messageId, + channelId, + authorId, + text, + quotedMessage, + date, + wasEdited, + messageType, + metaData); + } + + public bisq.chat.protobuf.ChatMessage toProto() { + return getChatMessageBuilder().setPublicChatMessage(bisq.chat.protobuf.PublicChatMessage.newBuilder()).build(); } - @Override - public boolean isDataInvalid(byte[] pubKeyHash) { - // AuthorId must be pubKeyHash. We get pubKeyHash passed from the data storage layer where the signature is - // verified as well, so we can be sure it's the sender of the message. This check prevents against - // impersonation attack. - return !authorId.equals(Hex.encode(pubKeyHash)); + public static PublicChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { + Optional quotedMessage = baseProto.hasQuotation() ? + Optional.of(Quotation.fromProto(baseProto.getQuotation())) : + Optional.empty(); + return new PublicChatMessage( + baseProto.getMessageId(), + baseProto.getChannelId(), + baseProto.getAuthorId(), + Optional.of(baseProto.getText()), + quotedMessage, + baseProto.getDate(), + baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), + MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java b/chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java deleted file mode 100644 index 7e5ea4e04f..0000000000 --- a/chat/src/main/java/bisq/chat/message/PublicModeratedChatMessage.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.message; - -import bisq.common.util.StringUtils; -import bisq.network.p2p.services.data.storage.MetaData; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.Optional; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public final class PublicModeratedChatMessage extends PublicChatMessage { - public PublicModeratedChatMessage(String channelId, - String authorId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited) { - this(StringUtils.createShortUid(), - channelId, - authorId, - Optional.of(text), - quotedMessage, - date, - wasEdited, - MessageType.TEXT, - new MetaData(ChatMessage.TTL, 100000, PublicModeratedChatMessage.class.getSimpleName())); - } - - private PublicModeratedChatMessage(String messageId, - String channelId, - String authorId, - Optional text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, - channelId, - authorId, - text, - quotedMessage, - date, - wasEdited, - messageType, - metaData); - } - - public bisq.chat.protobuf.ChatMessage toProto() { - return getChatMessageBuilder().setPublicModeratedChatMessage(bisq.chat.protobuf.PublicModeratedChatMessage.newBuilder()).build(); - } - - public static PublicModeratedChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { - Optional quotedMessage = baseProto.hasQuotation() ? - Optional.of(Quotation.fromProto(baseProto.getQuotation())) : - Optional.empty(); - return new PublicModeratedChatMessage( - baseProto.getMessageId(), - baseProto.getChannelId(), - baseProto.getAuthorId(), - Optional.of(baseProto.getText()), - quotedMessage, - baseProto.getDate(), - baseProto.getWasEdited(), - MessageType.fromProto(baseProto.getMessageType()), - MetaData.fromProto(baseProto.getMetaData())); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java deleted file mode 100644 index 714dae043f..0000000000 --- a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionService.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support; - -import bisq.chat.channel.Channel; -import bisq.chat.channel.PrivateTwoPartyChannel; -import bisq.chat.channel.PrivateTwoPartyChannelService; -import bisq.chat.channel.PublicModeratedChannelService; -import bisq.chat.message.ChatMessage; -import bisq.common.observable.Observable; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceClient; -import bisq.persistence.PersistenceService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.CompletableFuture; - -@Slf4j -@Getter -public class SupportChannelSelectionService implements PersistenceClient { - private final SupportChannelSelectionStore persistableStore = new SupportChannelSelectionStore(); - private final Persistence persistence; - private final PrivateTwoPartyChannelService privateChannelService; - private final PublicModeratedChannelService publicChannelService; - - public SupportChannelSelectionService(PersistenceService persistenceService, - PrivateTwoPartyChannelService privateChannelService, - PublicModeratedChannelService publicChannelService) { - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); - this.privateChannelService = privateChannelService; - this.publicChannelService = publicChannelService; - } - - public CompletableFuture initialize() { - log.info("initialize"); - maybeSelectChannels(); - return CompletableFuture.completedFuture(true); - } - - public CompletableFuture shutdown() { - log.info("shutdown"); - return CompletableFuture.completedFuture(true); - } - - public void selectChannel(Channel channel) { - if (channel instanceof PrivateTwoPartyChannel) { - privateChannelService.removeExpiredMessages((PrivateTwoPartyChannel) channel); - } - - getSelectedChannel().set(channel); - persist(); - } - - public Observable> getSelectedChannel() { - return persistableStore.getSelectedChannel(); - } - - public void reportUserProfile(UserProfile userProfile, String reason) { - //todo report user to admin and moderators, add reason - log.info("called reportChatUser {} {}", userProfile, reason); - } - - private void maybeSelectChannels() { - if (getSelectedChannel().get() == null) { - publicChannelService.getChannels().stream().findAny().ifPresent(this::selectChannel); - } - persist(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionStore.java b/chat/src/main/java/bisq/chat/support/SupportChannelSelectionStore.java deleted file mode 100644 index 6ba981382e..0000000000 --- a/chat/src/main/java/bisq/chat/support/SupportChannelSelectionStore.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.support; - -import bisq.chat.channel.Channel; -import bisq.chat.message.ChatMessage; -import bisq.common.observable.Observable; -import bisq.common.proto.ProtoResolver; -import bisq.common.proto.UnresolvableProtobufMessageException; -import bisq.persistence.PersistableStore; -import com.google.protobuf.InvalidProtocolBufferException; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Optional; - -@Slf4j -@Getter -public final class SupportChannelSelectionStore implements PersistableStore { - private final Observable> selectedChannel = new Observable<>(); - - public SupportChannelSelectionStore() { - } - - private SupportChannelSelectionStore(Channel selectedChannel) { - this.selectedChannel.set(selectedChannel); - } - - @Override - public bisq.chat.protobuf.SupportChannelSelectionStore toProto() { - bisq.chat.protobuf.SupportChannelSelectionStore.Builder builder = bisq.chat.protobuf.SupportChannelSelectionStore.newBuilder(); - Optional.ofNullable(selectedChannel.get()).ifPresent(selectedChannel -> builder.setSelectedChannel(selectedChannel.toProto())); - return builder.build(); - } - - public static SupportChannelSelectionStore fromProto(bisq.chat.protobuf.SupportChannelSelectionStore proto) { - return new SupportChannelSelectionStore(proto.hasSelectedChannel() ? Channel.fromProto(proto.getSelectedChannel()) : null); - } - - - @Override - public ProtoResolver> getResolver() { - return any -> { - try { - return fromProto(any.unpack(bisq.chat.protobuf.SupportChannelSelectionStore.class)); - } catch (InvalidProtocolBufferException e) { - throw new UnresolvableProtobufMessageException(e); - } - }; - } - - @Override - public void applyPersisted(SupportChannelSelectionStore persisted) { - this.selectedChannel.set(persisted.selectedChannel.get()); - } - - @Override - public SupportChannelSelectionStore getClone() { - return new SupportChannelSelectionStore(selectedChannel.get()); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java index 459d9d2e38..9e29637f75 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java @@ -17,8 +17,8 @@ package bisq.chat.trade.pub; +import bisq.chat.channel.BasePublicChannelService; import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PublicChannelService; import bisq.chat.message.Quotation; import bisq.common.currency.Market; import bisq.common.currency.MarketRepository; @@ -42,7 +42,7 @@ import java.util.stream.Collectors; @Slf4j -public class PublicTradeChannelService extends PublicChannelService { +public class PublicTradeChannelService extends BasePublicChannelService { @Getter private final PublicTradeChannelStore persistableStore = new PublicTradeChannelStore(); @Getter diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java index fde7595ecc..f7d1345b34 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java @@ -17,9 +17,9 @@ package bisq.chat.trade.pub; +import bisq.chat.message.BasePublicChatMessage; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; -import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.common.util.StringUtils; import bisq.network.p2p.services.data.storage.MetaData; @@ -34,7 +34,7 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public final class PublicTradeChatMessage extends PublicChatMessage { +public final class PublicTradeChatMessage extends BasePublicChatMessage { private final Optional tradeChatOffer; public PublicTradeChatMessage(String channelId, diff --git a/chat/src/main/proto/chat.proto b/chat/src/main/proto/chat.proto index 20c623cf6f..3c2178a943 100644 --- a/chat/src/main/proto/chat.proto +++ b/chat/src/main/proto/chat.proto @@ -63,7 +63,7 @@ message ChatMessage { network.MetaData metaData = 9; oneof message { PrivateTwoPartyChatMessage privateTwoPartyChatMessage = 20; - PublicModeratedChatMessage publicModeratedChatMessage = 21; + PublicChatMessage publicChatMessage = 21; PrivateTradeChatMessage privateTradeChatMessage = 22; PublicTradeChatMessage publicTradeChatMessage = 23; @@ -76,7 +76,7 @@ message Channel { ChannelDomain channelDomain = 3; oneof message{ PrivateTwoPartyChannel privateTwoPartyChannel = 10; - PublicModeratedChannel publicModeratedChannel = 11; + PublicChannel publicChannel = 11; PrivateTradeChannel privateTradeChannel = 12; PublicTradeChannel publicTradeChannel = 13; @@ -98,25 +98,27 @@ message PrivateTwoPartyChannelStore { } -// PublicModerated -message PublicModeratedChatMessage { +// Public +message PublicChatMessage { } -message PublicModeratedChannel { +message PublicChannel { string channelName = 1; string description = 2; string channelAdminId = 3; repeated string channelModeratorIds = 4; bool isVisible = 5; } -message PublicModeratedChannelStore { +message PublicChannelStore { repeated Channel channels = 1; } -// SelectionStores -message DiscussionChannelSelectionStore { +message ChannelSelectionStore { optional Channel selectedChannel = 1; } + + + message EventsChannelSelectionStore { optional Channel selectedChannel = 1; } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index e447b5e7d9..a16b14d5a0 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -19,9 +19,6 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.*; -import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.events.EventsChannelSelectionService; -import bisq.chat.support.SupportChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -82,11 +79,11 @@ protected static class Controller extends ChannelSelection.Controller { private final PrivateTradeChannelService privateTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; - private final DiscussionChannelSelectionService discussionChannelSelectionService; + private final ChannelSelectionService discussionChannelSelectionService; private final PrivateTwoPartyChannelService privateEventsChannelService; private final PrivateTwoPartyChannelService privateSupportChannelService; - private final EventsChannelSelectionService eventsChannelSelectionService; - private final SupportChannelSelectionService supportChannelSelectionService; + private final ChannelSelectionService eventsChannelSelectionService; + private final ChannelSelectionService supportChannelSelectionService; private final UserIdentityService userIdentityService; private Pin inMediationPin; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java index 900a92a711..246638c29f 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicDiscussionChannelSelection.java @@ -19,9 +19,9 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.PublicModeratedChannel; -import bisq.chat.channel.PublicModeratedChannelService; -import bisq.chat.discuss.DiscussionChannelSelectionService; +import bisq.chat.channel.ChannelSelectionService; +import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.PublicChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; import bisq.i18n.Res; @@ -54,9 +54,9 @@ protected static class Controller extends ChannelSelection.Controller { private final Model model; @Getter private final View view; - private final PublicModeratedChannelService publicDiscussionChannelService; + private final PublicChannelService publicDiscussionChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final DiscussionChannelSelectionService discussionChannelSelectionService; + private final ChannelSelectionService discussionChannelSelectionService; protected Controller(ChatService chatService) { super(chatService); @@ -80,13 +80,13 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(ChannelSelection.View.ChannelItem::new) .to(publicDiscussionChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(discussionChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PublicModeratedChannel) { + if (channel instanceof PublicChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); } }); @@ -134,7 +134,7 @@ protected ListCell getListCell() { @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PublicModeratedChannel) { + if (item != null && !empty && item.getChannel() instanceof PublicChannel) { widthSubscription = setupCellBinding(this, item, label, iconImageView); updateCell(this, item, label, iconImageView); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java index 0bb838c9f6..04fe4ebbaa 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicEventsChannelSelection.java @@ -19,9 +19,9 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.PublicModeratedChannel; -import bisq.chat.channel.PublicModeratedChannelService; -import bisq.chat.events.EventsChannelSelectionService; +import bisq.chat.channel.ChannelSelectionService; +import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.PublicChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; import bisq.i18n.Res; @@ -54,9 +54,9 @@ protected static class Controller extends ChannelSelection.Controller { private final Model model; @Getter private final View view; - private final PublicModeratedChannelService publicEventsChannelService; + private final PublicChannelService publicEventsChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final EventsChannelSelectionService eventsChannelSelectionService; + private final ChannelSelectionService eventsChannelSelectionService; protected Controller(ChatService chatService) { super(chatService); @@ -80,13 +80,13 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(ChannelSelection.View.ChannelItem::new) .to(publicEventsChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(eventsChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PublicModeratedChannel) { + if (channel instanceof PublicChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); } }); @@ -134,7 +134,7 @@ protected ListCell getListCell() { @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PublicModeratedChannel) { + if (item != null && !empty && item.getChannel() instanceof PublicChannel) { widthSubscription = setupCellBinding(this, item, label, iconImageView); updateCell(this, item, label, iconImageView); setGraphic(hBox); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java index 289242d8a4..80d82f5d47 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicSupportChannelSelection.java @@ -19,9 +19,9 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; -import bisq.chat.channel.PublicModeratedChannel; -import bisq.chat.channel.PublicModeratedChannelService; -import bisq.chat.support.SupportChannelSelectionService; +import bisq.chat.channel.ChannelSelectionService; +import bisq.chat.channel.PublicChannel; +import bisq.chat.channel.PublicChannelService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.desktop.common.observable.FxBindings; import bisq.i18n.Res; @@ -54,9 +54,9 @@ protected static class Controller extends ChannelSelection.Controller { private final Model model; @Getter private final View view; - private final PublicModeratedChannelService publicSupportChannelService; + private final PublicChannelService publicSupportChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final SupportChannelSelectionService supportChannelSelectionService; + private final ChannelSelectionService supportChannelSelectionService; protected Controller(ChatService chatService) { super(chatService); @@ -80,13 +80,13 @@ protected ChannelSelection.Model getChannelSelectionModel() { public void onActivate() { super.onActivate(); - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(ChannelSelection.View.ChannelItem::new) .to(publicSupportChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(supportChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PublicModeratedChannel) { + if (channel instanceof PublicChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); } }); @@ -135,7 +135,7 @@ protected ListCell getListCell() { @Override protected void updateItem(ChannelItem item, boolean empty) { super.updateItem(item, empty); - if (item != null && !empty && item.getChannel() instanceof PublicModeratedChannel) { + if (item != null && !empty && item.getChannel() instanceof PublicChannel) { widthSubscription = setupCellBinding(this, item, label, iconImageView); updateCell(this, item, label, iconImageView); setGraphic(hBox); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index e4973db029..65c9dc5454 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -20,7 +20,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PublicModeratedChannel; +import bisq.chat.channel.PublicChannel; import bisq.chat.message.ChatMessage; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.desktop.components.containers.Spacer; @@ -108,8 +108,8 @@ void setChannel(Channel channel) { .sorted() .collect(Collectors.toList())); - if (channel instanceof PublicModeratedChannel) { - PublicModeratedChannel publicEventsChannel = (PublicModeratedChannel) channel; + if (channel instanceof PublicChannel) { + PublicChannel publicEventsChannel = (PublicChannel) channel; model.description.set(publicEventsChannel.getDescription()); model.descriptionVisible.set(true); model.adminProfile = userProfileService.findUserProfile(publicEventsChannel.getChannelAdminId()).map(ChatUserOverview::new); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 3de7a15978..5e723f67e7 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -20,11 +20,8 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; import bisq.chat.channel.*; -import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.chat.message.Quotation; -import bisq.chat.support.SupportChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -114,17 +111,17 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final UserProfileService userProfileService; private final PrivateTradeChannelService privateTradeChannelService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; - private final PublicModeratedChannelService publicDiscussionChannelService; + private final PublicChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final DiscussionChannelSelectionService discussionChannelSelectionService; + private final ChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; - private final PublicModeratedChannelService publicEventsChannelService; + private final PublicChannelService publicEventsChannelService; private final PrivateTwoPartyChannelService privateEventsChannelService; - private final EventsChannelSelectionService eventsChannelSelectionService; - private final PublicModeratedChannelService publicSupportChannelService; + private final ChannelSelectionService eventsChannelSelectionService; + private final PublicChannelService publicSupportChannelService; private final PrivateTwoPartyChannelService privateSupportChannelService; - private final SupportChannelSelectionService supportChannelSelectionService; + private final ChannelSelectionService supportChannelSelectionService; private final UserProfileSelection userProfileSelection; private Pin selectedChannelPin; private Pin chatMessagesPin; @@ -246,18 +243,18 @@ private void doSendMessage(String text) { } else { new Popup().information(Res.get("social.chat.sendMsg.tradeRulesNotConfirmed.popup")).show(); } - } else if (channel instanceof PublicModeratedChannel) { + } else if (channel instanceof PublicChannel) { switch (channel.getChannelDomain()) { case TRADE -> { } case DISCUSSION -> { - publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + publicDiscussionChannelService.publishChatMessage(text, quotation, (PublicChannel) channel, userIdentity); } case EVENTS -> { - publicEventsChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + publicEventsChannelService.publishChatMessage(text, quotation, (PublicChannel) channel, userIdentity); } case SUPPORT -> { - publicSupportChannelService.publishChatMessage(text, quotation, (PublicModeratedChannel) channel, userIdentity); + publicSupportChannelService.publishChatMessage(text, quotation, (PublicChannel) channel, userIdentity); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 25b35b5ca3..8e831c0e5a 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -20,10 +20,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; import bisq.chat.channel.*; -import bisq.chat.discuss.DiscussionChannelSelectionService; -import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.*; -import bisq.chat.support.SupportChannelSelectionService; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.priv.PrivateTradeChannelService; @@ -149,7 +146,7 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final ChatService chatService; private final PrivateTradeChannelService privateTradeChannelService; private final PrivateTwoPartyChannelService privateDiscussionChannelService; - private final PublicModeratedChannelService publicDiscussionChannelService; + private final PublicChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final UserIdentityService userIdentityService; private final Consumer mentionUserHandler; @@ -158,14 +155,14 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final ReputationService reputationService; private final UserProfileService userProfileService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final DiscussionChannelSelectionService discussionChannelSelectionService; + private final ChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; private final PrivateTwoPartyChannelService privateEventsChannelService; - private final PublicModeratedChannelService publicEventsChannelService; - private final EventsChannelSelectionService eventsChannelSelectionService; + private final PublicChannelService publicEventsChannelService; + private final ChannelSelectionService eventsChannelSelectionService; private final PrivateTwoPartyChannelService privateSupportChannelService; - private final PublicModeratedChannelService publicSupportChannelService; - private final SupportChannelSelectionService supportChannelSelectionService; + private final PublicChannelService publicSupportChannelService; + private final ChannelSelectionService supportChannelSelectionService; private final MediationService mediationService; private Pin selectedChannelPin, chatMessagesPin; private Pin offerOnlySettingsPin; @@ -248,13 +245,13 @@ public void onActivate() { } else if (model.getChannelDomain() == ChannelDomain.DISCUSSION) { selectedChannelPin = discussionChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); - if (channel instanceof PublicModeratedChannel) { + if (channel instanceof PublicChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PublicModeratedChannel) channel).getChatMessages()); + .to(((PublicChannel) channel).getChatMessages()); model.allowEditing.set(true); } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { @@ -269,13 +266,13 @@ public void onActivate() { } else if (model.getChannelDomain() == ChannelDomain.EVENTS) { selectedChannelPin = eventsChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); - if (channel instanceof PublicModeratedChannel) { + if (channel instanceof PublicChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PublicModeratedChannel) channel).getChatMessages()); + .to(((PublicChannel) channel).getChatMessages()); model.allowEditing.set(true); } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { @@ -290,13 +287,13 @@ public void onActivate() { } else if (model.getChannelDomain() == ChannelDomain.SUPPORT) { selectedChannelPin = supportChannelSelectionService.getSelectedChannel().addObserver(channel -> { model.selectedChannel.set(channel); - if (channel instanceof PublicModeratedChannel) { + if (channel instanceof PublicChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PublicModeratedChannel) channel).getChatMessages()); + .to(((PublicChannel) channel).getChatMessages()); model.allowEditing.set(true); } else if (channel instanceof PrivateTwoPartyChannel) { if (chatMessagesPin != null) { @@ -410,16 +407,16 @@ private void onDeleteMessage(ChatMessage chatMessage) { private void doDeleteMessage(ChatMessage chatMessage, UserIdentity messageAuthor) { if (chatMessage instanceof PublicTradeChatMessage) { publicTradeChannelService.deleteChatMessage((PublicTradeChatMessage) chatMessage, messageAuthor); - } else if (chatMessage instanceof PublicModeratedChatMessage) { + } else if (chatMessage instanceof PublicChatMessage) { //todo services dont do any domain specific here // -> networkService.removeAuthenticatedData(chatMessage, userIdentity.getNodeIdAndKeyPair()); publicDiscussionChannelService.findChannel(chatMessage.getChannelId()) - .ifPresent(c -> publicDiscussionChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor)); + .ifPresent(c -> publicDiscussionChannelService.deleteChatMessage((PublicChatMessage) chatMessage, messageAuthor)); publicEventsChannelService.findChannel(chatMessage.getChannelId()) - .ifPresent(c -> publicEventsChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor)); + .ifPresent(c -> publicEventsChannelService.deleteChatMessage((PublicChatMessage) chatMessage, messageAuthor)); publicSupportChannelService.findChannel(chatMessage.getChannelId()) - .ifPresent(c -> publicSupportChannelService.deleteChatMessage((PublicModeratedChatMessage) chatMessage, messageAuthor)); + .ifPresent(c -> publicSupportChannelService.deleteChatMessage((PublicChatMessage) chatMessage, messageAuthor)); } } @@ -437,9 +434,9 @@ private void onSaveEditedMessage(ChatMessage chatMessage, String editedText) { if (chatMessage instanceof PublicTradeChatMessage) { UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity().get(); publicTradeChannelService.publishEditedChatMessage((PublicTradeChatMessage) chatMessage, editedText, userIdentity); - } else if (chatMessage instanceof PublicModeratedChatMessage) { + } else if (chatMessage instanceof PublicChatMessage) { UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity().get(); - publicDiscussionChannelService.publishEditedChatMessage((PublicModeratedChatMessage) chatMessage, editedText, userIdentity); + publicDiscussionChannelService.publishEditedChatMessage((PublicChatMessage) chatMessage, editedText, userIdentity); } //todo editing private message not supported yet } @@ -454,7 +451,7 @@ private void onOpenMoreOptions(Node owner, ChatMessage chatMessage, Runnable onC items.add(new BisqPopupMenuItem(Res.get("satoshisquareapp.chat.messageMenu.copyMessage"), () -> onCopyMessage(chatMessage))); if (!isMyMessage(chatMessage)) { - if (chatMessage instanceof PublicChatMessage) { + if (chatMessage instanceof BasePublicChatMessage) { items.add(new BisqPopupMenuItem(Res.get("satoshisquareapp.chat.messageMenu.ignoreUser"), () -> onIgnoreUser(chatMessage))); } @@ -906,8 +903,8 @@ private void handleReactionsBox(ChatMessageListItem item) replyIcon.setVisible(!isMyMessage); replyIcon.setManaged(!isMyMessage); - pmIcon.setVisible(!isMyMessage && chatMessage instanceof PublicChatMessage); - pmIcon.setManaged(!isMyMessage && chatMessage instanceof PublicChatMessage); + pmIcon.setVisible(!isMyMessage && chatMessage instanceof BasePublicChatMessage); + pmIcon.setManaged(!isMyMessage && chatMessage instanceof BasePublicChatMessage); editIcon.setVisible(isMyMessage && allowEditing); editIcon.setManaged(isMyMessage && allowEditing); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index db49d34cb3..adf225819c 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -19,7 +19,6 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.*; -import bisq.chat.discuss.DiscussionChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; @@ -32,8 +31,8 @@ @Slf4j public class DiscussionsController extends ChatController implements Controller { - private final DiscussionChannelSelectionService discussionChannelSelectionService; - private final PublicModeratedChannelService publicDiscussionChannelService; + private final ChannelSelectionService discussionChannelSelectionService; + private final PublicChannelService publicDiscussionChannelService; private PublicDiscussionChannelSelection publicDiscussionChannelSelection; public DiscussionsController(DefaultApplicationService applicationService) { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index 87ea1c867e..7692d1238b 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -19,7 +19,6 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.*; -import bisq.chat.events.EventsChannelSelectionService; import bisq.chat.message.ChatMessage; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; @@ -32,8 +31,8 @@ @Slf4j public class EventsController extends ChatController implements Controller { - private final PublicModeratedChannelService publicEventsChannelService; - private final EventsChannelSelectionService eventsChannelSelectionService; + private final PublicChannelService publicEventsChannelService; + private final ChannelSelectionService eventsChannelSelectionService; private PublicEventsChannelSelection publicEventsChannelSelection; public EventsController(DefaultApplicationService applicationService) { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index 18e76e5ae4..ab8ef2c02e 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -20,7 +20,6 @@ import bisq.application.DefaultApplicationService; import bisq.chat.channel.*; import bisq.chat.message.ChatMessage; -import bisq.chat.support.SupportChannelSelectionService; import bisq.desktop.common.view.Controller; import bisq.desktop.common.view.NavigationTarget; import bisq.desktop.primary.main.content.chat.ChatController; @@ -32,8 +31,8 @@ @Slf4j public class SupportController extends ChatController implements Controller { - private final PublicModeratedChannelService publicSupportChannelService; - private final SupportChannelSelectionService supportChannelSelectionService; + private final PublicChannelService publicSupportChannelService; + private final ChannelSelectionService supportChannelSelectionService; private PublicSupportChannelSelection publicSupportChannelSelection; public SupportController(DefaultApplicationService applicationService) { diff --git a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java index 4069201644..ded0c69be2 100644 --- a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java +++ b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java @@ -1,6 +1,6 @@ package bisq.restApi.dto; -import bisq.chat.channel.PublicModeratedChannel; +import bisq.chat.channel.PublicChannel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +21,7 @@ public final class PublicDiscussionChannelDto { private String channelAdminId; private List channelModeratorIds; - public static PublicDiscussionChannelDto from(PublicModeratedChannel publicDiscussionChannel) { + public static PublicDiscussionChannelDto from(PublicChannel publicDiscussionChannel) { PublicDiscussionChannelDto dto = new PublicDiscussionChannelDto(); dto.id = publicDiscussionChannel.getId(); dto.channelName = publicDiscussionChannel.getChannelName(); From f01bb2909f3ebeb199d3349516dcaae07b41f97e Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 17:47:32 -0500 Subject: [PATCH 11/15] Fix channel id issues --- chat/src/main/java/bisq/chat/ChatService.java | 12 +- .../bisq/chat/channel/BasePrivateChannel.java | 66 +++++++ .../channel/BasePrivateChannelService.java | 181 ++++++++++++++++++ .../main/java/bisq/chat/channel/Channel.java | 6 +- .../chat/channel/ChannelSelectionService.java | 8 +- .../bisq/chat/channel/PrivateChannel.java | 91 ++++++--- .../chat/channel/PrivateChannelService.java | 170 ++++------------ ...nelStore.java => PrivateChannelStore.java} | 36 ++-- .../chat/channel/PrivateTwoPartyChannel.java | 104 ---------- .../PrivateTwoPartyChannelService.java | 95 --------- .../java/bisq/chat/channel/PublicChannel.java | 8 +- .../chat/message/BasePrivateChatMessage.java | 71 +++++++ .../java/bisq/chat/message/ChatMessage.java | 8 +- .../bisq/chat/message/PrivateChatMessage.java | 86 ++++++--- .../message/PrivateTwoPartyChatMessage.java | 101 ---------- .../chat/trade/priv/PrivateTradeChannel.java | 9 +- .../priv/PrivateTradeChannelService.java | 4 +- .../trade/priv/PrivateTradeChatMessage.java | 4 +- .../chat/trade/pub/PublicTradeChannel.java | 4 +- chat/src/main/proto/chat.proto | 29 +-- .../main/content/chat/ChatController.java | 6 +- .../chat/channels/ChannelSelection.java | 13 +- .../channels/PrivateChannelSelection.java | 32 ++-- .../components/ChatMessagesComponent.java | 14 +- .../components/ChatMessagesListView.java | 28 +-- .../discussion/DiscussionsController.java | 4 +- .../main/content/events/EventsController.java | 4 +- .../content/support/SupportController.java | 4 +- 28 files changed, 591 insertions(+), 607 deletions(-) create mode 100644 chat/src/main/java/bisq/chat/channel/BasePrivateChannel.java create mode 100644 chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java rename chat/src/main/java/bisq/chat/channel/{PrivateTwoPartyChannelStore.java => PrivateChannelStore.java} (53%) delete mode 100644 chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java delete mode 100644 chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java create mode 100644 chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java delete mode 100644 chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 05d79b8d83..17483d6cdf 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -38,15 +38,15 @@ @Getter public class ChatService implements Service { private final PrivateTradeChannelService privateTradeChannelService; - private final PrivateTwoPartyChannelService privateDiscussionChannelService; + private final PrivateChannelService privateDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final PublicChannelService publicDiscussionChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final ChannelSelectionService discussionChannelSelectionService; - private final PrivateTwoPartyChannelService privateSupportChannelService; + private final PrivateChannelService privateSupportChannelService; private final PublicChannelService publicSupportChannelService; private final ChannelSelectionService supportChannelSelectionService; - private final PrivateTwoPartyChannelService privateEventsChannelService; + private final PrivateChannelService privateEventsChannelService; private final PublicChannelService publicEventsChannelService; private final ChannelSelectionService eventsChannelSelectionService; @@ -68,7 +68,7 @@ public ChatService(PersistenceService persistenceService, publicTradeChannelService); // Discussion - privateDiscussionChannelService = new PrivateTwoPartyChannelService(persistenceService, + privateDiscussionChannelService = new PrivateChannelService(persistenceService, networkService, userIdentityService, proofOfWorkService, @@ -89,7 +89,7 @@ public ChatService(PersistenceService persistenceService, ChannelDomain.DISCUSSION); // Events - privateEventsChannelService = new PrivateTwoPartyChannelService(persistenceService, + privateEventsChannelService = new PrivateChannelService(persistenceService, networkService, userIdentityService, proofOfWorkService, @@ -110,7 +110,7 @@ public ChatService(PersistenceService persistenceService, ChannelDomain.EVENTS); // Support - privateSupportChannelService = new PrivateTwoPartyChannelService(persistenceService, + privateSupportChannelService = new PrivateChannelService(persistenceService, networkService, userIdentityService, proofOfWorkService, diff --git a/chat/src/main/java/bisq/chat/channel/BasePrivateChannel.java b/chat/src/main/java/bisq/chat/channel/BasePrivateChannel.java new file mode 100644 index 0000000000..ed7a5b0806 --- /dev/null +++ b/chat/src/main/java/bisq/chat/channel/BasePrivateChannel.java @@ -0,0 +1,66 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.chat.channel; + +import bisq.chat.message.BasePrivateChatMessage; +import bisq.common.data.ByteArray; +import bisq.common.data.Pair; +import bisq.common.observable.ObservableArray; +import bisq.user.identity.UserIdentity; +import bisq.user.profile.UserProfile; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +import java.util.Comparator; +import java.util.List; + +@Getter +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) +public abstract class BasePrivateChannel extends Channel { + + public static String createChannelName(Pair userIds) { + String userId1 = userIds.getFirst(); + String userId2 = userIds.getSecond(); + if (userId1.compareTo(userId2) < 0) { + return userId1 + "-" + userId2; + } else { + return userId2 + "-" + userId1; + } + } + + protected final UserIdentity myUserIdentity; + + // We persist the messages as they are NOT persisted in the P2P data store. + protected final ObservableArray chatMessages = new ObservableArray<>(); + + public BasePrivateChannel(ChannelDomain channelDomain, + String channelName, + UserIdentity myUserIdentity, + List chatMessages, + ChannelNotificationType channelNotificationType) { + super(channelDomain, channelName, channelNotificationType); + + this.myUserIdentity = myUserIdentity; + this.chatMessages.addAll(chatMessages); + this.chatMessages.sort(Comparator.comparing((T e) -> new ByteArray(e.serialize()))); + } + + public abstract UserProfile getPeer(); +} diff --git a/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java new file mode 100644 index 0000000000..eaa88c9fe4 --- /dev/null +++ b/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java @@ -0,0 +1,181 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.chat.channel; + +import bisq.chat.message.BasePrivateChatMessage; +import bisq.chat.message.MessageType; +import bisq.chat.message.Quotation; +import bisq.common.util.StringUtils; +import bisq.i18n.Res; +import bisq.network.NetworkId; +import bisq.network.NetworkIdWithKeyPair; +import bisq.network.NetworkService; +import bisq.network.p2p.services.confidential.MessageListener; +import bisq.persistence.PersistableStore; +import bisq.security.pow.ProofOfWorkService; +import bisq.user.identity.UserIdentity; +import bisq.user.identity.UserIdentityService; +import bisq.user.profile.UserProfile; +import lombok.extern.slf4j.Slf4j; + +import java.util.Date; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +@Slf4j +public abstract class BasePrivateChannelService, S extends PersistableStore> + extends ChannelService implements MessageListener { + protected final ProofOfWorkService proofOfWorkService; + + public BasePrivateChannelService(NetworkService networkService, + UserIdentityService userIdentityService, + ProofOfWorkService proofOfWorkService, + ChannelDomain channelDomain) { + super(networkService, userIdentityService, channelDomain); + this.proofOfWorkService = proofOfWorkService; + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Service + /////////////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public CompletableFuture initialize() { + log.info("initialize"); + networkService.addMessageListener(this); + return CompletableFuture.completedFuture(true); + } + + @Override + public CompletableFuture shutdown() { + log.info("shutdown"); + networkService.removeMessageListener(this); + return CompletableFuture.completedFuture(true); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////////////// + + public Optional maybeCreateAndAddChannel(UserProfile peer) { + return Optional.ofNullable(userIdentityService.getSelectedUserIdentity().get()) + .flatMap(myUserIdentity -> maybeCreateAndAddChannel(peer, myUserIdentity.getId())); + } + + protected CompletableFuture sendLeaveMessage(C channel) { + return sendPrivateChatMessage(Res.get("social.privateChannel.leave.message", channel.getMyUserIdentity().getUserProfile().getUserName()), + Optional.empty(), + channel, + MessageType.LEAVE); + } + + public CompletableFuture sendPrivateChatMessage(String text, + Optional quotedMessage, + C channel) { + return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer(), MessageType.TEXT); + } + + public CompletableFuture sendPrivateChatMessage(String text, + Optional quotedMessage, + C channel, + MessageType messageType) { + return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer(), messageType); + } + + protected CompletableFuture sendPrivateChatMessage(String messageId, + String text, + Optional quotedMessage, + C channel, + UserIdentity senderIdentity, + UserProfile receiver, + MessageType messageType) { + M chatMessage = createNewPrivateChatMessage(messageId, + channel, + senderIdentity.getUserProfile(), + receiver.getId(), + text, + quotedMessage, + new Date().getTime(), + false, + messageType); + addMessage(chatMessage, channel); + NetworkId receiverNetworkId = receiver.getNetworkId(); + NetworkIdWithKeyPair senderNetworkIdWithKeyPair = senderIdentity.getNodeIdAndKeyPair(); + return networkService.confidentialSend(chatMessage, receiverNetworkId, senderNetworkIdWithKeyPair); + } + + public void removeExpiredMessages(C channel) { + Set toRemove = channel.getChatMessages().stream() + .filter(BasePrivateChatMessage::isExpired) + .collect(Collectors.toSet()); + if (!toRemove.isEmpty()) { + synchronized (getPersistableStore()) { + channel.removeChatMessages(toRemove); + } + persist(); + } + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Protected + /////////////////////////////////////////////////////////////////////////////////////////////////// + + protected Optional maybeCreateAndAddChannel(UserProfile peer, String myUserIdentityId) { + return userIdentityService.findUserIdentity(myUserIdentityId) + .map(myUserIdentity -> { + Optional existingChannel = getChannels().stream() + .filter(channel -> channel.getMyUserIdentity().equals(myUserIdentity) && + channel.getPeer().equals(peer)) + .findAny(); + if (existingChannel.isPresent()) { + return existingChannel.get(); + } + + C channel = createNewChannel(peer, myUserIdentity); + getChannels().add(channel); + persist(); + return channel; + } + ); + } + + protected abstract C createNewChannel(UserProfile peer, UserIdentity myUserIdentity); + + protected abstract M createNewPrivateChatMessage(String messageId, + C channel, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long time, + boolean wasEdited, + MessageType messageType); + + protected void processMessage(M message) { + if (!userIdentityService.isUserIdentityPresent(message.getAuthorId())) { + findChannel(message.getChannelId()) + .or(() -> maybeCreateAndAddChannel(message.getSender(), message.getReceiversId())) + .ifPresent(channel -> addMessage(message, channel)); + } + } +} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index cc84bd67c8..d45395a8bb 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -52,7 +52,7 @@ public Channel(ChannelDomain channelDomain, String channelName, ChannelNotificat public bisq.chat.protobuf.Channel.Builder getChannelBuilder() { return bisq.chat.protobuf.Channel.newBuilder() - .setId(id) + .setChannelName(channelName) .setChannelDomain(channelDomain.toProto()) .setChannelNotificationType(channelNotificationType.get().toProto()); } @@ -61,8 +61,8 @@ public bisq.chat.protobuf.Channel.Builder getChannelBuilder() { public static Channel fromProto(bisq.chat.protobuf.Channel proto) { switch (proto.getMessageCase()) { - case PRIVATETWOPARTYCHANNEL: { - return PrivateTwoPartyChannel.fromProto(proto, proto.getPrivateTwoPartyChannel()); + case PRIVATECHANNEL: { + return PrivateChannel.fromProto(proto, proto.getPrivateChannel()); } case PRIVATETRADECHANNEL: { diff --git a/chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java b/chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java index 16d88569d4..19d001793b 100644 --- a/chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelSelectionService.java @@ -34,11 +34,11 @@ public class ChannelSelectionService implements PersistenceClient { private final ChannelSelectionStore persistableStore = new ChannelSelectionStore(); private final Persistence persistence; - private final PrivateTwoPartyChannelService privateChannelService; + private final PrivateChannelService privateChannelService; private final PublicChannelService publicChannelService; public ChannelSelectionService(PersistenceService persistenceService, - PrivateTwoPartyChannelService privateChannelService, + PrivateChannelService privateChannelService, PublicChannelService publicChannelService, ChannelDomain channelDomain) { persistence = persistenceService.getOrCreatePersistence(this, @@ -61,8 +61,8 @@ public CompletableFuture shutdown() { } public void selectChannel(Channel channel) { - if (channel instanceof PrivateTwoPartyChannel) { - privateChannelService.removeExpiredMessages((PrivateTwoPartyChannel) channel); + if (channel instanceof PrivateChannel) { + privateChannelService.removeExpiredMessages((PrivateChannel) channel); } getSelectedChannel().set(channel); diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index 7192c0cd3d..dc1bd87b55 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -18,49 +18,86 @@ package bisq.chat.channel; import bisq.chat.message.PrivateChatMessage; -import bisq.common.data.ByteArray; import bisq.common.data.Pair; -import bisq.common.observable.ObservableArray; import bisq.user.identity.UserIdentity; import bisq.user.profile.UserProfile; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; -import java.util.Comparator; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; -@Getter @ToString(callSuper = true) +@Getter @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public abstract class PrivateChannel extends Channel { +public final class PrivateChannel extends BasePrivateChannel { + private final UserProfile peer; - public static String createChannelName(Pair userIds) { - String userId1 = userIds.getFirst(); - String userId2 = userIds.getSecond(); - if (userId1.compareTo(userId2) < 0) { - return userId1 + "-" + userId2; - } else { - return userId2 + "-" + userId1; - } + public PrivateChannel(UserProfile peer, UserIdentity myUserIdentity, ChannelDomain channelDomain) { + this(channelDomain, + BasePrivateChannel.createChannelName(new Pair<>(peer.getId(), myUserIdentity.getId())), + peer, + myUserIdentity, + new ArrayList<>(), + ChannelNotificationType.ALL + ); } - protected final UserIdentity myUserIdentity; + private PrivateChannel(ChannelDomain channelDomain, + String channelName, + UserProfile peer, + UserIdentity myProfile, + List chatMessages, + ChannelNotificationType channelNotificationType) { + super(channelDomain, channelName, myProfile, chatMessages, channelNotificationType); + + this.peer = peer; + } - // We persist the messages as they are NOT persisted in the P2P data store. - protected final ObservableArray chatMessages = new ObservableArray<>(); + @Override + public bisq.chat.protobuf.Channel toProto() { + return getChannelBuilder().setPrivateChannel(bisq.chat.protobuf.PrivateChannel.newBuilder() + .setPeer(peer.toProto()) + .setMyUserIdentity(myUserIdentity.toProto()) + .addAllChatMessages(chatMessages.stream() + .map(PrivateChatMessage::toChatMessageProto) + .collect(Collectors.toList()))) + .build(); + } - public PrivateChannel(ChannelDomain channelDomain, - String channelName, - UserIdentity myUserIdentity, - List chatMessages, - ChannelNotificationType channelNotificationType) { - super(channelDomain, channelName, channelNotificationType); + public static PrivateChannel fromProto(bisq.chat.protobuf.Channel baseProto, + bisq.chat.protobuf.PrivateChannel proto) { + return new PrivateChannel(ChannelDomain.fromProto(baseProto.getChannelDomain()), + baseProto.getChannelName(), + UserProfile.fromProto(proto.getPeer()), + UserIdentity.fromProto(proto.getMyUserIdentity()), + proto.getChatMessagesList().stream() + .map(PrivateChatMessage::fromProto) + .collect(Collectors.toList()), + ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()) + ); + } - this.myUserIdentity = myUserIdentity; - this.chatMessages.addAll(chatMessages); - this.chatMessages.sort(Comparator.comparing((T e) -> new ByteArray(e.serialize()))); + @Override + public void addChatMessage(PrivateChatMessage chatMessage) { + chatMessages.add(chatMessage); } - public abstract UserProfile getPeer(); -} + @Override + public void removeChatMessage(PrivateChatMessage chatMessage) { + chatMessages.remove(chatMessage); + } + + @Override + public void removeChatMessages(Collection removeMessages) { + chatMessages.removeAll(removeMessages); + } + + @Override + public String getDisplayString() { + return peer.getUserName() + "-" + myUserIdentity.getUserName(); + } +} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index 2486216a99..a41c419392 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -20,162 +20,76 @@ import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; +import bisq.common.observable.ObservableArray; import bisq.common.util.StringUtils; -import bisq.i18n.Res; -import bisq.network.NetworkId; -import bisq.network.NetworkIdWithKeyPair; import bisq.network.NetworkService; -import bisq.network.p2p.services.confidential.MessageListener; -import bisq.persistence.PersistableStore; +import bisq.network.p2p.message.NetworkMessage; +import bisq.persistence.Persistence; +import bisq.persistence.PersistenceService; import bisq.security.pow.ProofOfWorkService; import bisq.user.identity.UserIdentity; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import java.util.Date; import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; @Slf4j -public abstract class PrivateChannelService, S extends PersistableStore> - extends ChannelService implements MessageListener { - protected final ProofOfWorkService proofOfWorkService; - - public PrivateChannelService(NetworkService networkService, +public class PrivateChannelService extends BasePrivateChannelService { + @Getter + private final PrivateChannelStore persistableStore = new PrivateChannelStore(); + @Getter + private final Persistence persistence; + + public PrivateChannelService(PersistenceService persistenceService, + NetworkService networkService, UserIdentityService userIdentityService, ProofOfWorkService proofOfWorkService, ChannelDomain channelDomain) { - super(networkService, userIdentityService, channelDomain); - this.proofOfWorkService = proofOfWorkService; + super(networkService, userIdentityService, proofOfWorkService, channelDomain); + persistence = persistenceService.getOrCreatePersistence(this, + "db", + "Private" + StringUtils.capitalize(channelDomain.name()) + "ChannelStore", + persistableStore); } - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // Service - /////////////////////////////////////////////////////////////////////////////////////////////////// - @Override - public CompletableFuture initialize() { - log.info("initialize"); - networkService.addMessageListener(this); - return CompletableFuture.completedFuture(true); + public void onMessage(NetworkMessage networkMessage) { + if (networkMessage instanceof PrivateChatMessage) { + processMessage((PrivateChatMessage) networkMessage); + } } @Override - public CompletableFuture shutdown() { - log.info("shutdown"); - networkService.removeMessageListener(this); - return CompletableFuture.completedFuture(true); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // API - /////////////////////////////////////////////////////////////////////////////////////////////////// - - public Optional maybeCreateAndAddChannel(UserProfile peer) { - return Optional.ofNullable(userIdentityService.getSelectedUserIdentity().get()) - .flatMap(myUserIdentity -> maybeCreateAndAddChannel(peer, myUserIdentity.getId())); - } - - protected CompletableFuture sendLeaveMessage(C channel) { - return sendPrivateChatMessage(Res.get("social.privateChannel.leave.message", channel.getMyUserIdentity().getUserProfile().getUserName()), - Optional.empty(), - channel, - MessageType.LEAVE); - } - - public CompletableFuture sendPrivateChatMessage(String text, - Optional quotedMessage, - C channel) { - return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer(), MessageType.TEXT); - } - - public CompletableFuture sendPrivateChatMessage(String text, - Optional quotedMessage, - C channel, - MessageType messageType) { - return sendPrivateChatMessage(StringUtils.createShortUid(), text, quotedMessage, channel, channel.getMyUserIdentity(), channel.getPeer(), messageType); - } - - protected CompletableFuture sendPrivateChatMessage(String messageId, - String text, - Optional quotedMessage, - C channel, - UserIdentity senderIdentity, - UserProfile receiver, - MessageType messageType) { - M chatMessage = createNewPrivateChatMessage(messageId, - channel, - senderIdentity.getUserProfile(), - receiver.getId(), + protected PrivateChatMessage createNewPrivateChatMessage(String messageId, + PrivateChannel channel, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long time, + boolean wasEdited, + MessageType messageType) { + return new PrivateChatMessage(messageId, + channel.getId(), + sender, + receiversId, text, quotedMessage, new Date().getTime(), - false, + wasEdited, messageType); - addMessage(chatMessage, channel); - NetworkId receiverNetworkId = receiver.getNetworkId(); - NetworkIdWithKeyPair senderNetworkIdWithKeyPair = senderIdentity.getNodeIdAndKeyPair(); - return networkService.confidentialSend(chatMessage, receiverNetworkId, senderNetworkIdWithKeyPair); } - public void removeExpiredMessages(C channel) { - Set toRemove = channel.getChatMessages().stream() - .filter(PrivateChatMessage::isExpired) - .collect(Collectors.toSet()); - if (!toRemove.isEmpty()) { - synchronized (getPersistableStore()) { - channel.removeChatMessages(toRemove); - } - persist(); - } - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////// - // Protected - /////////////////////////////////////////////////////////////////////////////////////////////////// - - protected Optional maybeCreateAndAddChannel(UserProfile peer, String myUserIdentityId) { - return userIdentityService.findUserIdentity(myUserIdentityId) - .map(myUserIdentity -> { - Optional existingChannel = getChannels().stream() - .filter(channel -> channel.getMyUserIdentity().equals(myUserIdentity) && - channel.getPeer().equals(peer)) - .findAny(); - if (existingChannel.isPresent()) { - return existingChannel.get(); - } - - C channel = createNewChannel(peer, myUserIdentity); - getChannels().add(channel); - persist(); - return channel; - } - ); + @Override + protected PrivateChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { + return new PrivateChannel(peer, myUserIdentity, channelDomain); } - protected abstract C createNewChannel(UserProfile peer, UserIdentity myUserIdentity); - - protected abstract M createNewPrivateChatMessage(String messageId, - C channel, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long time, - boolean wasEdited, - MessageType messageType); - - protected void processMessage(M message) { - if (!userIdentityService.isUserIdentityPresent(message.getAuthorId())) { - findChannel(message.getChannelId()) - .or(() -> maybeCreateAndAddChannel(message.getSender(), message.getReceiversId())) - .ifPresent(channel -> addMessage(message, channel)); - } + @Override + public ObservableArray getChannels() { + return persistableStore.getChannels(); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelStore.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelStore.java similarity index 53% rename from chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelStore.java rename to chat/src/main/java/bisq/chat/channel/PrivateChannelStore.java index 969423c3a6..5c46b7918a 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelStore.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelStore.java @@ -28,35 +28,35 @@ import java.util.stream.Collectors; @Getter -public class PrivateTwoPartyChannelStore implements PersistableStore { - private final ObservableArray channels = new ObservableArray<>(); +public class PrivateChannelStore implements PersistableStore { + private final ObservableArray channels = new ObservableArray<>(); - public PrivateTwoPartyChannelStore() { + public PrivateChannelStore() { } - private PrivateTwoPartyChannelStore(List privateTwoPartyChannels) { - setAll(privateTwoPartyChannels); + private PrivateChannelStore(List privateChannels) { + setAll(privateChannels); } @Override - public bisq.chat.protobuf.PrivateTwoPartyChannelStore toProto() { - bisq.chat.protobuf.PrivateTwoPartyChannelStore.Builder builder = bisq.chat.protobuf.PrivateTwoPartyChannelStore.newBuilder() - .addAllChannels(channels.stream().map(PrivateTwoPartyChannel::toProto).collect(Collectors.toList())); + public bisq.chat.protobuf.PrivateChannelStore toProto() { + bisq.chat.protobuf.PrivateChannelStore.Builder builder = bisq.chat.protobuf.PrivateChannelStore.newBuilder() + .addAllChannels(channels.stream().map(PrivateChannel::toProto).collect(Collectors.toList())); return builder.build(); } - public static PrivateTwoPartyChannelStore fromProto(bisq.chat.protobuf.PrivateTwoPartyChannelStore proto) { - List privateTwoPartyChannels = proto.getChannelsList().stream() - .map(e -> (PrivateTwoPartyChannel) PrivateTwoPartyChannel.fromProto(e)) + public static PrivateChannelStore fromProto(bisq.chat.protobuf.PrivateChannelStore proto) { + List privateChannels = proto.getChannelsList().stream() + .map(e -> (PrivateChannel) PrivateChannel.fromProto(e)) .collect(Collectors.toList()); - return new PrivateTwoPartyChannelStore(privateTwoPartyChannels); + return new PrivateChannelStore(privateChannels); } @Override public ProtoResolver> getResolver() { return any -> { try { - return fromProto(any.unpack(bisq.chat.protobuf.PrivateTwoPartyChannelStore.class)); + return fromProto(any.unpack(bisq.chat.protobuf.PrivateChannelStore.class)); } catch (InvalidProtocolBufferException e) { throw new UnresolvableProtobufMessageException(e); } @@ -64,17 +64,17 @@ public ProtoResolver> getResolver() { } @Override - public void applyPersisted(PrivateTwoPartyChannelStore chatStore) { + public void applyPersisted(PrivateChannelStore chatStore) { setAll(chatStore.getChannels()); } @Override - public PrivateTwoPartyChannelStore getClone() { - return new PrivateTwoPartyChannelStore(channels); + public PrivateChannelStore getClone() { + return new PrivateChannelStore(channels); } - public void setAll(List privateTwoPartyChannels) { + public void setAll(List privateChannels) { this.channels.clear(); - this.channels.addAll(privateTwoPartyChannels); + this.channels.addAll(privateChannels); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java deleted file mode 100644 index 47a901907b..0000000000 --- a/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannel.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.channel; - -import bisq.chat.message.PrivateTwoPartyChatMessage; -import bisq.common.data.Pair; -import bisq.user.identity.UserIdentity; -import bisq.user.profile.UserProfile; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -@ToString(callSuper = true) -@Getter -@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PrivateTwoPartyChannel extends PrivateChannel { - private final UserProfile peer; - - public PrivateTwoPartyChannel(UserProfile peer, UserIdentity myUserIdentity, ChannelDomain channelDomain) { - this(channelDomain, - PrivateChannel.createChannelName(new Pair<>(peer.getId(), myUserIdentity.getId())), - peer, - myUserIdentity, - new ArrayList<>(), - ChannelNotificationType.ALL - ); - } - - private PrivateTwoPartyChannel(ChannelDomain channelDomain, - String channelName, - UserProfile peer, - UserIdentity myProfile, - List chatMessages, - ChannelNotificationType channelNotificationType) { - super(channelDomain, channelName, myProfile, chatMessages, channelNotificationType); - - this.peer = peer; - } - - @Override - public bisq.chat.protobuf.Channel toProto() { - return getChannelBuilder().setPrivateTwoPartyChannel(bisq.chat.protobuf.PrivateTwoPartyChannel.newBuilder() - .setPeer(peer.toProto()) - .setMyUserIdentity(myUserIdentity.toProto()) - .addAllChatMessages(chatMessages.stream() - .map(PrivateTwoPartyChatMessage::toChatMessageProto) - .collect(Collectors.toList()))) - .build(); - } - - public static PrivateTwoPartyChannel fromProto(bisq.chat.protobuf.Channel baseProto, - bisq.chat.protobuf.PrivateTwoPartyChannel proto) { - return new PrivateTwoPartyChannel( - ChannelDomain.fromProto(baseProto.getChannelDomain()), - baseProto.getId(), - UserProfile.fromProto(proto.getPeer()), - UserIdentity.fromProto(proto.getMyUserIdentity()), - proto.getChatMessagesList().stream() - .map(PrivateTwoPartyChatMessage::fromProto) - .collect(Collectors.toList()), - ChannelNotificationType.fromProto(baseProto.getChannelNotificationType()) - ); - } - - @Override - public void addChatMessage(PrivateTwoPartyChatMessage chatMessage) { - chatMessages.add(chatMessage); - } - - @Override - public void removeChatMessage(PrivateTwoPartyChatMessage chatMessage) { - chatMessages.remove(chatMessage); - } - - @Override - public void removeChatMessages(Collection removeMessages) { - chatMessages.removeAll(removeMessages); - } - - @Override - public String getDisplayString() { - return peer.getUserName() + "-" + myUserIdentity.getUserName(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java deleted file mode 100644 index dec2a3818b..0000000000 --- a/chat/src/main/java/bisq/chat/channel/PrivateTwoPartyChannelService.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.channel; - -import bisq.chat.message.MessageType; -import bisq.chat.message.PrivateTwoPartyChatMessage; -import bisq.chat.message.Quotation; -import bisq.common.observable.ObservableArray; -import bisq.common.util.StringUtils; -import bisq.network.NetworkService; -import bisq.network.p2p.message.NetworkMessage; -import bisq.persistence.Persistence; -import bisq.persistence.PersistenceService; -import bisq.security.pow.ProofOfWorkService; -import bisq.user.identity.UserIdentity; -import bisq.user.identity.UserIdentityService; -import bisq.user.profile.UserProfile; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.Date; -import java.util.Optional; - -@Slf4j -public class PrivateTwoPartyChannelService extends PrivateChannelService { - @Getter - private final PrivateTwoPartyChannelStore persistableStore = new PrivateTwoPartyChannelStore(); - @Getter - private final Persistence persistence; - - public PrivateTwoPartyChannelService(PersistenceService persistenceService, - NetworkService networkService, - UserIdentityService userIdentityService, - ProofOfWorkService proofOfWorkService, - ChannelDomain channelDomain) { - super(networkService, userIdentityService, proofOfWorkService, channelDomain); - persistence = persistenceService.getOrCreatePersistence(this, - "db", - "Private" + StringUtils.capitalize(channelDomain.name()) + "ChannelStore", - persistableStore); - } - - @Override - public void onMessage(NetworkMessage networkMessage) { - if (networkMessage instanceof PrivateTwoPartyChatMessage) { - processMessage((PrivateTwoPartyChatMessage) networkMessage); - } - } - - @Override - protected PrivateTwoPartyChatMessage createNewPrivateChatMessage(String messageId, - PrivateTwoPartyChannel channel, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long time, - boolean wasEdited, - MessageType messageType) { - return new PrivateTwoPartyChatMessage(messageId, - channel.getId(), - sender, - receiversId, - text, - quotedMessage, - new Date().getTime(), - wasEdited, - messageType); - } - - @Override - protected PrivateTwoPartyChannel createNewChannel(UserProfile peer, UserIdentity myUserIdentity) { - return new PrivateTwoPartyChannel(peer, myUserIdentity, channelDomain); - } - - @Override - public ObservableArray getChannels() { - return persistableStore.getChannels(); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannel.java b/chat/src/main/java/bisq/chat/channel/PublicChannel.java index 433d4b3328..23a75c0a50 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannel.java @@ -53,8 +53,7 @@ private PublicChannel(ChannelDomain channelDomain, String description, String channelAdminId, List channelModeratorIds, - ChannelNotificationType channelNotificationType - ) { + ChannelNotificationType channelNotificationType) { super(channelDomain, channelName, channelNotificationType); this.displayName = displayName; @@ -77,9 +76,8 @@ public bisq.chat.protobuf.Channel toProto() { public static PublicChannel fromProto(bisq.chat.protobuf.Channel baseProto, bisq.chat.protobuf.PublicChannel proto) { - return new PublicChannel( - ChannelDomain.fromProto(baseProto.getChannelDomain()), - baseProto.getId(), + return new PublicChannel(ChannelDomain.fromProto(baseProto.getChannelDomain()), + baseProto.getChannelName(), proto.getChannelName(), proto.getDescription(), proto.getChannelAdminId(), diff --git a/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java b/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java new file mode 100644 index 0000000000..4955dbdc70 --- /dev/null +++ b/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java @@ -0,0 +1,71 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.chat.message; + +import bisq.network.p2p.services.data.storage.MetaData; +import bisq.network.p2p.services.data.storage.mailbox.MailboxMessage; +import bisq.user.profile.UserProfile; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +import java.util.Optional; + +/** + * PrivateChatMessage is sent as direct message to peer and in case peer is not online it can be stores as + * mailbox message. + */ +@Getter +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public abstract class BasePrivateChatMessage extends ChatMessage implements MailboxMessage { + protected final String receiversId; + protected final UserProfile sender; + + protected BasePrivateChatMessage(String messageId, + String channelId, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType, + MetaData metaData) { + super(messageId, + channelId, + sender.getId(), + Optional.of(text), + quotedMessage, + date, + wasEdited, + messageType, + metaData); + this.receiversId = receiversId; + this.sender = sender; + } + + @Override + public MetaData getMetaData() { + return metaData; + } + + public boolean isExpired() { + return (System.currentTimeMillis() - getDate() > getMetaData().getTtl()); + } +} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 41b8c875c2..35e088bccf 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -92,8 +92,8 @@ public bisq.chat.protobuf.ChatMessage.Builder getChatMessageBuilder() { public static ChatMessage fromProto(bisq.chat.protobuf.ChatMessage proto) { switch (proto.getMessageCase()) { - case PRIVATETWOPARTYCHATMESSAGE: { - return PrivateTwoPartyChatMessage.fromProto(proto); + case PRIVATECHATMESSAGE: { + return PrivateChatMessage.fromProto(proto); } case PUBLICTRADECHATMESSAGE: { @@ -141,8 +141,8 @@ public static ProtoResolver getNetworkM try { bisq.chat.protobuf.ChatMessage proto = any.unpack(bisq.chat.protobuf.ChatMessage.class); switch (proto.getMessageCase()) { - case PRIVATETWOPARTYCHATMESSAGE: { - return PrivateTwoPartyChatMessage.fromProto(proto); + case PRIVATECHATMESSAGE: { + return PrivateChatMessage.fromProto(proto); } case PRIVATETRADECHATMESSAGE: { diff --git a/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java b/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java index 87426c447e..7190616b61 100644 --- a/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java @@ -18,54 +18,84 @@ package bisq.chat.message; import bisq.network.p2p.services.data.storage.MetaData; -import bisq.network.p2p.services.data.storage.mailbox.MailboxMessage; +import bisq.network.protobuf.ExternalNetworkMessage; +import bisq.network.protobuf.NetworkMessage; import bisq.user.profile.UserProfile; +import com.google.protobuf.Any; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; import java.util.Optional; -/** - * PrivateChatMessage is sent as direct message to peer and in case peer is not online it can be stores as - * mailbox message. - */ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public abstract class PrivateChatMessage extends ChatMessage implements MailboxMessage { - protected final String receiversId; - protected final UserProfile sender; - - protected PrivateChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { +public final class PrivateChatMessage extends BasePrivateChatMessage { + public PrivateChatMessage(String messageId, + String channelId, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType) { super(messageId, channelId, - sender.getId(), - Optional.of(text), + sender, + receiversId, + text, quotedMessage, date, wasEdited, messageType, - metaData); - this.receiversId = receiversId; - this.sender = sender; + new MetaData(ChatMessage.TTL, 100000, PrivateChatMessage.class.getSimpleName())); + } + + private PrivateChatMessage(String messageId, + String channelId, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + MessageType messageType, + MetaData metaData) { + super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); } @Override - public MetaData getMetaData() { - return metaData; + public NetworkMessage toProto() { + return getNetworkMessageBuilder() + .setExternalNetworkMessage(ExternalNetworkMessage.newBuilder().setAny(Any.pack(toChatMessageProto()))) + .build(); } - public boolean isExpired() { - return (System.currentTimeMillis() - getDate() > getMetaData().getTtl()); + public bisq.chat.protobuf.ChatMessage toChatMessageProto() { + return getChatMessageBuilder() + .setPrivateChatMessage(bisq.chat.protobuf.PrivateChatMessage.newBuilder() + .setReceiversId(receiversId) + .setSender(sender.toProto())) + .build(); + } + + public static PrivateChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { + Optional quotedMessage = baseProto.hasQuotation() ? + Optional.of(Quotation.fromProto(baseProto.getQuotation())) : + Optional.empty(); + bisq.chat.protobuf.PrivateChatMessage privateChatMessage = baseProto.getPrivateChatMessage(); + return new PrivateChatMessage( + baseProto.getMessageId(), + baseProto.getChannelId(), + UserProfile.fromProto(privateChatMessage.getSender()), + privateChatMessage.getReceiversId(), + baseProto.getText(), + quotedMessage, + baseProto.getDate(), + baseProto.getWasEdited(), + MessageType.fromProto(baseProto.getMessageType()), + MetaData.fromProto(baseProto.getMetaData())); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java b/chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java deleted file mode 100644 index b5436776b1..0000000000 --- a/chat/src/main/java/bisq/chat/message/PrivateTwoPartyChatMessage.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.chat.message; - -import bisq.network.p2p.services.data.storage.MetaData; -import bisq.network.protobuf.ExternalNetworkMessage; -import bisq.network.protobuf.NetworkMessage; -import bisq.user.profile.UserProfile; -import com.google.protobuf.Any; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -import java.util.Optional; - -@Getter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public final class PrivateTwoPartyChatMessage extends PrivateChatMessage { - public PrivateTwoPartyChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType) { - super(messageId, - channelId, - sender, - receiversId, - text, - quotedMessage, - date, - wasEdited, - messageType, - new MetaData(ChatMessage.TTL, 100000, PrivateTwoPartyChatMessage.class.getSimpleName())); - } - - private PrivateTwoPartyChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - MessageType messageType, - MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); - } - - @Override - public NetworkMessage toProto() { - return getNetworkMessageBuilder() - .setExternalNetworkMessage(ExternalNetworkMessage.newBuilder().setAny(Any.pack(toChatMessageProto()))) - .build(); - } - - public bisq.chat.protobuf.ChatMessage toChatMessageProto() { - return getChatMessageBuilder() - .setPrivateTwoPartyChatMessage(bisq.chat.protobuf.PrivateTwoPartyChatMessage.newBuilder() - .setReceiversId(receiversId) - .setSender(sender.toProto())) - .build(); - } - - public static PrivateTwoPartyChatMessage fromProto(bisq.chat.protobuf.ChatMessage baseProto) { - Optional quotedMessage = baseProto.hasQuotation() ? - Optional.of(Quotation.fromProto(baseProto.getQuotation())) : - Optional.empty(); - bisq.chat.protobuf.PrivateTwoPartyChatMessage privateTwoPartyChatMessage = baseProto.getPrivateTwoPartyChatMessage(); - return new PrivateTwoPartyChatMessage( - baseProto.getMessageId(), - baseProto.getChannelId(), - UserProfile.fromProto(privateTwoPartyChatMessage.getSender()), - privateTwoPartyChatMessage.getReceiversId(), - baseProto.getText(), - quotedMessage, - baseProto.getDate(), - baseProto.getWasEdited(), - MessageType.fromProto(baseProto.getMessageType()), - MetaData.fromProto(baseProto.getMetaData())); - } -} \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index b88f69d124..a4010fa12e 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -17,9 +17,9 @@ package bisq.chat.trade.priv; +import bisq.chat.channel.BasePrivateChannel; import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; -import bisq.chat.channel.PrivateChannel; import bisq.common.data.Pair; import bisq.common.observable.Observable; import bisq.i18n.Res; @@ -43,7 +43,7 @@ @ToString(callSuper = true) @Getter @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) -public final class PrivateTradeChannel extends PrivateChannel { +public final class PrivateTradeChannel extends BasePrivateChannel { public static PrivateTradeChannel createByTrader(UserIdentity myUserIdentity, UserProfile peer, Optional mediator) { @@ -72,7 +72,7 @@ private PrivateTradeChannel(UserProfile peerOrTrader1, UserProfile myUserProfileOrTrader2, UserIdentity myUserIdentity, Optional mediator) { - this(PrivateChannel.createChannelName(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), + this(BasePrivateChannel.createChannelName(new Pair<>(peerOrTrader1.getId(), myUserProfileOrTrader2.getId())), peerOrTrader1, myUserProfileOrTrader2, myUserIdentity, @@ -112,8 +112,7 @@ public bisq.chat.protobuf.Channel toProto() { public static PrivateTradeChannel fromProto(bisq.chat.protobuf.Channel baseProto, bisq.chat.protobuf.PrivateTradeChannel proto) { - PrivateTradeChannel privateTradeChannel = new PrivateTradeChannel( - baseProto.getId(), + PrivateTradeChannel privateTradeChannel = new PrivateTradeChannel(baseProto.getChannelName(), UserProfile.fromProto(proto.getPeerOrTrader1()), UserProfile.fromProto(proto.getMyUserProfileOrTrader2()), UserIdentity.fromProto(proto.getMyUserIdentity()), diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index a49b3cb37a..75104a7dfe 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -17,8 +17,8 @@ package bisq.chat.trade.priv; +import bisq.chat.channel.BasePrivateChannelService; import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannelService; import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; import bisq.common.data.Pair; @@ -42,7 +42,7 @@ import java.util.concurrent.CompletableFuture; @Slf4j -public class PrivateTradeChannelService extends PrivateChannelService { +public class PrivateTradeChannelService extends BasePrivateChannelService { @Getter private final PrivateTradeChannelStore persistableStore = new PrivateTradeChannelStore(); @Getter diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java index 3ca6c67d1e..a7caa9b3e6 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java @@ -17,8 +17,8 @@ package bisq.chat.trade.priv; +import bisq.chat.message.BasePrivateChatMessage; import bisq.chat.message.MessageType; -import bisq.chat.message.PrivateChatMessage; import bisq.chat.message.Quotation; import bisq.network.p2p.services.data.storage.MetaData; import bisq.network.protobuf.ExternalNetworkMessage; @@ -34,7 +34,7 @@ @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public final class PrivateTradeChatMessage extends PrivateChatMessage { +public final class PrivateTradeChatMessage extends BasePrivateChatMessage { private final Optional mediator; public PrivateTradeChatMessage(String messageId, diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index 490dd3bb76..9285a678fe 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -44,6 +44,7 @@ private PublicTradeChannel(String channelName, Market market) { this.market = market; } + @Override public bisq.chat.protobuf.Channel toProto() { return getChannelBuilder().setPublicTradeChannel(bisq.chat.protobuf.PublicTradeChannel.newBuilder() @@ -53,8 +54,7 @@ public bisq.chat.protobuf.Channel toProto() { public static PublicTradeChannel fromProto(bisq.chat.protobuf.Channel baseProto, bisq.chat.protobuf.PublicTradeChannel proto) { - return new PublicTradeChannel(baseProto.getId(), - Market.fromProto(proto.getMarket())); + return new PublicTradeChannel(baseProto.getChannelName(), Market.fromProto(proto.getMarket())); } @Override diff --git a/chat/src/main/proto/chat.proto b/chat/src/main/proto/chat.proto index 3c2178a943..eec8291361 100644 --- a/chat/src/main/proto/chat.proto +++ b/chat/src/main/proto/chat.proto @@ -62,38 +62,36 @@ message ChatMessage { MessageType messageType = 8; network.MetaData metaData = 9; oneof message { - PrivateTwoPartyChatMessage privateTwoPartyChatMessage = 20; + PrivateChatMessage privateChatMessage = 20; PublicChatMessage publicChatMessage = 21; - PrivateTradeChatMessage privateTradeChatMessage = 22; PublicTradeChatMessage publicTradeChatMessage = 23; } } message Channel { - string id = 1; - ChannelNotificationType channelNotificationType = 2; - ChannelDomain channelDomain = 3; + ChannelDomain channelDomain = 1; + string channelName = 2; + ChannelNotificationType channelNotificationType = 3; oneof message{ - PrivateTwoPartyChannel privateTwoPartyChannel = 10; + PrivateChannel privateChannel = 10; PublicChannel publicChannel = 11; - PrivateTradeChannel privateTradeChannel = 12; PublicTradeChannel publicTradeChannel = 13; } } -// PrivateTwoParty -message PrivateTwoPartyChatMessage { +// Private +message PrivateChatMessage { string receiversId = 1; user.UserProfile sender = 2; } -message PrivateTwoPartyChannel { +message PrivateChannel { user.UserProfile peer = 1; user.UserIdentity myUserIdentity = 2; repeated ChatMessage chatMessages = 3; } -message PrivateTwoPartyChannelStore { +message PrivateChannelStore { repeated Channel channels = 1; } @@ -118,15 +116,6 @@ message ChannelSelectionStore { } - -message EventsChannelSelectionStore { - optional Channel selectedChannel = 1; -} -message SupportChannelSelectionStore { - optional Channel selectedChannel = 1; -} - - // Trade message PrivateTradeChatMessage { string receiversId = 1; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java index d16beeb830..587ccdbb91 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java @@ -19,10 +19,10 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; +import bisq.chat.channel.BasePrivateChannel; import bisq.chat.channel.BasePublicChannel; import bisq.chat.channel.Channel; import bisq.chat.channel.ChannelDomain; -import bisq.chat.channel.PrivateChannel; import bisq.chat.message.ChatMessage; import bisq.common.observable.Pin; import bisq.desktop.common.threading.UIThread; @@ -198,7 +198,7 @@ protected void cleanupChannelInfo() { channelSidebar.setOnUndoIgnoreChatUser(null); } - protected void applyPeersIcon(PrivateChannel privateChannel) { + protected void applyPeersIcon(BasePrivateChannel privateChannel) { Image image = RoboHash.getImage(privateChannel.getPeer().getPubKeyHash()); ImageView imageView = new ImageView(image); imageView.setFitWidth(42); @@ -208,7 +208,7 @@ protected void applyPeersIcon(PrivateChannel privateChannel) { protected void applyDefaultPublicChannelIcon(BasePublicChannel channel) { String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; - String iconId = "channels" + domain + channel.getId(); + String iconId = "channels" + domain + channel.getChannelName(); model.getChannelIcon().set(BisqIconButton.createIconButton(iconId)); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java index 5ee1287c20..f4371ad1fa 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java @@ -1,8 +1,8 @@ package bisq.desktop.primary.main.content.chat.channels; import bisq.chat.ChatService; +import bisq.chat.channel.BasePrivateChannel; import bisq.chat.channel.Channel; -import bisq.chat.channel.PrivateChannel; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.common.observable.Pin; @@ -245,13 +245,12 @@ public ChannelItem(Channel channel, @Nullable UserIdentityService userIdentit id = channel.getId(); String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; - iconIdSelected = "channels" + domain + channel.getId(); - iconIdHover = "channels" + domain + channel.getId() + "-white"; - iconId = "channels" + domain + channel.getId() + "-grey"; + iconIdSelected = "channels" + domain + channel.getChannelName(); + iconIdHover = "channels" + domain + channel.getChannelName() + "-white"; + iconId = "channels" + domain + channel.getChannelName() + "-grey"; - - if (channel instanceof PrivateChannel) { - PrivateChannel privateChannel = (PrivateChannel) channel; + if (channel instanceof BasePrivateChannel) { + BasePrivateChannel privateChannel = (BasePrivateChannel) channel; displayString = privateChannel.getPeer().getUserName(); // PrivateTradeChannel is handled in ListCell code if (!(channel instanceof PrivateTradeChannel) && hasMultipleProfiles) { diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index a16b14d5a0..5909be92b2 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -78,10 +78,10 @@ protected static class Controller extends ChannelSelection.Controller { private final View view; private final PrivateTradeChannelService privateTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; - private final PrivateTwoPartyChannelService privateDiscussionChannelService; + private final PrivateChannelService privateDiscussionChannelService; private final ChannelSelectionService discussionChannelSelectionService; - private final PrivateTwoPartyChannelService privateEventsChannelService; - private final PrivateTwoPartyChannelService privateSupportChannelService; + private final PrivateChannelService privateEventsChannelService; + private final PrivateChannelService privateSupportChannelService; private final ChannelSelectionService eventsChannelSelectionService; private final ChannelSelectionService supportChannelSelectionService; private final UserIdentityService userIdentityService; @@ -136,39 +136,39 @@ public void onActivate() { } }); } else if (model.channelDomain == ChannelDomain.DISCUSSION) { - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateDiscussionChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(discussionChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PrivateTwoPartyChannel) { + if (channel instanceof PrivateChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel, userIdentityService)); - userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); + userIdentityService.selectChatUserIdentity(((PrivateChannel) channel).getMyUserIdentity()); } }); } else if (model.channelDomain == ChannelDomain.EVENTS) { - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateEventsChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(eventsChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PrivateTwoPartyChannel) { + if (channel instanceof PrivateChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel, userIdentityService)); - userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); + userIdentityService.selectChatUserIdentity(((PrivateChannel) channel).getMyUserIdentity()); } }); } else if (model.channelDomain == ChannelDomain.SUPPORT) { - channelsPin = FxBindings.bind(model.channelItems) + channelsPin = FxBindings.bind(model.channelItems) .map(e -> new ChannelSelection.View.ChannelItem(e, userIdentityService)) .to(privateSupportChannelService.getChannels()); selectedChannelPin = FxBindings.subscribe(supportChannelSelectionService.getSelectedChannel(), channel -> { - if (channel instanceof PrivateTwoPartyChannel) { + if (channel instanceof PrivateChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel, userIdentityService)); - userIdentityService.selectChatUserIdentity(((PrivateTwoPartyChannel) channel).getMyUserIdentity()); + userIdentityService.selectChatUserIdentity(((PrivateChannel) channel).getMyUserIdentity()); } }); } @@ -202,7 +202,7 @@ public void deSelectChannel() { model.selectedChannelItem.set(null); } - public void onLeaveChannel(PrivateChannel privateChannel) { + public void onLeaveChannel(BasePrivateChannel privateChannel) { new Popup().warning(Res.get("social.privateChannel.leave.warning", privateChannel.getMyUserIdentity().getUserName())) .closeButtonText(Res.get("cancel")) .actionButtonText(Res.get("social.privateChannel.leave")) @@ -210,7 +210,7 @@ public void onLeaveChannel(PrivateChannel privateChannel) { .show(); } - public void doLeaveChannel(PrivateChannel privateChannel) { + public void doLeaveChannel(BasePrivateChannel privateChannel) { switch (privateChannel.getChannelDomain()) { case TRADE -> { privateTradeChannelService.leaveChannel((PrivateTradeChannel) privateChannel); @@ -331,11 +331,11 @@ protected void updateItem(ChannelItem item, boolean empty) { } Channel channel = item.getChannel(); - if (!(channel instanceof PrivateChannel)) { + if (!(channel instanceof BasePrivateChannel)) { return; } - PrivateChannel privateChannel = (PrivateChannel) item.getChannel(); + BasePrivateChannel privateChannel = (BasePrivateChannel) item.getChannel(); UserProfile peer = privateChannel.getPeer(); roboIcon.setImage(RoboHash.getImage(peer.getPubKeyHash())); Tooltip.install(this, tooltip); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java index 5e723f67e7..938151a913 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesComponent.java @@ -110,17 +110,17 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final ChatMessagesListView chatMessagesListView; private final UserProfileService userProfileService; private final PrivateTradeChannelService privateTradeChannelService; - private final PrivateTwoPartyChannelService privateDiscussionChannelService; + private final PrivateChannelService privateDiscussionChannelService; private final PublicChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final TradeChannelSelectionService tradeChannelSelectionService; private final ChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; private final PublicChannelService publicEventsChannelService; - private final PrivateTwoPartyChannelService privateEventsChannelService; + private final PrivateChannelService privateEventsChannelService; private final ChannelSelectionService eventsChannelSelectionService; private final PublicChannelService publicSupportChannelService; - private final PrivateTwoPartyChannelService privateSupportChannelService; + private final PrivateChannelService privateSupportChannelService; private final ChannelSelectionService supportChannelSelectionService; private final UserProfileSelection userProfileSelection; private Pin selectedChannelPin; @@ -258,18 +258,18 @@ private void doSendMessage(String text) { } } - } else if (channel instanceof PrivateTwoPartyChannel) { + } else if (channel instanceof PrivateChannel) { switch (channel.getChannelDomain()) { case TRADE -> { } case DISCUSSION -> { - privateDiscussionChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); + privateDiscussionChannelService.sendPrivateChatMessage(text, quotation, (PrivateChannel) channel); } case EVENTS -> { - privateEventsChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); + privateEventsChannelService.sendPrivateChatMessage(text, quotation, (PrivateChannel) channel); } case SUPPORT -> { - privateSupportChannelService.sendPrivateChatMessage(text, quotation, (PrivateTwoPartyChannel) channel); + privateSupportChannelService.sendPrivateChatMessage(text, quotation, (PrivateChannel) channel); } } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 8e831c0e5a..39364b8c4b 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -145,7 +145,7 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final View view; private final ChatService chatService; private final PrivateTradeChannelService privateTradeChannelService; - private final PrivateTwoPartyChannelService privateDiscussionChannelService; + private final PrivateChannelService privateDiscussionChannelService; private final PublicChannelService publicDiscussionChannelService; private final PublicTradeChannelService publicTradeChannelService; private final UserIdentityService userIdentityService; @@ -157,10 +157,10 @@ private static class Controller implements bisq.desktop.common.view.Controller { private final TradeChannelSelectionService tradeChannelSelectionService; private final ChannelSelectionService discussionChannelSelectionService; private final SettingsService settingsService; - private final PrivateTwoPartyChannelService privateEventsChannelService; + private final PrivateChannelService privateEventsChannelService; private final PublicChannelService publicEventsChannelService; private final ChannelSelectionService eventsChannelSelectionService; - private final PrivateTwoPartyChannelService privateSupportChannelService; + private final PrivateChannelService privateSupportChannelService; private final PublicChannelService publicSupportChannelService; private final ChannelSelectionService supportChannelSelectionService; private final MediationService mediationService; @@ -253,13 +253,13 @@ public void onActivate() { .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) .to(((PublicChannel) channel).getChatMessages()); model.allowEditing.set(true); - } else if (channel instanceof PrivateTwoPartyChannel) { + } else if (channel instanceof PrivateChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PrivateTwoPartyChannel) channel).getChatMessages()); + .to(((PrivateChannel) channel).getChatMessages()); model.allowEditing.set(false); } }); @@ -274,13 +274,13 @@ public void onActivate() { .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) .to(((PublicChannel) channel).getChatMessages()); model.allowEditing.set(true); - } else if (channel instanceof PrivateTwoPartyChannel) { + } else if (channel instanceof PrivateChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PrivateTwoPartyChannel) channel).getChatMessages()); + .to(((PrivateChannel) channel).getChatMessages()); model.allowEditing.set(false); } }); @@ -295,13 +295,13 @@ public void onActivate() { .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) .to(((PublicChannel) channel).getChatMessages()); model.allowEditing.set(true); - } else if (channel instanceof PrivateTwoPartyChannel) { + } else if (channel instanceof PrivateChannel) { if (chatMessagesPin != null) { chatMessagesPin.unbind(); } - chatMessagesPin = FxBindings.>bind(model.chatMessages) + chatMessagesPin = FxBindings.>bind(model.chatMessages) .map(chatMessage -> new ChatMessageListItem<>(chatMessage, userProfileService, reputationService)) - .to(((PrivateTwoPartyChannel) channel).getChatMessages()); + .to(((PrivateChannel) channel).getChatMessages()); model.allowEditing.set(false); } }); @@ -1018,8 +1018,8 @@ public ChatMessageListItem(T chatMessage, UserProfileService userProfileService, if (chatMessage instanceof PrivateTradeChatMessage) { senderUserProfile = Optional.of(((PrivateTradeChatMessage) chatMessage).getSender()); - } else if (chatMessage instanceof PrivateTwoPartyChatMessage) { - senderUserProfile = Optional.of(((PrivateTwoPartyChatMessage) chatMessage).getSender()); + } else if (chatMessage instanceof PrivateChatMessage) { + senderUserProfile = Optional.of(((PrivateChatMessage) chatMessage).getSender()); } else { senderUserProfile = userProfileService.findUserProfile(chatMessage.getAuthorId()); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java index adf225819c..872bc10216 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/discussion/DiscussionsController.java @@ -81,8 +81,8 @@ public DiscussionsView getChatView() { protected void handleChannelChange(Channel channel) { super.handleChannelChange(channel); - if (channel instanceof PrivateTwoPartyChannel) { - applyPeersIcon((PrivateChannel) channel); + if (channel instanceof PrivateChannel) { + applyPeersIcon((BasePrivateChannel) channel); publicDiscussionChannelSelection.deSelectChannel(); } else { applyDefaultPublicChannelIcon((BasePublicChannel) channel); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java index 7692d1238b..dcb50f0a21 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/events/EventsController.java @@ -81,8 +81,8 @@ public EventsView getChatView() { protected void handleChannelChange(Channel channel) { super.handleChannelChange(channel); - if (channel instanceof PrivateTwoPartyChannel) { - applyPeersIcon((PrivateChannel) channel); + if (channel instanceof PrivateChannel) { + applyPeersIcon((BasePrivateChannel) channel); publicEventsChannelSelection.deSelectChannel(); } else { applyDefaultPublicChannelIcon((BasePublicChannel) channel); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java index ab8ef2c02e..b11af668f5 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/support/SupportController.java @@ -81,8 +81,8 @@ public SupportView getChatView() { protected void handleChannelChange(Channel channel) { super.handleChannelChange(channel); - if (channel instanceof PrivateTwoPartyChannel) { - applyPeersIcon((PrivateChannel) channel); + if (channel instanceof PrivateChannel) { + applyPeersIcon((BasePrivateChannel) channel); publicSupportChannelSelection.deSelectChannel(); } else { applyDefaultPublicChannelIcon((BasePublicChannel) channel); From 1ca9337efa62608d152b2e8ab78310810cb856d7 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 18:59:02 -0500 Subject: [PATCH 12/15] Separate all private channels --- .../channel/BasePrivateChannelService.java | 8 +++-- .../channel/BasePublicChannelService.java | 5 ++- .../main/java/bisq/chat/channel/Channel.java | 4 +-- .../bisq/chat/channel/ChannelService.java | 14 ++++++-- .../chat/channel/PrivateChannelService.java | 3 +- .../chat/channel/PublicChannelService.java | 12 +++++-- .../chat/message/BasePrivateChatMessage.java | 7 ++-- .../chat/message/BasePublicChatMessage.java | 6 ++-- .../java/bisq/chat/message/ChatMessage.java | 13 ++++--- .../bisq/chat/message/PrivateChatMessage.java | 15 +++++--- .../bisq/chat/message/PublicChatMessage.java | 16 ++++++--- .../trade/TradeChannelSelectionService.java | 2 +- .../priv/PrivateTradeChannelService.java | 16 ++++----- .../trade/priv/PrivateTradeChatMessage.java | 34 +++++++++++-------- .../chat/trade/pub/PublicTradeChannel.java | 2 +- .../trade/pub/PublicTradeChannelService.java | 20 +++++------ .../trade/pub/PublicTradeChannelStore.java | 18 +++++----- .../trade/pub/PublicTradeChatMessage.java | 15 +++++--- chat/src/main/proto/chat.proto | 19 ++++++----- .../chat/channels/ChannelSelection.java | 17 ++++++---- .../channels/PrivateChannelSelection.java | 2 +- .../channels/PublicTradeChannelSelection.java | 5 +-- .../components/ChatMessagesListView.java | 6 ++-- .../review/ReviewOfferController.java | 5 +-- .../dto/PublicDiscussionChannelDto.java | 3 ++ .../restApi/dto/PublicTradeChannelDto.java | 4 +-- .../java/bisq/support/MediationService.java | 2 +- 27 files changed, 165 insertions(+), 108 deletions(-) diff --git a/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java index eaa88c9fe4..0bba502a5f 100644 --- a/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java @@ -172,8 +172,12 @@ protected abstract M createNewPrivateChatMessage(String messageId, MessageType messageType); protected void processMessage(M message) { - if (!userIdentityService.isUserIdentityPresent(message.getAuthorId())) { - findChannel(message.getChannelId()) + if (message.getChannelDomain() != channelDomain) { + return; + } + boolean isMyMessage = userIdentityService.isUserIdentityPresent(message.getAuthorId()); + if (!isMyMessage) { + findChannelForMessage(message) .or(() -> maybeCreateAndAddChannel(message.getSender(), message.getReceiversId())) .ifPresent(channel -> addMessage(message, channel)); } diff --git a/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java b/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java index 0440937950..60526bcbf8 100644 --- a/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/BasePublicChannelService.java @@ -107,12 +107,11 @@ public Collection getMentionableChannels() { /////////////////////////////////////////////////////////////////////////////////////////////////// protected void processAddedMessage(M message) { - findChannel(message.getChannelId()) - .ifPresent(channel -> addMessage(message, channel)); + findChannelForMessage(message).ifPresent(channel -> addMessage(message, channel)); } protected void processRemovedMessage(M message) { - findChannel(message.getChannelId()) + findChannelForMessage(message) .ifPresent(channel -> removeMessage(message, channel)); } diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index d45395a8bb..b667d871f5 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -92,9 +92,7 @@ public static Channel fromProto(bisq.chat.protobuf.Channe abstract public void removeChatMessages(Collection removeMessages); - public String getDisplayString() { - return id; - } + abstract public String getDisplayString(); public Set getMembers() { Map> chatMessagesByAuthor = new HashMap<>(); diff --git a/chat/src/main/java/bisq/chat/channel/ChannelService.java b/chat/src/main/java/bisq/chat/channel/ChannelService.java index 82298cc6e1..1f407c9a81 100644 --- a/chat/src/main/java/bisq/chat/channel/ChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelService.java @@ -46,9 +46,19 @@ public void setNotificationSetting(Channel channel, Chann persist(); } - public Optional findChannel(String channelId) { + public Optional findChannelById(String id) { return getChannels().stream() - .filter(channel -> channel.getId().equals(channelId)) + .filter(channel -> channel.getId().equals(id)) + .findAny(); + } + + public Optional findChannelForMessage(ChatMessage chatMessage) { + return findChannel(chatMessage.getChannelDomain(), chatMessage.getChannelName()); + } + + public Optional findChannel(ChannelDomain channelDomain, String channelName) { + return getChannels().stream() + .filter(channel -> channel.getChannelDomain().equals(channelDomain) && channel.getChannelName().equals(channelName)) .findAny(); } diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index a41c419392..9c9611db60 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -73,7 +73,8 @@ protected PrivateChatMessage createNewPrivateChatMessage(String messageId, boolean wasEdited, MessageType messageType) { return new PrivateChatMessage(messageId, - channel.getId(), + channel.getChannelDomain(), + channel.getChannelName(), sender, receiversId, text, diff --git a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java index 14bbf6b69f..c0d770fd95 100644 --- a/chat/src/main/java/bisq/chat/channel/PublicChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PublicChannelService.java @@ -20,6 +20,7 @@ import bisq.chat.message.PublicChatMessage; import bisq.chat.message.Quotation; import bisq.common.observable.ObservableArray; +import bisq.common.util.StringUtils; import bisq.network.NetworkService; import bisq.network.p2p.services.data.storage.DistributedData; import bisq.network.p2p.services.data.storage.auth.AuthenticatedData; @@ -51,7 +52,10 @@ public PublicChannelService(PersistenceService persistenceService, this.defaultChannels = defaultChannels; - persistence = persistenceService.getOrCreatePersistence(this, persistableStore); + persistence = persistenceService.getOrCreatePersistence(this, + "db", + "Public" + StringUtils.capitalize(channelDomain.name()) + "ChannelStore", + persistableStore); } @@ -90,7 +94,8 @@ protected PublicChatMessage createChatMessage(String text, Optional quotedMessage, PublicChannel publicChannel, UserProfile userProfile) { - return new PublicChatMessage(publicChannel.getId(), + return new PublicChatMessage(publicChannel.getChannelDomain(), + publicChannel.getChannelName(), userProfile.getId(), text, quotedMessage, @@ -102,7 +107,8 @@ protected PublicChatMessage createChatMessage(String text, protected PublicChatMessage createEditedChatMessage(PublicChatMessage originalChatMessage, String editedText, UserProfile userProfile) { - return new PublicChatMessage(originalChatMessage.getChannelId(), + return new PublicChatMessage(originalChatMessage.getChannelDomain(), + originalChatMessage.getChannelName(), userProfile.getId(), editedText, originalChatMessage.getQuotation(), diff --git a/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java b/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java index 4955dbdc70..438f3cbf10 100644 --- a/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/BasePrivateChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.message; +import bisq.chat.channel.ChannelDomain; import bisq.network.p2p.services.data.storage.MetaData; import bisq.network.p2p.services.data.storage.mailbox.MailboxMessage; import bisq.user.profile.UserProfile; @@ -38,7 +39,8 @@ public abstract class BasePrivateChatMessage extends ChatMessage implements Mail protected final UserProfile sender; protected BasePrivateChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, UserProfile sender, String receiversId, String text, @@ -48,7 +50,8 @@ protected BasePrivateChatMessage(String messageId, MessageType messageType, MetaData metaData) { super(messageId, - channelId, + channelDomain, + channelName, sender.getId(), Optional.of(text), quotedMessage, diff --git a/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java b/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java index fb9cef314c..11466715d2 100644 --- a/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/BasePublicChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.message; +import bisq.chat.channel.ChannelDomain; import bisq.common.encoding.Hex; import bisq.network.p2p.services.data.storage.DistributedData; import bisq.network.p2p.services.data.storage.MetaData; @@ -34,7 +35,8 @@ @EqualsAndHashCode(callSuper = true) public abstract class BasePublicChatMessage extends ChatMessage implements DistributedData { protected BasePublicChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, String authorId, Optional text, Optional quotation, @@ -42,7 +44,7 @@ protected BasePublicChatMessage(String messageId, boolean wasEdited, MessageType messageType, MetaData metaData) { - super(messageId, channelId, authorId, text, quotation, date, wasEdited, messageType, metaData); + super(messageId, channelDomain, channelName, authorId, text, quotation, date, wasEdited, messageType, metaData); } @Override diff --git a/chat/src/main/java/bisq/chat/message/ChatMessage.java b/chat/src/main/java/bisq/chat/message/ChatMessage.java index 35e088bccf..400984a212 100644 --- a/chat/src/main/java/bisq/chat/message/ChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/ChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.message; +import bisq.chat.channel.ChannelDomain; import bisq.chat.trade.priv.PrivateTradeChatMessage; import bisq.chat.trade.pub.PublicTradeChatMessage; import bisq.common.proto.Proto; @@ -43,7 +44,8 @@ public abstract class ChatMessage implements Proto { public final static long TTL = TimeUnit.DAYS.toMillis(1); protected final String messageId; - protected final String channelId; + private final ChannelDomain channelDomain; + protected final String channelName; protected final Optional optionalText; protected String authorId; protected final Optional quotation; @@ -53,7 +55,8 @@ public abstract class ChatMessage implements Proto { protected final MetaData metaData; protected ChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, String authorId, Optional text, Optional quotation, @@ -62,7 +65,8 @@ protected ChatMessage(String messageId, MessageType messageType, MetaData metaData) { this.messageId = messageId; - this.channelId = channelId; + this.channelDomain = channelDomain; + this.channelName = channelName; this.authorId = authorId; this.optionalText = text; this.quotation = quotation; @@ -79,7 +83,8 @@ public String getText() { public bisq.chat.protobuf.ChatMessage.Builder getChatMessageBuilder() { bisq.chat.protobuf.ChatMessage.Builder builder = bisq.chat.protobuf.ChatMessage.newBuilder() .setMessageId(messageId) - .setChannelId(channelId) + .setChannelDomain(channelDomain.toProto()) + .setChannelName(channelName) .setAuthorId(authorId) .setDate(date) .setWasEdited(wasEdited) diff --git a/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java b/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java index 7190616b61..9932ae3f9e 100644 --- a/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PrivateChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.message; +import bisq.chat.channel.ChannelDomain; import bisq.network.p2p.services.data.storage.MetaData; import bisq.network.protobuf.ExternalNetworkMessage; import bisq.network.protobuf.NetworkMessage; @@ -33,7 +34,8 @@ @EqualsAndHashCode(callSuper = true) public final class PrivateChatMessage extends BasePrivateChatMessage { public PrivateChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, UserProfile sender, String receiversId, String text, @@ -42,7 +44,8 @@ public PrivateChatMessage(String messageId, boolean wasEdited, MessageType messageType) { super(messageId, - channelId, + channelDomain, + channelName, sender, receiversId, text, @@ -54,7 +57,8 @@ public PrivateChatMessage(String messageId, } private PrivateChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, UserProfile sender, String receiversId, String text, @@ -63,7 +67,7 @@ private PrivateChatMessage(String messageId, boolean wasEdited, MessageType messageType, MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); + super(messageId, channelDomain, channelName, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); } @Override @@ -88,7 +92,8 @@ public static PrivateChatMessage fromProto(bisq.chat.protobuf.ChatMessage basePr bisq.chat.protobuf.PrivateChatMessage privateChatMessage = baseProto.getPrivateChatMessage(); return new PrivateChatMessage( baseProto.getMessageId(), - baseProto.getChannelId(), + ChannelDomain.fromProto(baseProto.getChannelDomain()), + baseProto.getChannelName(), UserProfile.fromProto(privateChatMessage.getSender()), privateChatMessage.getReceiversId(), baseProto.getText(), diff --git a/chat/src/main/java/bisq/chat/message/PublicChatMessage.java b/chat/src/main/java/bisq/chat/message/PublicChatMessage.java index 3e1897e67f..8b5dbf8378 100644 --- a/chat/src/main/java/bisq/chat/message/PublicChatMessage.java +++ b/chat/src/main/java/bisq/chat/message/PublicChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.message; +import bisq.chat.channel.ChannelDomain; import bisq.common.util.StringUtils; import bisq.network.p2p.services.data.storage.MetaData; import lombok.EqualsAndHashCode; @@ -29,14 +30,16 @@ @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) public final class PublicChatMessage extends BasePublicChatMessage { - public PublicChatMessage(String channelId, + public PublicChatMessage(ChannelDomain channelDomain, + String channelName, String authorId, String text, Optional quotedMessage, long date, boolean wasEdited) { this(StringUtils.createShortUid(), - channelId, + channelDomain, + channelName, authorId, Optional.of(text), quotedMessage, @@ -47,7 +50,8 @@ public PublicChatMessage(String channelId, } private PublicChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, String authorId, Optional text, Optional quotedMessage, @@ -56,7 +60,8 @@ private PublicChatMessage(String messageId, MessageType messageType, MetaData metaData) { super(messageId, - channelId, + channelDomain, + channelName, authorId, text, quotedMessage, @@ -76,7 +81,8 @@ public static PublicChatMessage fromProto(bisq.chat.protobuf.ChatMessage basePro Optional.empty(); return new PublicChatMessage( baseProto.getMessageId(), - baseProto.getChannelId(), + ChannelDomain.fromProto(baseProto.getChannelDomain()), + baseProto.getChannelName(), baseProto.getAuthorId(), Optional.of(baseProto.getText()), quotedMessage, diff --git a/chat/src/main/java/bisq/chat/trade/TradeChannelSelectionService.java b/chat/src/main/java/bisq/chat/trade/TradeChannelSelectionService.java index 008143afe4..255108b01c 100644 --- a/chat/src/main/java/bisq/chat/trade/TradeChannelSelectionService.java +++ b/chat/src/main/java/bisq/chat/trade/TradeChannelSelectionService.java @@ -44,9 +44,9 @@ public class TradeChannelSelectionService implements PersistenceClient initialize() { diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index 75104a7dfe..307f5bbf2d 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -82,7 +82,7 @@ protected PrivateTradeChatMessage createNewPrivateChatMessage(String messageId, Optional mediator = channel.getChatMessages().isEmpty() ? channel.getMediator() : Optional.empty(); return new PrivateTradeChatMessage( messageId, - channel.getId(), + channel.getChannelName(), sender, receiversId, text, @@ -100,9 +100,9 @@ protected PrivateTradeChannel createNewChannel(UserProfile peer, UserIdentity my } public PrivateTradeChannel mediatorCreatesNewChannel(UserIdentity myUserIdentity, UserProfile trader1, UserProfile trader2) { - String channelId = PrivateTradeChannel.createChannelName(new Pair<>(trader1.getId(), trader2.getId())); + String channelName = PrivateTradeChannel.createChannelName(new Pair<>(trader1.getId(), trader2.getId())); Optional existingChannel = getChannels().stream() - .filter(channel -> channel.getId().equals(channelId)) + .filter(channel -> channel.getChannelName().equals(channelName)) .findAny(); if (existingChannel.isPresent()) { return existingChannel.get(); @@ -115,9 +115,9 @@ public PrivateTradeChannel mediatorCreatesNewChannel(UserIdentity myUserIdentity } public PrivateTradeChannel traderCreatesNewChannel(UserIdentity myUserIdentity, UserProfile peersUserProfile, Optional mediator) { - String channelId = PrivateTradeChannel.createChannelName(new Pair<>(myUserIdentity.getUserProfile().getId(), peersUserProfile.getId())); + String channelName = PrivateTradeChannel.createChannelName(new Pair<>(myUserIdentity.getUserProfile().getId(), peersUserProfile.getId())); Optional existingChannel = getChannels().stream() - .filter(channel -> channel.getId().equals(channelId)) + .filter(channel -> channel.getChannelName().equals(channelName)) .findAny(); if (existingChannel.isPresent()) { return existingChannel.get(); @@ -149,7 +149,7 @@ public ObservableArray getChannels() { protected void processMessage(PrivateTradeChatMessage message) { if (!userIdentityService.isUserIdentityPresent(message.getAuthorId())) { userIdentityService.findUserIdentity(message.getReceiversId()) - .flatMap(myUserIdentity -> findChannel(message.getChannelId()) + .flatMap(myUserIdentity -> findChannelForMessage(message) .or(() -> { if (message.getMessageType() == MessageType.LEAVE) { return Optional.empty(); @@ -191,7 +191,7 @@ public CompletableFuture sendPrivateChatMessag Optional mediator = channel.getChatMessages().isEmpty() ? channel.getMediator() : Optional.empty(); PrivateTradeChatMessage message1 = new PrivateTradeChatMessage( messageId, - channel.getId(), + channel.getChannelName(), senderUserProfile, receiver1.getId(), text, @@ -207,7 +207,7 @@ public CompletableFuture sendPrivateChatMessag PrivateTradeChatMessage message2 = new PrivateTradeChatMessage( messageId, - channel.getId(), + channel.getChannelName(), senderUserProfile, receiver2.getId(), text, diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java index a7caa9b3e6..418aa0bf64 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.trade.priv; +import bisq.chat.channel.ChannelDomain; import bisq.chat.message.BasePrivateChatMessage; import bisq.chat.message.MessageType; import bisq.chat.message.Quotation; @@ -38,7 +39,7 @@ public final class PrivateTradeChatMessage extends BasePrivateChatMessage { private final Optional mediator; public PrivateTradeChatMessage(String messageId, - String channelId, + String channelName, UserProfile sender, String receiversId, String text, @@ -48,7 +49,8 @@ public PrivateTradeChatMessage(String messageId, Optional mediator, MessageType messageType) { this(messageId, - channelId, + ChannelDomain.TRADE, + channelName, sender, receiversId, text, @@ -60,18 +62,19 @@ public PrivateTradeChatMessage(String messageId, new MetaData(TTL, 100000, PrivateTradeChatMessage.class.getSimpleName())); } - public PrivateTradeChatMessage(String messageId, - String channelId, - UserProfile sender, - String receiversId, - String text, - Optional quotedMessage, - long date, - boolean wasEdited, - Optional mediator, - MessageType messageType, - MetaData metaData) { - super(messageId, channelId, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); + private PrivateTradeChatMessage(String messageId, + ChannelDomain channelDomain, + String channelName, + UserProfile sender, + String receiversId, + String text, + Optional quotedMessage, + long date, + boolean wasEdited, + Optional mediator, + MessageType messageType, + MetaData metaData) { + super(messageId, channelDomain, channelName, sender, receiversId, text, quotedMessage, date, wasEdited, messageType, metaData); this.mediator = mediator; } @@ -102,7 +105,8 @@ public static PrivateTradeChatMessage fromProto(bisq.chat.protobuf.ChatMessage b Optional.empty(); return new PrivateTradeChatMessage( baseProto.getMessageId(), - baseProto.getChannelId(), + ChannelDomain.fromProto(baseProto.getChannelDomain()), + baseProto.getChannelName(), UserProfile.fromProto(privateTradeChatMessage.getSender()), privateTradeChatMessage.getReceiversId(), baseProto.getText(), diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java index 9285a678fe..ccba854bce 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannel.java @@ -80,7 +80,7 @@ public String getDisplayString() { return market.getMarketCodes(); } - private static String getChannelName(Market market) { + public static String getChannelName(Market market) { return market.toString(); } diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java index 9e29637f75..0393c46128 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java @@ -59,27 +59,27 @@ public PublicTradeChannelService(PersistenceService persistenceService, public void showChannel(PublicTradeChannel channel) { - getVisibleChannelIds().add(channel.getId()); - numVisibleChannels.set(getVisibleChannelIds().size()); + getVisibleChannelNames().add(channel.getChannelName()); + numVisibleChannels.set(getVisibleChannelNames().size()); persist(); } public void hidePublicTradeChannel(PublicTradeChannel channel) { - getVisibleChannelIds().remove(channel.getId()); - numVisibleChannels.set(getVisibleChannelIds().size()); + getVisibleChannelNames().remove(channel.getChannelName()); + numVisibleChannels.set(getVisibleChannelNames().size()); persist(); } public boolean isVisible(PublicTradeChannel channel) { - return getVisibleChannelIds().contains(channel.getId()); + return getVisibleChannelNames().contains(channel.getChannelName()); } - public ObservableSet getVisibleChannelIds() { - return persistableStore.getVisibleChannelIds(); + public ObservableSet getVisibleChannelNames() { + return persistableStore.getVisibleChannelNames(); } public Set getVisibleChannels() { - return getChannels().stream().filter(channel -> getVisibleChannelIds().contains(channel.getId())).collect(Collectors.toSet()); + return getChannels().stream().filter(channel -> getVisibleChannelNames().contains(channel.getChannelName())).collect(Collectors.toSet()); } @@ -118,7 +118,7 @@ protected PublicTradeChatMessage createChatMessage(String text, Optional quotedMessage, PublicTradeChannel publicChannel, UserProfile userProfile) { - return new PublicTradeChatMessage(publicChannel.getId(), + return new PublicTradeChatMessage(publicChannel.getChannelName(), userProfile.getId(), Optional.empty(), Optional.of(text), @@ -131,7 +131,7 @@ protected PublicTradeChatMessage createChatMessage(String text, protected PublicTradeChatMessage createEditedChatMessage(PublicTradeChatMessage originalChatMessage, String editedText, UserProfile userProfile) { - return new PublicTradeChatMessage(originalChatMessage.getChannelId(), + return new PublicTradeChatMessage(originalChatMessage.getChannelName(), userProfile.getId(), Optional.empty(), Optional.of(editedText), diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelStore.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelStore.java index 25e214c67a..445dfdc01f 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelStore.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelStore.java @@ -33,21 +33,21 @@ @Getter public class PublicTradeChannelStore implements PersistableStore { private final ObservableArray channels = new ObservableArray<>(); - private final ObservableSet visibleChannelIds = new ObservableSet<>(); + private final ObservableSet visibleChannelNames = new ObservableSet<>(); public PublicTradeChannelStore() { } private PublicTradeChannelStore(List privateTradeChannels, - Set visibleChannelIds) { - setAll(privateTradeChannels, visibleChannelIds); + Set visibleChannelNames) { + setAll(privateTradeChannels, visibleChannelNames); } @Override public bisq.chat.protobuf.PublicTradeChannelStore toProto() { bisq.chat.protobuf.PublicTradeChannelStore.Builder builder = bisq.chat.protobuf.PublicTradeChannelStore.newBuilder() .addAllChannels(channels.stream().map(PublicTradeChannel::toProto).collect(Collectors.toList())) - .addAllVisibleChannelIds(visibleChannelIds); + .addAllVisibleChannelNames(visibleChannelNames); return builder.build(); } @@ -55,7 +55,7 @@ public static PublicTradeChannelStore fromProto(bisq.chat.protobuf.PublicTradeCh List privateTradeChannels = proto.getChannelsList().stream() .map(e -> (PublicTradeChannel) PublicTradeChannel.fromProto(e)) .collect(Collectors.toList()); - return new PublicTradeChannelStore(privateTradeChannels, new HashSet<>(proto.getVisibleChannelIdsList())); + return new PublicTradeChannelStore(privateTradeChannels, new HashSet<>(proto.getVisibleChannelNamesList())); } @Override @@ -71,18 +71,18 @@ public ProtoResolver> getResolver() { @Override public void applyPersisted(PublicTradeChannelStore chatStore) { - setAll(chatStore.getChannels(), chatStore.getVisibleChannelIds()); + setAll(chatStore.getChannels(), chatStore.getVisibleChannelNames()); } @Override public PublicTradeChannelStore getClone() { - return new PublicTradeChannelStore(channels, visibleChannelIds); + return new PublicTradeChannelStore(channels, visibleChannelNames); } public void setAll(List privateTradeChannels, Set visibleChannelIds) { this.channels.clear(); this.channels.addAll(privateTradeChannels); - this.visibleChannelIds.clear(); - this.visibleChannelIds.addAll(visibleChannelIds); + this.visibleChannelNames.clear(); + this.visibleChannelNames.addAll(visibleChannelIds); } } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java index f7d1345b34..00cbfb56c5 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChatMessage.java @@ -17,6 +17,7 @@ package bisq.chat.trade.pub; +import bisq.chat.channel.ChannelDomain; import bisq.chat.message.BasePublicChatMessage; import bisq.chat.message.ChatMessage; import bisq.chat.message.MessageType; @@ -37,7 +38,7 @@ public final class PublicTradeChatMessage extends BasePublicChatMessage { private final Optional tradeChatOffer; - public PublicTradeChatMessage(String channelId, + public PublicTradeChatMessage(String channelName, String authorId, Optional tradeChatOffer, Optional text, @@ -45,7 +46,8 @@ public PublicTradeChatMessage(String channelId, long date, boolean wasEdited) { this(StringUtils.createShortUid(), - channelId, + ChannelDomain.TRADE, + channelName, authorId, tradeChatOffer, text, @@ -57,7 +59,8 @@ public PublicTradeChatMessage(String channelId, } private PublicTradeChatMessage(String messageId, - String channelId, + ChannelDomain channelDomain, + String channelName, String authorId, Optional tradeChatOffer, Optional text, @@ -67,7 +70,8 @@ private PublicTradeChatMessage(String messageId, MessageType messageType, MetaData metaData) { super(messageId, - channelId, + channelDomain, + channelName, authorId, text, quotedMessage, @@ -96,7 +100,8 @@ public static PublicTradeChatMessage fromProto(bisq.chat.protobuf.ChatMessage ba Optional.empty(); return new PublicTradeChatMessage( baseProto.getMessageId(), - baseProto.getChannelId(), + ChannelDomain.fromProto(baseProto.getChannelDomain()), + baseProto.getChannelName(), baseProto.getAuthorId(), tradeChatOffer, text, diff --git a/chat/src/main/proto/chat.proto b/chat/src/main/proto/chat.proto index eec8291361..f9fccacc1a 100644 --- a/chat/src/main/proto/chat.proto +++ b/chat/src/main/proto/chat.proto @@ -53,14 +53,15 @@ message Quotation { message ChatMessage { string messageId = 1; - string channelId = 2; - optional string text = 3; - string authorId = 4; - optional Quotation quotation = 5; - uint64 date = 6; - bool wasEdited = 7; - MessageType messageType = 8; - network.MetaData metaData = 9; + ChannelDomain channelDomain = 2; + string channelName = 3; + optional string text = 4; + string authorId = 5; + optional Quotation quotation = 6; + uint64 date = 7; + bool wasEdited = 8; + MessageType messageType = 9; + network.MetaData metaData = 10; oneof message { PrivateChatMessage privateChatMessage = 20; PublicChatMessage publicChatMessage = 21; @@ -160,7 +161,7 @@ message PrivateTradeChannelStore { message PublicTradeChannelStore { repeated Channel channels = 1; - repeated string visibleChannelIds = 2; + repeated string visibleChannelNames = 2; } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java index f4371ad1fa..29c4d5e635 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/ChannelSelection.java @@ -3,6 +3,7 @@ import bisq.chat.ChatService; import bisq.chat.channel.BasePrivateChannel; import bisq.chat.channel.Channel; +import bisq.chat.channel.ChannelDomain; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.common.observable.Pin; @@ -224,7 +225,9 @@ protected Subscription setupCellBinding(ListCell cell, ChannelItem @Getter static class ChannelItem { @EqualsAndHashCode.Include - private final String id; + private final String channelName; + @EqualsAndHashCode.Include + private final ChannelDomain channelDomain; private final Channel channel; private String displayString; private final boolean hasMultipleProfiles; @@ -240,14 +243,14 @@ public ChannelItem(Channel channel) { public ChannelItem(Channel channel, @Nullable UserIdentityService userIdentityService) { this.channel = channel; + channelDomain = channel.getChannelDomain(); + channelName = channel.getChannelName(); hasMultipleProfiles = userIdentityService != null && userIdentityService.getUserIdentities().size() > 1; - id = channel.getId(); - - String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; - iconIdSelected = "channels" + domain + channel.getChannelName(); - iconIdHover = "channels" + domain + channel.getChannelName() + "-white"; - iconId = "channels" + domain + channel.getChannelName() + "-grey"; + String domain = "-" + channelDomain.name().toLowerCase() + "-"; + iconIdSelected = "channels" + domain + channelName; + iconIdHover = "channels" + domain + channelName + "-white"; + iconId = "channels" + domain + channelName + "-grey"; if (channel instanceof BasePrivateChannel) { BasePrivateChannel privateChannel = (BasePrivateChannel) channel; diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java index 5909be92b2..5c5db4dfea 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PrivateChannelSelection.java @@ -397,7 +397,7 @@ protected void updateItem(ChannelItem item, boolean empty) { hBox.getChildren().addAll(roboIcon, label, Spacer.fillHBox(), removeIcon); widthSubscription = EasyBind.subscribe(widthProperty(), w -> { if (w.doubleValue() > 0) { - label.setMaxWidth(getWidth() - 75); + label.setMaxWidth(getWidth() - 95); } }); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java index 480a0e3129..73a251b760 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java @@ -18,6 +18,7 @@ package bisq.desktop.primary.main.content.chat.channels; import bisq.application.DefaultApplicationService; +import bisq.chat.channel.ChannelDomain; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.pub.PublicTradeChannel; import bisq.chat.trade.pub.PublicTradeChannelService; @@ -160,7 +161,7 @@ public void deSelectChannel() { public void onShowMarket(View.MarketListItem marketListItem) { if (marketListItem != null) { model.allMarkets.remove(marketListItem); - publicTradeChannelService.findChannel(PublicTradeChannel.getChannelId(marketListItem.market)) + publicTradeChannelService.findChannel(ChannelDomain.TRADE, PublicTradeChannel.getChannelName(marketListItem.market)) .ifPresent(channel -> { publicTradeChannelService.showChannel(channel); tradeChannelSelectionService.selectChannel(channel); @@ -180,7 +181,7 @@ public void onHideTradeChannel(PublicTradeChannel channel) { } private int getNumMessages(Market market) { - return publicTradeChannelService.findChannel(PublicTradeChannel.getChannelId(market)) + return publicTradeChannelService.findChannel(ChannelDomain.TRADE, PublicTradeChannel.getChannelName(market)) .map(e -> e.getChatMessages().size()) .orElse(0); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java index 39364b8c4b..cca5b5a078 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/components/ChatMessagesListView.java @@ -411,11 +411,11 @@ private void doDeleteMessage(ChatMessage chatMessage, UserIdentity messageAuthor //todo services dont do any domain specific here // -> networkService.removeAuthenticatedData(chatMessage, userIdentity.getNodeIdAndKeyPair()); - publicDiscussionChannelService.findChannel(chatMessage.getChannelId()) + publicDiscussionChannelService.findChannelForMessage(chatMessage) .ifPresent(c -> publicDiscussionChannelService.deleteChatMessage((PublicChatMessage) chatMessage, messageAuthor)); - publicEventsChannelService.findChannel(chatMessage.getChannelId()) + publicEventsChannelService.findChannelForMessage(chatMessage) .ifPresent(c -> publicEventsChannelService.deleteChatMessage((PublicChatMessage) chatMessage, messageAuthor)); - publicSupportChannelService.findChannel(chatMessage.getChannelId()) + publicSupportChannelService.findChannelForMessage(chatMessage) .ifPresent(c -> publicSupportChannelService.deleteChatMessage((PublicChatMessage) chatMessage, messageAuthor)); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java b/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java index e234af7b9e..449415a90f 100644 --- a/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java +++ b/desktop/src/main/java/bisq/desktop/primary/overlay/createOffer/review/ReviewOfferController.java @@ -19,6 +19,7 @@ import bisq.application.DefaultApplicationService; import bisq.chat.ChatService; +import bisq.chat.channel.ChannelDomain; import bisq.chat.message.Quotation; import bisq.chat.trade.TradeChannelSelectionService; import bisq.chat.trade.priv.PrivateTradeChannel; @@ -124,7 +125,7 @@ public void setShowMatchingOffers(boolean showMatchingOffers) { @Override public void onActivate() { - PublicTradeChannel channel = publicTradeChannelService.findChannel(PublicTradeChannel.getChannelId(model.getMarket())).orElseThrow(); + PublicTradeChannel channel = publicTradeChannelService.findChannel(ChannelDomain.TRADE, PublicTradeChannel.getChannelName(model.getMarket())).orElseThrow(); model.setSelectedChannel(channel); model.getShowCreateOfferSuccess().set(false); @@ -143,7 +144,7 @@ public void onActivate() { publicTradeChannelService.showChannel(channel); tradeChannelSelectionService.selectChannel(channel); - PublicTradeChatMessage myOfferMessage = new PublicTradeChatMessage(channel.getId(), + PublicTradeChatMessage myOfferMessage = new PublicTradeChatMessage(channel.getChannelName(), userIdentity.getUserProfile().getId(), Optional.of(tradeChatOffer), Optional.empty(), diff --git a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java index ded0c69be2..a1b1080194 100644 --- a/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java +++ b/restApi/src/main/java/bisq/restApi/dto/PublicDiscussionChannelDto.java @@ -1,5 +1,6 @@ package bisq.restApi.dto; +import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.PublicChannel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.EqualsAndHashCode; @@ -16,6 +17,7 @@ public final class PublicDiscussionChannelDto { @EqualsAndHashCode.Include private String id; + private ChannelDomain channelDomain; private String channelName; private String description; private String channelAdminId; @@ -24,6 +26,7 @@ public final class PublicDiscussionChannelDto { public static PublicDiscussionChannelDto from(PublicChannel publicDiscussionChannel) { PublicDiscussionChannelDto dto = new PublicDiscussionChannelDto(); dto.id = publicDiscussionChannel.getId(); + dto.channelDomain = publicDiscussionChannel.getChannelDomain(); dto.channelName = publicDiscussionChannel.getChannelName(); dto.description = publicDiscussionChannel.getDescription(); dto.channelAdminId = publicDiscussionChannel.getChannelAdminId(); diff --git a/restApi/src/main/java/bisq/restApi/dto/PublicTradeChannelDto.java b/restApi/src/main/java/bisq/restApi/dto/PublicTradeChannelDto.java index f5b5f7ed81..505f2f519e 100644 --- a/restApi/src/main/java/bisq/restApi/dto/PublicTradeChannelDto.java +++ b/restApi/src/main/java/bisq/restApi/dto/PublicTradeChannelDto.java @@ -13,7 +13,7 @@ @Schema(name = "PublicTradeChannel") public final class PublicTradeChannelDto { @EqualsAndHashCode.Include - private String id; + private String channelName; private String description; private String displayString; @@ -22,7 +22,7 @@ public final class PublicTradeChannelDto { public static PublicTradeChannelDto from(PublicTradeChannel publicTradeChannel) { PublicTradeChannelDto dto = new PublicTradeChannelDto(); - dto.id = publicTradeChannel.getId(); + dto.channelName = publicTradeChannel.getChannelName(); dto.description = publicTradeChannel.getDescription(); dto.displayString = publicTradeChannel.getDisplayString(); dto.marketDto = MarketDto.from(publicTradeChannel.getMarket()); diff --git a/support/src/main/java/bisq/support/MediationService.java b/support/src/main/java/bisq/support/MediationService.java index 9b2323cce5..7100dfee4b 100644 --- a/support/src/main/java/bisq/support/MediationService.java +++ b/support/src/main/java/bisq/support/MediationService.java @@ -163,7 +163,7 @@ private void processMediationRequest(MediationRequest mediationRequest) { } private void processMediationResponse(MediationResponse mediationResponse) { - privateTradeChannelService.findChannel(mediationResponse.getChannelId()).ifPresent(channel -> { + privateTradeChannelService.findChannelById(mediationResponse.getChannelId()).ifPresent(channel -> { // Requester had it activated at request time if (!channel.getInMediation().get()) { // Peer who has not requested sends their messages as well, so mediator can be sure to get all messages From 41e32733b139354b845c4633be88f669dd132126 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 19:24:12 -0500 Subject: [PATCH 13/15] Add button to private chat peer icon --- .../components/controls/BisqIconButton.java | 8 ++++++++ .../main/content/chat/ChatController.java | 17 +++++++++++------ .../primary/main/content/chat/ChatView.java | 2 +- .../bisqEasy/chat/BisqEasyChatController.java | 4 ++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/controls/BisqIconButton.java b/desktop/src/main/java/bisq/desktop/components/controls/BisqIconButton.java index 9ee2aebcb3..fc0b22993f 100644 --- a/desktop/src/main/java/bisq/desktop/components/controls/BisqIconButton.java +++ b/desktop/src/main/java/bisq/desktop/components/controls/BisqIconButton.java @@ -56,6 +56,13 @@ public static Button createIconButton(String iconId, @Nullable String tooltip) { return button; } + public static Button createIconButton(ImageView imageView) { + Button button = new Button(); + button.setGraphic(imageView); + button.getStyleClass().add("icon-button"); + return button; + } + @Getter private final ImageView icon; @@ -72,6 +79,7 @@ public BisqIconButton(String iconId) { icon.setId(iconId); } + public void setIcon(AwesomeIcon icon) { setGraphic(AwesomeDude.createIconLabel(icon)); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java index 587ccdbb91..e8d06d4ad3 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatController.java @@ -39,6 +39,7 @@ import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfileService; import bisq.user.reputation.ReputationService; +import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import lombok.Getter; @@ -97,14 +98,14 @@ public ChatController(DefaultApplicationService applicationService, ChannelDomai @Override public void onActivate() { - chatMessagesComponent.setOnShowChatUserDetails(chatUser -> { + chatMessagesComponent.setOnShowChatUserDetails(userProfile -> { onCloseSideBar(); model.getSideBarVisible().set(true); UserProfileSidebar userProfileSidebar = new UserProfileSidebar(userProfileService, chatService, reputationService, - chatUser, + userProfile, () -> { onCloseSideBar(); chatMessagesComponent.resetSelectedChatMessage(); @@ -201,14 +202,18 @@ protected void cleanupChannelInfo() { protected void applyPeersIcon(BasePrivateChannel privateChannel) { Image image = RoboHash.getImage(privateChannel.getPeer().getPubKeyHash()); ImageView imageView = new ImageView(image); - imageView.setFitWidth(42); - imageView.setFitHeight(42); - model.getChannelIcon().set(imageView); + imageView.setFitWidth(35); + imageView.setFitHeight(35); + model.getChannelIcon().set(BisqIconButton.createIconButton(imageView)); } protected void applyDefaultPublicChannelIcon(BasePublicChannel channel) { String domain = "-" + channel.getChannelDomain().name().toLowerCase() + "-"; String iconId = "channels" + domain + channel.getChannelName(); - model.getChannelIcon().set(BisqIconButton.createIconButton(iconId)); + Button iconButton = BisqIconButton.createIconButton(iconId); + //todo get larger icons and dont use scaling + iconButton.setScaleX(1.25); + iconButton.setScaleY(1.25); + model.getChannelIcon().set(iconButton); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatView.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatView.java index 1669b383cb..d5526d902e 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatView.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/ChatView.java @@ -137,7 +137,7 @@ protected void onViewAttached() { channelIconPin = EasyBind.subscribe(model.getChannelIcon(), icon -> { if (icon != null) { headline.setGraphic(icon); - headline.setGraphicTextGap(8); + headline.setGraphicTextGap(10); icon.setStyle("-fx-cursor: hand;"); icon.setOnMouseClicked(e -> controller.onToggleChannelInfo()); } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java index 6b6084991b..9deb82068f 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/trade/bisqEasy/chat/BisqEasyChatController.java @@ -145,6 +145,10 @@ protected void handleChannelChange(Channel channel) { StackPane marketsImage = MarketImageComposition.imageBoxForMarket( market.getBaseCurrencyCode().toLowerCase(), market.getQuoteCurrencyCode().toLowerCase()).getFirst(); + + //todo get larger icons and dont use scaling + marketsImage.setScaleX(1.25); + marketsImage.setScaleY(1.25); model.getChannelIcon().set(marketsImage); } }); From 319dc9ddadf1fc05a9a152fe1de03e44b7de8bab Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 19:58:33 -0500 Subject: [PATCH 14/15] Add support for ignored user --- .../application/DefaultApplicationService.java | 3 ++- chat/src/main/java/bisq/chat/ChatService.java | 14 ++++++++++++-- .../chat/channel/BasePrivateChannelService.java | 4 +++- .../chat/channel/BasePublicChannelService.java | 8 ++++++-- .../java/bisq/chat/channel/ChannelService.java | 8 +++++++- .../bisq/chat/channel/PrivateChannelService.java | 4 +++- .../bisq/chat/channel/PublicChannelService.java | 4 +++- .../trade/priv/PrivateTradeChannelService.java | 6 +++++- .../chat/trade/pub/PublicTradeChannelService.java | 6 ++++-- .../chat/channels/PrivateChannelSelection.java | 10 +++++----- .../chat/channels/PublicTradeChannelSelection.java | 2 ++ 11 files changed, 52 insertions(+), 17 deletions(-) diff --git a/application/src/main/java/bisq/application/DefaultApplicationService.java b/application/src/main/java/bisq/application/DefaultApplicationService.java index 580d155146..94c452b72c 100644 --- a/application/src/main/java/bisq/application/DefaultApplicationService.java +++ b/application/src/main/java/bisq/application/DefaultApplicationService.java @@ -109,7 +109,8 @@ public DefaultApplicationService(String[] args) { chatService = new ChatService(persistenceService, securityService.getProofOfWorkService(), networkService, - userService.getUserIdentityService()); + userService.getUserIdentityService(), + userService.getUserProfileService()); supportService = new SupportService(networkService, chatService, userService); diff --git a/chat/src/main/java/bisq/chat/ChatService.java b/chat/src/main/java/bisq/chat/ChatService.java index 17483d6cdf..4c5d692485 100644 --- a/chat/src/main/java/bisq/chat/ChatService.java +++ b/chat/src/main/java/bisq/chat/ChatService.java @@ -28,6 +28,7 @@ import bisq.security.pow.ProofOfWorkService; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import bisq.user.profile.UserProfileService; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -53,16 +54,19 @@ public class ChatService implements Service { public ChatService(PersistenceService persistenceService, ProofOfWorkService proofOfWorkService, NetworkService networkService, - UserIdentityService userIdentityService) { + UserIdentityService userIdentityService, + UserProfileService userProfileService) { // Trade privateTradeChannelService = new PrivateTradeChannelService(persistenceService, networkService, userIdentityService, + userProfileService, proofOfWorkService); publicTradeChannelService = new PublicTradeChannelService(persistenceService, networkService, - userIdentityService); + userIdentityService, + userProfileService); tradeChannelSelectionService = new TradeChannelSelectionService(persistenceService, privateTradeChannelService, publicTradeChannelService); @@ -71,11 +75,13 @@ public ChatService(PersistenceService persistenceService, privateDiscussionChannelService = new PrivateChannelService(persistenceService, networkService, userIdentityService, + userProfileService, proofOfWorkService, ChannelDomain.DISCUSSION); publicDiscussionChannelService = new PublicChannelService(persistenceService, networkService, userIdentityService, + userProfileService, ChannelDomain.DISCUSSION, List.of(new PublicChannel(ChannelDomain.DISCUSSION, "bisq"), new PublicChannel(ChannelDomain.DISCUSSION, "bitcoin"), @@ -92,11 +98,13 @@ public ChatService(PersistenceService persistenceService, privateEventsChannelService = new PrivateChannelService(persistenceService, networkService, userIdentityService, + userProfileService, proofOfWorkService, ChannelDomain.EVENTS); publicEventsChannelService = new PublicChannelService(persistenceService, networkService, userIdentityService, + userProfileService, ChannelDomain.EVENTS, List.of(new PublicChannel(ChannelDomain.EVENTS, "conferences"), new PublicChannel(ChannelDomain.EVENTS, "meetups"), @@ -113,11 +121,13 @@ public ChatService(PersistenceService persistenceService, privateSupportChannelService = new PrivateChannelService(persistenceService, networkService, userIdentityService, + userProfileService, proofOfWorkService, ChannelDomain.SUPPORT); publicSupportChannelService = new PublicChannelService(persistenceService, networkService, userIdentityService, + userProfileService, ChannelDomain.SUPPORT, List.of(new PublicChannel(ChannelDomain.SUPPORT, "support"), new PublicChannel(ChannelDomain.SUPPORT, "questions"), diff --git a/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java index 0bba502a5f..7ec91631e2 100644 --- a/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/BasePrivateChannelService.java @@ -31,6 +31,7 @@ import bisq.user.identity.UserIdentity; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import bisq.user.profile.UserProfileService; import lombok.extern.slf4j.Slf4j; import java.util.Date; @@ -46,9 +47,10 @@ public abstract class BasePrivateChannelService, S extends PersistableStore> extends ChannelService implements DataService.Listener { - public BasePublicChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { - super(networkService, userIdentityService, channelDomain); + public BasePublicChannelService(NetworkService networkService, + UserIdentityService userIdentityService, + UserProfileService userProfileService, + ChannelDomain channelDomain) { + super(networkService, userIdentityService, userProfileService, channelDomain); } diff --git a/chat/src/main/java/bisq/chat/channel/ChannelService.java b/chat/src/main/java/bisq/chat/channel/ChannelService.java index 1f407c9a81..5b795b9675 100644 --- a/chat/src/main/java/bisq/chat/channel/ChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/ChannelService.java @@ -24,6 +24,7 @@ import bisq.persistence.PersistableStore; import bisq.persistence.PersistenceClient; import bisq.user.identity.UserIdentityService; +import bisq.user.profile.UserProfileService; import lombok.extern.slf4j.Slf4j; import java.util.Optional; @@ -33,11 +34,16 @@ public abstract class ChannelService implements Service, PersistenceClient { protected final NetworkService networkService; protected final UserIdentityService userIdentityService; + protected final UserProfileService userProfileService; protected final ChannelDomain channelDomain; - public ChannelService(NetworkService networkService, UserIdentityService userIdentityService, ChannelDomain channelDomain) { + public ChannelService(NetworkService networkService, + UserIdentityService userIdentityService, + UserProfileService userProfileService, + ChannelDomain channelDomain) { this.networkService = networkService; this.userIdentityService = userIdentityService; + this.userProfileService = userProfileService; this.channelDomain = channelDomain; } diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java index 9c9611db60..881a08a2d5 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannelService.java @@ -30,6 +30,7 @@ import bisq.user.identity.UserIdentity; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import bisq.user.profile.UserProfileService; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -46,9 +47,10 @@ public class PrivateChannelService extends BasePrivateChannelService defaultChannels) { - super(networkService, userIdentityService, channelDomain); + super(networkService, userIdentityService, userProfileService, channelDomain); this.defaultChannels = defaultChannels; diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java index 307f5bbf2d..7844e42b2d 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannelService.java @@ -34,6 +34,7 @@ import bisq.user.identity.UserIdentity; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import bisq.user.profile.UserProfileService; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -51,8 +52,9 @@ public class PrivateTradeChannelService extends BasePrivateChannelService { if (message.getMessageType() == MessageType.LEAVE) { return Optional.empty(); + } else if (userProfileService.isChatUserIgnored(message.getSender())) { + return Optional.empty(); } else { return Optional.of(traderCreatesNewChannel(myUserIdentity, message.getSender(), diff --git a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java index 0393c46128..202c47982c 100644 --- a/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java +++ b/chat/src/main/java/bisq/chat/trade/pub/PublicTradeChannelService.java @@ -32,6 +32,7 @@ import bisq.persistence.PersistenceService; import bisq.user.identity.UserIdentityService; import bisq.user.profile.UserProfile; +import bisq.user.profile.UserProfileService; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -52,8 +53,9 @@ public class PublicTradeChannelService extends BasePublicChannelService privateChannel) { //todo } } - if (!model.sortedList.isEmpty()) { - tradeChannelSelectionService.selectChannel(model.sortedList.get(0).getChannel()); - } else { - tradeChannelSelectionService.selectChannel(null); - } + + model.sortedList.stream().filter(e -> !e.getChannel().getId().equals(privateChannel.getId())) + .findFirst() + .ifPresentOrElse(e -> tradeChannelSelectionService.selectChannel(e.getChannel()), + () -> tradeChannelSelectionService.selectChannel(null)); } } diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java index 73a251b760..fd3d0cc5f5 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/channels/PublicTradeChannelSelection.java @@ -115,6 +115,8 @@ public void onActivate() { channel -> { if (channel instanceof PublicTradeChannel) { model.selectedChannelItem.set(new ChannelSelection.View.ChannelItem(channel)); + } else if (channel == null && !model.channelItems.isEmpty()) { + model.selectedChannelItem.set(model.channelItems.get(0)); } else { model.selectedChannelItem.set(null); } From 8f10df62298a8f48723ddd1f16051e17e2ddeb58 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 23 Dec 2022 20:50:59 -0500 Subject: [PATCH 15/15] Update members --- .../bisq/chat/channel/BasePublicChannel.java | 26 +++++++++++ .../main/java/bisq/chat/channel/Channel.java | 27 ++--------- .../bisq/chat/channel/PrivateChannel.java | 30 +++++++++++-- .../chat/trade/priv/PrivateTradeChannel.java | 45 ++++++++++++++++--- .../content/chat/sidebar/ChannelSidebar.java | 17 +++++-- 5 files changed, 110 insertions(+), 35 deletions(-) diff --git a/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java b/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java index 593cb7cca2..e7958831a9 100644 --- a/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java +++ b/chat/src/main/java/bisq/chat/channel/BasePublicChannel.java @@ -18,11 +18,17 @@ package bisq.chat.channel; import bisq.chat.message.BasePublicChatMessage; +import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; +import bisq.common.data.Pair; import bisq.common.observable.ObservableArray; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; +import java.util.*; +import java.util.stream.Collectors; + @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) @@ -33,4 +39,24 @@ public abstract class BasePublicChannel extends public BasePublicChannel(ChannelDomain channelDomain, String channelName, ChannelNotificationType channelNotificationType) { super(channelDomain, channelName, channelNotificationType); } + + @Override + public Set getMembers() { + Map> chatMessagesByAuthor = new HashMap<>(); + getChatMessages().forEach(chatMessage -> { + String authorId = chatMessage.getAuthorId(); + chatMessagesByAuthor.putIfAbsent(authorId, new ArrayList<>()); + chatMessagesByAuthor.get(authorId).add(chatMessage); + }); + + return chatMessagesByAuthor.entrySet().stream().map(entry -> { + List chatMessages = entry.getValue(); + chatMessages.sort(Comparator.comparing(chatMessage -> new Date(chatMessage.getDate()))); + ChatMessage lastChatMessage = chatMessages.get(chatMessages.size() - 1); + return new Pair<>(entry.getKey(), lastChatMessage); + }) + .filter(pair -> pair.getSecond().getMessageType() != MessageType.LEAVE) + .map(Pair::getFirst) + .collect(Collectors.toSet()); + } } diff --git a/chat/src/main/java/bisq/chat/channel/Channel.java b/chat/src/main/java/bisq/chat/channel/Channel.java index b667d871f5..85706adee9 100644 --- a/chat/src/main/java/bisq/chat/channel/Channel.java +++ b/chat/src/main/java/bisq/chat/channel/Channel.java @@ -18,10 +18,8 @@ package bisq.chat.channel; import bisq.chat.message.ChatMessage; -import bisq.chat.message.MessageType; import bisq.chat.trade.priv.PrivateTradeChannel; import bisq.chat.trade.pub.PublicTradeChannel; -import bisq.common.data.Pair; import bisq.common.observable.Observable; import bisq.common.observable.ObservableArray; import bisq.common.proto.Proto; @@ -30,8 +28,8 @@ import lombok.Getter; import lombok.ToString; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Collection; +import java.util.Set; @ToString @Getter @@ -92,24 +90,7 @@ public static Channel fromProto(bisq.chat.protobuf.Channe abstract public void removeChatMessages(Collection removeMessages); - abstract public String getDisplayString(); + abstract public Set getMembers(); - public Set getMembers() { - Map> chatMessagesByAuthor = new HashMap<>(); - getChatMessages().forEach(chatMessage -> { - String authorId = chatMessage.getAuthorId(); - chatMessagesByAuthor.putIfAbsent(authorId, new ArrayList<>()); - chatMessagesByAuthor.get(authorId).add(chatMessage); - }); - - return chatMessagesByAuthor.entrySet().stream().map(entry -> { - List chatMessages = entry.getValue(); - chatMessages.sort(Comparator.comparing(chatMessage -> new Date(chatMessage.getDate()))); - ChatMessage lastChatMessage = chatMessages.get(chatMessages.size() - 1); - return new Pair<>(entry.getKey(), lastChatMessage); - }) - .filter(pair -> pair.getSecond().getMessageType() != MessageType.LEAVE) - .map(Pair::getFirst) - .collect(Collectors.toSet()); - } + abstract public String getDisplayString(); } \ No newline at end of file diff --git a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java index dc1bd87b55..097e729515 100644 --- a/chat/src/main/java/bisq/chat/channel/PrivateChannel.java +++ b/chat/src/main/java/bisq/chat/channel/PrivateChannel.java @@ -17,6 +17,8 @@ package bisq.chat.channel; +import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.chat.message.PrivateChatMessage; import bisq.common.data.Pair; import bisq.user.identity.UserIdentity; @@ -25,9 +27,7 @@ import lombok.Getter; import lombok.ToString; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @ToString(callSuper = true) @@ -96,6 +96,30 @@ public void removeChatMessages(Collection removeMessages) { chatMessages.removeAll(removeMessages); } + @Override + public Set getMembers() { + Map> chatMessagesByAuthor = new HashMap<>(); + getChatMessages().forEach(chatMessage -> { + String authorId = chatMessage.getAuthorId(); + chatMessagesByAuthor.putIfAbsent(authorId, new ArrayList<>()); + chatMessagesByAuthor.get(authorId).add(chatMessage); + + String receiversId = chatMessage.getReceiversId(); + chatMessagesByAuthor.putIfAbsent(receiversId, new ArrayList<>()); + chatMessagesByAuthor.get(receiversId).add(chatMessage); + }); + + return chatMessagesByAuthor.entrySet().stream().map(entry -> { + List chatMessages = entry.getValue(); + chatMessages.sort(Comparator.comparing(chatMessage -> new Date(chatMessage.getDate()))); + ChatMessage lastChatMessage = chatMessages.get(chatMessages.size() - 1); + return new Pair<>(entry.getKey(), lastChatMessage); + }) + .filter(pair -> pair.getSecond().getMessageType() != MessageType.LEAVE) + .map(Pair::getFirst) + .collect(Collectors.toSet()); + } + @Override public String getDisplayString() { return peer.getUserName() + "-" + myUserIdentity.getUserName(); diff --git a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java index a4010fa12e..3d0a91543e 100644 --- a/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java +++ b/chat/src/main/java/bisq/chat/trade/priv/PrivateTradeChannel.java @@ -20,6 +20,8 @@ import bisq.chat.channel.BasePrivateChannel; import bisq.chat.channel.ChannelDomain; import bisq.chat.channel.ChannelNotificationType; +import bisq.chat.message.ChatMessage; +import bisq.chat.message.MessageType; import bisq.common.data.Pair; import bisq.common.observable.Observable; import bisq.i18n.Res; @@ -29,10 +31,7 @@ import lombok.Getter; import lombok.ToString; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -157,12 +156,48 @@ public String getDisplayString() { } } + @Override + public Set getMembers() { + Map> chatMessagesByAuthor = new HashMap<>(); + getChatMessages().forEach(chatMessage -> { + String authorId = chatMessage.getAuthorId(); + chatMessagesByAuthor.putIfAbsent(authorId, new ArrayList<>()); + chatMessagesByAuthor.get(authorId).add(chatMessage); + + String receiversId = chatMessage.getReceiversId(); + if (chatMessage.getMessageType() != MessageType.LEAVE) { + chatMessagesByAuthor.putIfAbsent(receiversId, new ArrayList<>()); + chatMessagesByAuthor.get(receiversId).add(chatMessage); + } + + chatMessage.getMediator().ifPresent(mediator -> { + if (inMediation.get()) { + String mediatorId = mediator.getId(); + chatMessagesByAuthor.putIfAbsent(mediatorId, new ArrayList<>()); + chatMessagesByAuthor.get(mediatorId).add(chatMessage); + } + }); + }); + + return chatMessagesByAuthor.entrySet().stream().map(entry -> { + List chatMessages = entry.getValue(); + chatMessages.sort(Comparator.comparing(chatMessage -> new Date(chatMessage.getDate()))); + ChatMessage lastChatMessage = chatMessages.get(chatMessages.size() - 1); + return new Pair<>(entry.getKey(), lastChatMessage); + }) + .filter(pair -> pair.getSecond().getMessageType() != MessageType.LEAVE) + .map(Pair::getFirst) + .collect(Collectors.toSet()); + } + public String getChannelSelectionDisplayString() { if (inMediation.get()) { if (isMediator()) { return peerOrTrader1.getUserName() + ", " + myUserProfileOrTrader2.getUserName(); + } else if (mediator.isPresent()) { + return peerOrTrader1.getUserName() + ", " + mediator.get().getUserName(); } else { - return peerOrTrader1.getUserName() + ", " + mediator.orElseThrow().getUserName(); + return peerOrTrader1.getUserName(); } } else { return peerOrTrader1.getUserName(); diff --git a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java index 65c9dc5454..2535c3e352 100644 --- a/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java +++ b/desktop/src/main/java/bisq/desktop/primary/main/content/chat/sidebar/ChannelSidebar.java @@ -100,6 +100,15 @@ public void onDeactivate() { } void setChannel(Channel channel) { + if (channel == null) { + model.descriptionVisible.set(false); + model.description.set(null); + model.adminProfile = Optional.empty(); + model.moderators.clear(); + model.channel.set(null); + return; + } + Set ignoredChatUserIds = new HashSet<>(userProfileService.getIgnoredUserProfileIds()); model.channelName.set(channel.getDisplayString()); model.members.setAll(channel.getMembers().stream() @@ -109,11 +118,11 @@ void setChannel(Channel channel) { .collect(Collectors.toList())); if (channel instanceof PublicChannel) { - PublicChannel publicEventsChannel = (PublicChannel) channel; - model.description.set(publicEventsChannel.getDescription()); + PublicChannel publicChannel = (PublicChannel) channel; + model.description.set(publicChannel.getDescription()); model.descriptionVisible.set(true); - model.adminProfile = userProfileService.findUserProfile(publicEventsChannel.getChannelAdminId()).map(ChatUserOverview::new); - model.moderators.setAll(publicEventsChannel.getChannelModeratorIds().stream() + model.adminProfile = userProfileService.findUserProfile(publicChannel.getChannelAdminId()).map(ChatUserOverview::new); + model.moderators.setAll(publicChannel.getChannelModeratorIds().stream() .flatMap(id -> userProfileService.findUserProfile(id).stream()) .map(ChatUserOverview::new) .sorted()