Added option to disable attachments and groups on both client and server

This commit is contained in:
delvh
2020-08-22 18:14:26 +02:00
parent eb4e421974
commit c784ebb787
15 changed files with 219 additions and 83 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -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()); }));
}
/**

View File

@ -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<User> 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()); }));
}
/**

View File

@ -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();
}
/**

View File

@ -62,7 +62,7 @@
<Insets />
</HBox.margin>
</Button>
<Button mnemonicParsing="false" prefWidth="100.0" text="New Group">
<Button fx:id="newGroupButton" mnemonicParsing="false" prefWidth="100.0" text="New Group">
<HBox.margin>
<Insets />
</HBox.margin>

View File

@ -34,7 +34,7 @@
wrapText="true" />
</tooltip>
</ClearableTextField>
<Button mnemonicParsing="false"
<Button fx:id="newGroupButton" mnemonicParsing="false"
onAction="#newGroupButtonClicked" prefHeight="26.0"
prefWidth="139.0" text="New Group">
<HBox.margin>