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