From c784ebb787e7e68a465abf8b6af1fa48eafa0ff1 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 22 Aug 2020 18:14:26 +0200 Subject: [PATCH] Added option to disable attachments and groups on both client and server --- .../main/java/envoy/client/net/Client.java | 7 + .../main/java/envoy/client/net/Receiver.java | 2 +- .../envoy/client/ui/controller/ChatScene.java | 27 +++- .../ui/controller/ContactSearchScene.java | 9 +- .../ui/controller/GroupCreationScene.java | 22 ++- client/src/main/resources/fxml/ChatScene.fxml | 2 +- .../resources/fxml/ContactSearchScene.fxml | 2 +- .../java/envoy/event/GroupCreationResult.java | 25 +++ .../main/java/envoy/event/NoAttachments.java | 25 +++ .../main/java/envoy/server/data/Message.java | 3 +- .../java/envoy/server/data/ServerConfig.java | 14 ++ .../processors/GroupCreationProcessor.java | 10 +- .../processors/GroupMessageProcessor.java | 142 ++++++++++-------- .../server/processors/MessageProcessor.java | 10 +- server/src/main/resources/server.properties | 2 + 15 files changed, 219 insertions(+), 83 deletions(-) create mode 100644 common/src/main/java/envoy/event/GroupCreationResult.java create mode 100644 common/src/main/java/envoy/event/NoAttachments.java diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 9c9a9c4..923f721 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -164,6 +164,13 @@ public final class Client implements Closeable { // Process ProfilePicChanges receiver.registerProcessor(ProfilePicChange.class, eventBus::dispatch); + // Process requests to not send anymore attachments as they will not be shown to + // other users + receiver.registerProcessor(NoAttachments.class, eventBus::dispatch); + + // Process group creation rejections - they have been disabled on the server + receiver.registerProcessor(GroupCreationResult.class, eventBus::dispatch); + // Send event eventBus.register(SendEvent.class, evt -> { try { diff --git a/client/src/main/java/envoy/client/net/Receiver.java b/client/src/main/java/envoy/client/net/Receiver.java index dbc5220..ce510cf 100644 --- a/client/src/main/java/envoy/client/net/Receiver.java +++ b/client/src/main/java/envoy/client/net/Receiver.java @@ -69,7 +69,7 @@ public final class Receiver extends Thread { // Server has stopped sending, i.e. because he went offline if (len == 0 && bytesRead == -1) { isAlive = false; - logger.log(Level.WARNING, "Lost connection to the server. Exiting receiver"); + logger.log(Level.INFO, "Lost connection to the server. Exiting receiver..."); continue; } logger.log(Level.WARNING, diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 173784f..fa788e4 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -87,6 +87,12 @@ public final class ChatScene implements Restorable { @FXML private Button rotateButton; + @FXML + private Button messageSearchButton; + + @FXML + private Button newGroupButton; + @FXML private TextArea messageTextArea; @@ -108,9 +114,6 @@ public final class ChatScene implements Restorable { @FXML private Label topBarStatusLabel; - @FXML - private Button messageSearchButton; - @FXML private ImageView clientProfilePic; @@ -129,7 +132,8 @@ public final class ChatScene implements Restorable { private AudioRecorder recorder; private boolean recording; private Attachment pendingAttachment; - private boolean postingPermanentlyDisabled; + + private boolean postingPermanentlyDisabled; private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap(); @@ -237,6 +241,21 @@ public final class ChatScene implements Restorable { break; } }); + + // Disable attachment button if server says attachments will be filtered out + eventBus.register(NoAttachments.class, e -> { + Platform.runLater(() -> { + attachmentButton.setDisable(true); + voiceButton.setDisable(true); + final var alert = new Alert(AlertType.ERROR); + alert.setTitle("No attachments possible"); + alert.setHeaderText("Your current server does not support attachments."); + alert.setContentText("If this is unplanned, please contact your server administrator."); + alert.showAndWait(); + }); + }); + + eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); })); } /** diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 7258f8b..63f16b0 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -6,10 +6,8 @@ import java.util.logging.Logger; import javafx.application.Platform; import javafx.fxml.FXML; -import javafx.scene.control.Alert; +import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.ButtonType; -import javafx.scene.control.ListView; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; @@ -20,6 +18,7 @@ import envoy.client.ui.listcell.ListCellFactory; import envoy.data.User; import envoy.event.ElementOperation; import envoy.event.EventBus; +import envoy.event.GroupCreationResult; import envoy.event.contact.ContactOperation; import envoy.event.contact.UserSearchRequest; import envoy.event.contact.UserSearchResult; @@ -50,6 +49,9 @@ public final class ContactSearchScene { @FXML private ListView userList; + @FXML + private Button newGroupButton; + private SceneContext sceneContext; private LocalDB localDB; @@ -86,6 +88,7 @@ public final class ContactSearchScene { eventBus.register(UserSearchResult.class, response -> Platform.runLater(() -> { userList.getItems().clear(); userList.getItems().addAll(response.get()); })); eventBus.register(ContactOperation.class, handler); + eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); })); } /** diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index 6b16d2e..da9e997 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -21,6 +21,7 @@ import envoy.data.Group; import envoy.data.User; import envoy.event.EventBus; import envoy.event.GroupCreation; +import envoy.event.GroupCreationResult; import envoy.util.Bounds; /** @@ -54,6 +55,8 @@ public final class GroupCreationScene { private LocalDB localDB; + private String groupName; + private static final EventBus eventBus = EventBus.getInstance(); @FXML @@ -61,6 +64,18 @@ public final class GroupCreationScene { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); }); + eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { + if (e.get()) new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", groupName)).showAndWait(); + else { + createButton.setDisable(true); + final var alert = new Alert(AlertType.ERROR); + alert.setTitle("Groups are not allowed"); + alert.setHeaderText("Cannot create group as your current server disabled this feature"); + alert.setContentText("If this is unplanned, please contact your server administrator."); + alert.showAndWait(); + sceneContext.pop(); + } + })); } /** @@ -119,10 +134,7 @@ public final class GroupCreationScene { alert.setTitle("Create Group?"); alert.setHeaderText("Proceed?"); alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> createGroup(name)); - } else { - new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait(); - createGroup(name); - } + } else createGroup(name); } /** @@ -133,9 +145,9 @@ public final class GroupCreationScene { * @since Envoy Client v0.1-beta */ private void createGroup(String name) { + groupName = name; eventBus.dispatch(new SendEvent( new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet())))); - sceneContext.pop(); } /** diff --git a/client/src/main/resources/fxml/ChatScene.fxml b/client/src/main/resources/fxml/ChatScene.fxml index 5bf8cd1..5b6bf77 100644 --- a/client/src/main/resources/fxml/ChatScene.fxml +++ b/client/src/main/resources/fxml/ChatScene.fxml @@ -62,7 +62,7 @@ -