Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various refactorings [1] #1427

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public BisqEasyNotificationsService(NotificationsService notificationsService) {
public CompletableFuture<Boolean> initialize() {
log.info("initialize");

notificationsService.subscribe(changed -> {
notificationsService.subscribe(notificationId -> {
tradeIdsOfNotifications.setAll(notificationsService.getNotConsumedNotificationIds().stream()
.filter(id -> ChatNotificationService.getChatChannelDomain(id) == ChatChannelDomain.BISQ_EASY_OPEN_TRADES)
.flatMap(id -> ChatNotificationService.findTradeId(id).stream())
Expand Down
4 changes: 2 additions & 2 deletions chat/src/main/java/bisq/chat/ChatChannelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ protected void doRemoveExpiredMessages(C channel) {
}
}

public Optional<C> findChannel(String id) {
public Optional<C> findChannel(String channelId) {
return getChannels().stream()
.filter(channel -> channel.getId().equals(id))
.filter(channel -> channel.getId().equals(channelId))
.findAny();
}

Expand Down
2 changes: 1 addition & 1 deletion chat/src/main/java/bisq/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public BisqEasyOfferbookSelectionService getBisqEasyOfferbookChannelSelectionSer
return (BisqEasyOfferbookSelectionService) getChatChannelSelectionServices().get(ChatChannelDomain.BISQ_EASY_OFFERBOOK);
}

public BisqEasyOpenTradeSelectionService getBisqEasyOpenTradesChannelSelectionService() {
public BisqEasyOpenTradeSelectionService getBisqEasyOpenTradesSelectionService() {
return (BisqEasyOpenTradeSelectionService) getChatChannelSelectionServices().get(ChatChannelDomain.BISQ_EASY_OPEN_TRADES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@Getter
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
public final class BisqEasyOpenTradeChannel extends PrivateGroupChatChannel<BisqEasyOpenTradeMessage> {
public static String createChannelId(String tradeId) {
public static String createId(String tradeId) {
return ChatChannelDomain.BISQ_EASY_OPEN_TRADES.name().toLowerCase() + "." + tradeId;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ private BisqEasyOpenTradeChannel(String tradeId,
UserIdentity myUserIdentity,
UserProfile peer,
Optional<UserProfile> mediator) {
this(createChannelId(tradeId),
this(createId(tradeId),
tradeId,
bisqEasyOffer,
myUserIdentity,
Expand All @@ -105,7 +105,7 @@ private BisqEasyOpenTradeChannel(String tradeId,
UserIdentity myUserIdentity,
UserProfile requestingTrader,
UserProfile nonRequestingTrader) {
this(createChannelId(tradeId),
this(createId(tradeId),
tradeId,
bisqEasyOffer,
myUserIdentity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
public final class TwoPartyPrivateChatChannel extends PrivateChatChannel<TwoPartyPrivateChatMessage> {
// Channel id must be deterministic, so we sort both userIds and use that order for the concatenated string.
public static String createId(ChatChannelDomain ChatChannelDomain, String userProfileId1, String userProfileId2) {
public static String createId(ChatChannelDomain chatChannelDomain, String userProfileId1, String userProfileId2) {
List<String> userIds = Stream.of(userProfileId1, userProfileId2)
.sorted()
.collect(Collectors.toList());
return ChatChannelDomain.name().toLowerCase() + "." + userIds.get(0) + "-" + userIds.get(1);
return chatChannelDomain.name().toLowerCase() + "." + userIds.get(0) + "-" + userIds.get(1);
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static <T> boolean isCompleted(CompletableFuture<T> future) {
// Borrowed from https://4comprehension.com/be-careful-with-completablefuture-applytoeither/
public static <T> CompletableFuture<T> either(CompletableFuture<T> f1, CompletableFuture<T> f2) {
CompletableFuture<T> result = new CompletableFuture<>();
CompletableFuture.allOf(f1, f2).whenComplete((__, throwable) -> {
CompletableFuture.allOf(f1, f2).whenComplete((nil, throwable) -> {
if (f1.isCompletedExceptionally() && f2.isCompletedExceptionally()) {
result.completeExceptionally(throwable);
}
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/main/java/bisq/desktop/DesktopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void onApplicationServiceInitialized(Boolean result, Throwable throwable)

public void onUncaughtException(Thread thread, Throwable throwable) {
log.error("Uncaught exception from thread {}", thread);
log.error("Uncaught exception", throwable);
log.error("Uncaught exception:", throwable);
UIThread.run(() -> new Popup().error(throwable).show());
}

Expand Down
2 changes: 1 addition & 1 deletion desktop/src/main/java/bisq/desktop/common/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void handleSceneChange(Scene oldValue, Scene newScene) {
if (!controller.useCaching()) {
// If we do not use caching we do not expect to get added again to stage without creating a
// new instance of the view, so we remove our sceneChangeListener.
UIThread.runOnNextRenderFrame(() -> root.sceneProperty().removeListener(View.this.sceneChangeListener));
UIThread.runOnNextRenderFrame(() -> root.sceneProperty().removeListener(sceneChangeListener));
if (oldValue.getWindow() != null && windowChangeListener != null) {
UIThread.runOnNextRenderFrame(() -> oldValue.windowProperty().removeListener(windowChangeListener));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public BisqEasyOpenTradesController(ServiceProvider serviceProvider) {
super(serviceProvider, ChatChannelDomain.BISQ_EASY_OPEN_TRADES, NavigationTarget.BISQ_EASY_OPEN_TRADES);

channelService = chatService.getBisqEasyOpenTradeChannelService();
selectionService = chatService.getBisqEasyOpenTradesChannelSelectionService();
selectionService = chatService.getBisqEasyOpenTradesSelectionService();
bisqEasyTradeService = serviceProvider.getTradeService().getBisqEasyTradeService();
settingsService = serviceProvider.getSettingsService();
reputationService = serviceProvider.getUserService().getReputationService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public TradeStateController(ServiceProvider serviceProvider) {
bisqEasyTradeService = serviceProvider.getTradeService().getBisqEasyTradeService();
ChatService chatService = serviceProvider.getChatService();
channelService = chatService.getBisqEasyOpenTradeChannelService();
selectionService = chatService.getBisqEasyOpenTradesChannelSelectionService();
selectionService = chatService.getBisqEasyOpenTradesSelectionService();
mediationService = serviceProvider.getSupportService().getMediationService();

tradePhaseBox = new TradePhaseBox(serviceProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected Controller(ServiceProvider serviceProvider, BisqEasyTrade bisqEasyTrad
accountService = serviceProvider.getAccountService();
userIdentityService = serviceProvider.getUserService().getUserIdentityService();
channelService = serviceProvider.getChatService().getBisqEasyOpenTradeChannelService();
selectionService = serviceProvider.getChatService().getBisqEasyOpenTradesChannelSelectionService();
selectionService = serviceProvider.getChatService().getBisqEasyOpenTradesSelectionService();

model = createModel(bisqEasyTrade, channel);
view = createView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Controller(ServiceProvider serviceProvider, BisqEasyTrade bisqEasyTrade,

explorerService = serviceProvider.getBondedRolesService().getExplorerService();
bisqEasyOpenTradeChannelService = serviceProvider.getChatService().getBisqEasyOpenTradeChannelService();
bisqEasyOpenTradeSelectionService = serviceProvider.getChatService().getBisqEasyOpenTradesChannelSelectionService();
bisqEasyOpenTradeSelectionService = serviceProvider.getChatService().getBisqEasyOpenTradesSelectionService();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Controller(ServiceProvider serviceProvider, BisqEasyTrade bisqEasyTrade,

explorerService = serviceProvider.getBondedRolesService().getExplorerService();
bisqEasyOpenTradeChannelService = serviceProvider.getChatService().getBisqEasyOpenTradeChannelService();
bisqEasyOpenTradeSelectionService = serviceProvider.getChatService().getBisqEasyOpenTradesChannelSelectionService();
bisqEasyOpenTradeSelectionService = serviceProvider.getChatService().getBisqEasyOpenTradesSelectionService();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void onDownload() {
model.getHeadline().set(Res.get("updater.downloadAndVerify.headline"));
try {
updaterService.downloadAndVerify()
.whenComplete((__, throwable) -> {
.whenComplete((nil, throwable) -> {
if (throwable == null) {
UIThread.run(() -> model.getDownloadAndVerifyCompleted().set(true));
} else if (!(throwable instanceof CancellationException)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void onApplicationServiceInitialized(Boolean result, Throwable throwab
@Override
protected void setDefaultUncaughtExceptionHandler() {
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
log.error("Uncaught exception", throwable);
log.error("Uncaught exception:", throwable);
UIThread.run(() -> {
if (desktopController != null) {
desktopController.onUncaughtException(thread, throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<CompletableFuture<Inventory>> request(DataFilter dataFilter) {
requestHandlerMap.put(key, handler);
return handler.request(dataFilter)
.orTimeout(TIMEOUT, TimeUnit.SECONDS)
.whenComplete((__, throwable) -> requestHandlerMap.remove(key));
.whenComplete((inventory, throwable) -> requestHandlerMap.remove(key));
})
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void sendPing(Connection connection) {
requestHandlerMap.put(key, handler);
handler.request()
.orTimeout(TIMEOUT_SEC, TimeUnit.SECONDS)
.whenComplete((__, throwable) -> requestHandlerMap.remove(key));
.whenComplete((nil, throwable) -> requestHandlerMap.remove(key));
}

public void shutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void request(Connection connection) {
requestHandlerMap.put(key, handler);
handler.request()
.orTimeout(TIMEOUT_SEC, TimeUnit.SECONDS)
.whenComplete((__, throwable) -> requestHandlerMap.remove(key));
.whenComplete((nil, throwable) -> requestHandlerMap.remove(key));
}

public void shutdown() {
Expand Down