Added support for sending groupMessages

* Implemented distinguishing between regular messages and groupMessages
when sending messages to the server (and sends the right object
obviously)
This commit is contained in:
DieGurke 2020-06-12 23:50:52 +02:00
parent 1a8c7dcfea
commit 8826d0c3d3

View File

@ -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. * messageTextArea.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
@ -249,6 +250,18 @@ public final class ChatScene {
@FXML @FXML
private void postMessage() { private void postMessage() {
try { try {
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 groupMessage
writeProxy.writeMessage(groupMessage);
// Add message to LocalDB and update UI
messageList.getItems().add(groupMessage);
} else {
// Create and send message // Create and send message
final var message = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()) final var message = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
.setText(messageTextArea.getText().strip()) .setText(messageTextArea.getText().strip())
@ -259,6 +272,7 @@ public final class ChatScene {
// Add message to LocalDB and update UI // Add message to LocalDB and update UI
messageList.getItems().add(message); messageList.getItems().add(message);
}
// Request a new ID generator if all IDs were used // Request a new ID generator if all IDs were used
if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator(); if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();