Skip to content

Commit

Permalink
Merge pull request #616 from HenrikJannsen/chat_domain_improvements
Browse files Browse the repository at this point in the history
Chat domain improvements
  • Loading branch information
alvasw authored Dec 30, 2022
2 parents 5e15bc7 + 8f10df6 commit e14c4fa
Show file tree
Hide file tree
Showing 86 changed files with 2,024 additions and 3,638 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
103 changes: 65 additions & 38 deletions chat/src/main/java/bisq/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@

package bisq.chat;

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.channel.*;
import bisq.chat.trade.TradeChannelSelectionService;
import bisq.chat.trade.priv.PrivateTradeChannelService;
import bisq.chat.trade.pub.PublicTradeChannelService;
Expand All @@ -36,79 +28,114 @@
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;

import java.util.List;
import java.util.concurrent.CompletableFuture;

@Slf4j
@Getter
public class ChatService implements Service {
private final PrivateTradeChannelService privateTradeChannelService;
private final PrivateDiscussionChannelService privateDiscussionChannelService;
private final PrivateChannelService privateDiscussionChannelService;
private final PublicTradeChannelService publicTradeChannelService;
private final PublicDiscussionChannelService publicDiscussionChannelService;
private final PublicChannelService publicDiscussionChannelService;
private final TradeChannelSelectionService tradeChannelSelectionService;
private final DiscussionChannelSelectionService discussionChannelSelectionService;
private final PrivateSupportChannelService privateSupportChannelService;
private final PublicSupportChannelService publicSupportChannelService;
private final SupportChannelSelectionService supportChannelSelectionService;
private final PrivateEventsChannelService privateEventsChannelService;
private final PublicEventsChannelService publicEventsChannelService;
private final EventsChannelSelectionService eventsChannelSelectionService;
private final ChannelSelectionService discussionChannelSelectionService;
private final PrivateChannelService privateSupportChannelService;
private final PublicChannelService publicSupportChannelService;
private final ChannelSelectionService supportChannelSelectionService;
private final PrivateChannelService privateEventsChannelService;
private final PublicChannelService publicEventsChannelService;
private final ChannelSelectionService eventsChannelSelectionService;

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);

// Discussion
privateDiscussionChannelService = new PrivateDiscussionChannelService(persistenceService,
privateDiscussionChannelService = new PrivateChannelService(persistenceService,
networkService,
userIdentityService,
proofOfWorkService);
publicDiscussionChannelService = new PublicDiscussionChannelService(persistenceService,
userProfileService,
proofOfWorkService,
ChannelDomain.DISCUSSION);
publicDiscussionChannelService = new PublicChannelService(persistenceService,
networkService,
userIdentityService);
discussionChannelSelectionService = new DiscussionChannelSelectionService(persistenceService,
userIdentityService,
userProfileService,
ChannelDomain.DISCUSSION,
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 ChannelSelectionService(persistenceService,
privateDiscussionChannelService,
publicDiscussionChannelService);
publicDiscussionChannelService,
ChannelDomain.DISCUSSION);

// Events
privateEventsChannelService = new PrivateEventsChannelService(persistenceService,
privateEventsChannelService = new PrivateChannelService(persistenceService,
networkService,
userIdentityService,
proofOfWorkService);
publicEventsChannelService = new PublicEventsChannelService(persistenceService,
userProfileService,
proofOfWorkService,
ChannelDomain.EVENTS);
publicEventsChannelService = new PublicChannelService(persistenceService,
networkService,
userIdentityService);
eventsChannelSelectionService = new EventsChannelSelectionService(persistenceService,
userIdentityService,
userProfileService,
ChannelDomain.EVENTS,
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 PrivateSupportChannelService(persistenceService,
privateSupportChannelService = new PrivateChannelService(persistenceService,
networkService,
userIdentityService,
proofOfWorkService);
publicSupportChannelService = new PublicSupportChannelService(persistenceService,
userProfileService,
proofOfWorkService,
ChannelDomain.SUPPORT);
publicSupportChannelService = new PublicChannelService(persistenceService,
networkService,
userIdentityService);
supportChannelSelectionService = new SupportChannelSelectionService(persistenceService,
userIdentityService,
userProfileService,
ChannelDomain.SUPPORT,
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
Expand Down
66 changes: 66 additions & 0 deletions chat/src/main/java/bisq/chat/channel/BasePrivateChannel.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<T extends BasePrivateChatMessage> extends Channel<T> {

public static String createChannelName(Pair<String, String> 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<T> chatMessages = new ObservableArray<>();

public BasePrivateChannel(ChannelDomain channelDomain,
String channelName,
UserIdentity myUserIdentity,
List<T> 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();
}
Loading

0 comments on commit e14c4fa

Please sign in to comment.