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

Add remove mediation case button #3274

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 @@ -18,6 +18,7 @@
package bisq.desktop.main.content.authorized_role.mediator;

import bisq.chat.ChatService;
import bisq.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannel;
import bisq.chat.bisq_easy.open_trades.BisqEasyOpenTradeChannelService;
import bisq.chat.priv.LeavePrivateChatManager;
import bisq.common.data.Triple;
Expand All @@ -26,6 +27,7 @@
import bisq.desktop.components.overlay.Popup;
import bisq.desktop.main.content.components.UserProfileDisplay;
import bisq.i18n.Res;
import bisq.settings.DontShowAgainService;
import bisq.support.mediation.MediatorService;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -75,6 +77,7 @@ private static class Controller implements bisq.desktop.common.view.Controller {
private final Runnable onCloseHandler;
private final Runnable onReOpenHandler;
private final LeavePrivateChatManager leavePrivateChatManager;
private final DontShowAgainService dontShowAgainService;

private Controller(ServiceProvider serviceProvider, Runnable onCloseHandler, Runnable onReOpenHandler) {
this.onCloseHandler = onCloseHandler;
Expand All @@ -83,6 +86,7 @@ private Controller(ServiceProvider serviceProvider, Runnable onCloseHandler, Run
channelService = chatService.getBisqEasyOpenTradeChannelService();
leavePrivateChatManager = chatService.getLeavePrivateChatManager();
mediatorService = serviceProvider.getSupportService().getMediatorService();
dontShowAgainService = serviceProvider.getDontShowAgainService();

model = new Model();
view = new View(model, this);
Expand All @@ -104,38 +108,89 @@ void onToggleOpenClose() {
if (model.getShowClosedCases().get()) {
doReOpen();
} else {
new Popup().warning(Res.get("authorizedRole.mediator.close.warning"))
String key = "mediator.close.warning";
if (dontShowAgainService.showAgain(key)) {
new Popup().warning(Res.get("authorizedRole.mediator.close.warning"))
.dontShowAgainId(key)
.actionButtonText(Res.get("confirmation.yes"))
.onAction(this::doClose)
.closeButtonText(Res.get("confirmation.no"))
.show();
} else {
doClose();
}
}
}

void onLeaveChannel() {
String key = "mediator.leaveChannel.warning";
if (dontShowAgainService.showAgain(key)) {
new Popup().warning(Res.get("authorizedRole.mediator.leaveChannel.warning"))
.dontShowAgainId(key)
.actionButtonText(Res.get("confirmation.yes"))
.onAction(this::doClose)
.onAction(this::doLeave)
.closeButtonText(Res.get("confirmation.no"))
.show();
} else {
doLeave();
}
}

void onLeaveChannel() {
new Popup().warning(Res.get("authorizedRole.mediator.leaveChannel.warning"))
.actionButtonText(Res.get("confirmation.yes"))
.onAction(this::doLeave)
.closeButtonText(Res.get("confirmation.no"))
.show();
void onRemoveCase() {
String key = "mediator.removeCase.warning";
if (dontShowAgainService.showAgain(key)) {
new Popup().warning(Res.get("authorizedRole.mediator.removeCase.warning"))
.dontShowAgainId(key)
.actionButtonText(Res.get("confirmation.yes"))
.onAction(this::deRemoveCase)
.closeButtonText(Res.get("confirmation.no"))
.show();
} else {
deRemoveCase();
}
}

private void deRemoveCase() {
MediationCaseListItem listItem = model.getMediationCaseListItem().get();
if (listItem != null) {
doClose();
doLeave();
mediatorService.removeMediationCase(listItem.getMediationCase());
}
}

private void doLeave() {
leavePrivateChatManager.leaveChannel(model.getMediationCaseListItem().get().getChannel());
MediationCaseListItem listItem = model.getMediationCaseListItem().get();
if (listItem != null) {
BisqEasyOpenTradeChannel channel = listItem.getChannel();
if (channel != null) {
leavePrivateChatManager.leaveChannel(channel);
}
}
}

private void doClose() {
MediationCaseListItem listItem = model.getMediationCaseListItem().get();
channelService.sendTradeLogMessage(Res.encode("authorizedRole.mediator.close.tradeLogMessage"), listItem.getChannel());
mediatorService.closeMediationCase(listItem.getMediationCase());
onCloseHandler.run();
if (listItem != null) {
BisqEasyOpenTradeChannel channel = listItem.getChannel();
if (channel != null) {
channelService.sendTradeLogMessage(Res.encode("authorizedRole.mediator.close.tradeLogMessage"), channel);
}
mediatorService.closeMediationCase(listItem.getMediationCase());
onCloseHandler.run();
}
}

private void doReOpen() {
MediationCaseListItem listItem = model.getMediationCaseListItem().get();
channelService.sendTradeLogMessage(Res.encode("authorizedRole.mediator"), listItem.getChannel());
mediatorService.reOpenMediationCase(listItem.getMediationCase());
onReOpenHandler.run();
if (listItem != null) {
BisqEasyOpenTradeChannel channel = listItem.getChannel();
if (channel != null) {
channelService.sendTradeLogMessage(Res.encode("authorizedRole.mediator"), channel);
}
mediatorService.reOpenMediationCase(listItem.getMediationCase());
onReOpenHandler.run();
}
}
}

Expand All @@ -153,7 +208,7 @@ private static class View extends bisq.desktop.common.view.View<HBox, Model, Con
private final Triple<Text, Text, VBox> tradeId;
private final UserProfileDisplay makerProfileDisplay, takerProfileDisplay;
private final Label directionalTitle;
private final Button openCloseButton, leaveButton;
private final Button openCloseButton, leaveButton, removeButton;
private Subscription mediationCaseListItemPin, showClosedCasesPin;

private View(Model model, Controller controller) {
Expand Down Expand Up @@ -188,12 +243,18 @@ private View(Model model, Controller controller) {
leaveButton.setMinWidth(120);
leaveButton.setStyle("-fx-padding: 5 16 5 16");

removeButton = new Button(Res.get("authorizedRole.mediator.remove"));
removeButton.setMinWidth(120);
removeButton.setStyle("-fx-padding: 5 16 5 16");

Region spacer = Spacer.fillHBox();
HBox.setMargin(spacer, new Insets(0, -50, 0, 0));
HBox.setMargin(directionalTitle, new Insets(10, -20, 0, -20));
HBox.setMargin(leaveButton, new Insets(0, -20, 0, 0));
HBox.setMargin(removeButton, new Insets(0, -20, 0, 0));
HBox.setMargin(openCloseButton, new Insets(0, -20, 0, 0));
root.getChildren().addAll(maker.getThird(), directionalTitle, taker.getThird(), tradeId.getThird(), spacer, leaveButton, openCloseButton);
root.getChildren().addAll(maker.getThird(), directionalTitle, taker.getThird(), tradeId.getThird(), spacer,
removeButton, leaveButton, openCloseButton);
}

@Override
Expand Down Expand Up @@ -244,6 +305,7 @@ protected void onViewAttached() {
});
openCloseButton.setOnAction(e -> controller.onToggleOpenClose());
leaveButton.setOnAction(e -> controller.onLeaveChannel());
removeButton.setOnAction(e -> controller.onRemoveCase());
}

@Override
Expand All @@ -252,6 +314,7 @@ protected void onViewDetached() {
showClosedCasesPin.unsubscribe();
openCloseButton.setOnAction(null);
leaveButton.setOnAction(null);
removeButton.setOnAction(null);

makerProfileDisplay.dispose();
takerProfileDisplay.dispose();
Expand Down
3 changes: 3 additions & 0 deletions i18n/src/main/resources/authorized_role.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ authorizedRole.mediator.table.taker=Taker
authorizedRole.mediator.close=Close case
authorizedRole.mediator.reOpen=Re-open case
authorizedRole.mediator.leave=Leave chat
authorizedRole.mediator.remove=Remove case
authorizedRole.mediator.showClosedCases=Show closed cases
authorizedRole.mediator.hasRequested={0}\nHas requested mediation: {1}
authorizedRole.mediator.close.warning=Are you sure you want to close the mediation case?\n\n\
Expand All @@ -65,6 +66,8 @@ authorizedRole.mediator.table.header.closeCaseDate=Close date
authorizedRole.mediator=The mediator has re-opened the case.
authorizedRole.mediator.leaveChannel.warning=Are you sure you want to leave the chat channel?\n\n\
Once you left the chat channel all messages and channel data are gone, and you cannot communicate with the traders anymore.
authorizedRole.mediator.removeCase.warning=Are you sure you want to remove that mediation case?\n\n\
Once you remove the mediation case you leave the chat channel and all data for that case is gone. You cannot undo that.


################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public void closeMediationCase(MediationCase mediationCase) {
persist();
}

public void removeMediationCase(MediationCase mediationCase) {
getMediationCases().remove(mediationCase);
persist();
}

public void reOpenMediationCase(MediationCase mediationCase) {
mediationCase.setClosed(false);
persist();
Expand Down
Loading