From 8826d0c3d3bb4b6d372bc5a498373d758a8de1d0 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Fri, 12 Jun 2020 23:50:52 +0200 Subject: [PATCH] Added support for sending groupMessages * Implemented distinguishing between regular messages and groupMessages when sending messages to the server (and sends the right object obviously) --- .../envoy/client/ui/controller/ChatScene.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 8f7b487..cc6b018 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -241,7 +241,8 @@ public final class ChatScene { } /** - * Sends a new message to the server based on the text entered in the + * Sends a new message or groupMessage to the server based on the text entered + * in the * messageTextArea. * * @since Envoy Client v0.1-beta @@ -249,16 +250,29 @@ public final class ChatScene { @FXML private void postMessage() { try { - // Create and send message - final var message = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()) - .setText(messageTextArea.getText().strip()) - .build(); + if (currentChat.getRecipient().getClass().equals(Group.class)) { + // Create and send groupMessage + final var groupMessage = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()) + .setText(messageTextArea.getText().strip()) + .buildGroupMessage((Group) currentChat.getRecipient()); - // Send message - writeProxy.writeMessage(message); + // Send groupMessage + writeProxy.writeMessage(groupMessage); - // Add message to LocalDB and update UI - messageList.getItems().add(message); + // Add message to LocalDB and update UI + messageList.getItems().add(groupMessage); + } else { + // Create and send message + final var message = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()) + .setText(messageTextArea.getText().strip()) + .build(); + + // Send message + writeProxy.writeMessage(message); + + // Add message to LocalDB and update UI + messageList.getItems().add(message); + } // Request a new ID generator if all IDs were used if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();