diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java
index 3f6188f..087a23d 100644
--- a/src/main/java/envoy/client/ui/controller/ChatScene.java
+++ b/src/main/java/envoy/client/ui/controller/ChatScene.java
@@ -16,6 +16,7 @@ import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
+import javafx.scene.paint.Paint;
import envoy.client.data.Chat;
import envoy.client.data.LocalDB;
@@ -62,6 +63,9 @@ public final class ChatScene {
@FXML
private Label remainingChars;
+ @FXML
+ private Label infoLabel;
+
@FXML
private MenuItem deleteContactMenuItem;
@@ -70,6 +74,8 @@ public final class ChatScene {
private WriteProxy writeProxy;
private SceneContext sceneContext;
+ private boolean postingPermanentlyDisabled = false;
+
private Chat currentChat;
private static final Settings settings = Settings.getInstance();
@@ -165,6 +171,7 @@ public final class ChatScene {
userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList())));
contactLabel.setText(localDB.getUser().getName());
MessageListCell.setUser(localDB.getUser());
+ if (!client.isOnline()) updateInfoLabel("You are offline", Color.YELLOW);
}
/**
@@ -244,10 +251,15 @@ public final class ChatScene {
*/
@FXML
private void checkPostConditions(KeyEvent e) {
- if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
- || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()))
- postMessage();
- postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
+ if (!postingPermanentlyDisabled) {
+ if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
+ || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()))
+ postMessage();
+ postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
+ } else if (!infoLabel.getText().equals("You need to go online to send more messages"))
+ // Informing the user that he is a f*cking moron and should use Envoy online
+ // because he ran out of messageIDs to use
+ updateInfoLabel("You need to go online to send more messages", Color.RED);
}
/**
@@ -286,6 +298,12 @@ public final class ChatScene {
*/
@FXML
private void postMessage() {
+ postingPermanentlyDisabled = !(client.isOnline() || localDB.getIDGenerator().hasNext());
+ if (postingPermanentlyDisabled) {
+ postButton.setDisable(true);
+ updateInfoLabel("You need to go online to send more messages", Color.RED);
+ return;
+ }
final var text = messageTextArea.getText().strip();
if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent.");
try {
@@ -322,6 +340,19 @@ public final class ChatScene {
*/
private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); }
+ /**
+ * Updates the {@code infoLabel}.
+ *
+ * @param text the text to use
+ * @param textfill the color in which to display information
+ * @since Envoy Client v0.1-beta
+ */
+ private void updateInfoLabel(String text, Paint textfill) {
+ infoLabel.setText(text);
+ infoLabel.setTextFill(textfill);
+ infoLabel.setVisible(true);
+ }
+
// Context menu actions
@FXML
diff --git a/src/main/java/envoy/client/ui/controller/LoginScene.java b/src/main/java/envoy/client/ui/controller/LoginScene.java
index b17fa81..020bd43 100644
--- a/src/main/java/envoy/client/ui/controller/LoginScene.java
+++ b/src/main/java/envoy/client/ui/controller/LoginScene.java
@@ -115,8 +115,7 @@ public final class LoginScene {
if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) {
new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait();
repeatPasswordField.clear();
- }
- else performHandshake(
+ } else performHandshake(
new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION));
}
@@ -190,9 +189,8 @@ public final class LoginScene {
localDB.synchronize();
- if (client.isOnline()) {
- writeProxy.flushCache();
- } else
+ if (client.isOnline()) writeProxy.flushCache();
+ else
// Set all contacts to offline mode
localDB.getChats()
.stream()
diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml
index 0a65449..fa1a4ef 100644
--- a/src/main/resources/fxml/ChatScene.fxml
+++ b/src/main/resources/fxml/ChatScene.fxml
@@ -19,27 +19,27 @@
fx:controller="envoy.client.ui.controller.ChatScene">
-
+
+ minHeight="10.0" percentHeight="7.0" vgrow="SOMETIMES" />
+
@@ -56,7 +56,7 @@
+ mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
@@ -72,8 +72,8 @@
@@ -93,25 +93,25 @@
-
-
-
-
+
+
+
+