diff --git a/client/src/main/java/envoy/client/event/MessageCreationEvent.java b/client/src/main/java/envoy/client/event/MessageCreationEvent.java
deleted file mode 100644
index b9a4556..0000000
--- a/client/src/main/java/envoy/client/event/MessageCreationEvent.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package envoy.client.event;
-
-import envoy.data.Message;
-import envoy.event.Event;
-
-/**
- * Project: envoy-client
- * File: MessageCreationEvent.java
- * Created: 4 Dec 2019
- *
- * @author Kai S. K. Engelbart
- * @since Envoy Client v0.2-alpha
- */
-public final class MessageCreationEvent extends Event {
-
- private static final long serialVersionUID = 0L;
-
- /**
- * @param message the {@link Message} that has been created
- */
- public MessageCreationEvent(Message message) { super(message); }
-}
diff --git a/client/src/main/java/envoy/client/event/MessageModificationEvent.java b/client/src/main/java/envoy/client/event/MessageModificationEvent.java
deleted file mode 100644
index 5f1c6f0..0000000
--- a/client/src/main/java/envoy/client/event/MessageModificationEvent.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package envoy.client.event;
-
-import envoy.data.Message;
-import envoy.event.Event;
-
-/**
- * Project: envoy-client
- * File: MessageModificationEvent.java
- * Created: 4 Dec 2019
- *
- * @author Kai S. K. Engelbart
- * @since Envoy Client v0.2-alpha
- */
-public final class MessageModificationEvent extends Event {
-
- private static final long serialVersionUID = 0L;
-
- /**
- * @param message the {@link Message} that has been modified
- */
- public MessageModificationEvent(Message message) { super(message); }
-}
diff --git a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java
index 297bedc..ec5210b 100644
--- a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java
+++ b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java
@@ -3,7 +3,6 @@ package envoy.client.net;
import java.util.function.Consumer;
import java.util.logging.Logger;
-import envoy.client.event.MessageCreationEvent;
import envoy.data.GroupMessage;
import envoy.data.Message.MessageStatus;
import envoy.util.EnvoyLog;
@@ -28,7 +27,7 @@ public final class ReceivedGroupMessageProcessor implements Consumer {
// Update status to RECEIVED
if (message.getStatus() == MessageStatus.SENT) message.nextStatus();
- // Dispatch event
- EventBus.getInstance().dispatch(new MessageCreationEvent(message));
+ // Dispatch message
+ EventBus.getInstance().dispatch(message);
}
}
diff --git a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java
index c4b995a..8824bd8 100644
--- a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java
+++ b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java
@@ -6,7 +6,6 @@ import java.awt.TrayIcon.MessageType;
import javafx.application.Platform;
import javafx.stage.Stage;
-import envoy.client.event.MessageCreationEvent;
import envoy.data.Message;
import dev.kske.eventbus.*;
@@ -91,9 +90,10 @@ public final class StatusTrayIcon implements EventListener {
public void hide() { SystemTray.getSystemTray().remove(trayIcon); }
@Event
- private void onMessageCreation(MessageCreationEvent evt) {
- if (displayMessages) trayIcon
- .displayMessage(evt.get().hasAttachment() ? "New " + evt.get().getAttachment().getType().toString().toLowerCase() + " message received"
- : "New message received", evt.get().getText(), MessageType.INFO);
+ private void onMessage(Message evt) {
+ if (displayMessages) trayIcon.displayMessage(
+ evt.hasAttachment() ? "New " + evt.getAttachment().getType().toString().toLowerCase() + " message received" : "New message received",
+ evt.getText(),
+ MessageType.INFO);
}
}
diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java
index e8f5c61..36845a3 100644
--- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java
+++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java
@@ -211,8 +211,7 @@ public final class ChatScene implements EventListener, Restorable {
private void onBackEvent() { tabPane.getSelectionModel().select(Tabs.CONTACT_LIST.ordinal()); }
@Event
- private void onMessageCreation(MessageCreationEvent evt) {
- final var message = evt.get();
+ private void onMessage(Message message) {
// The sender of the message is the recipient of the chat
// Exceptions: this user is the sender (sync) or group message (group is
@@ -245,10 +244,10 @@ public final class ChatScene implements EventListener, Restorable {
@Event
private void onMessageStatusChange(MessageStatusChange evt) {
localDB.getMessage(evt.getID()).ifPresent(message -> {
- message.setStatus(evt.get());
- // Update UI if in current chat and the current user was the sender of the
- // message
- if (currentChat != null && message.getSenderID() == client.getSender().getID()) Platform.runLater(messageList::refresh);
+ message.setStatus(evt.get());
+ // Update UI if in current chat and the current user was the sender of the
+ // message
+ if (currentChat != null && message.getSenderID() == client.getSender().getID()) Platform.runLater(messageList::refresh);
});
}
@@ -257,8 +256,8 @@ public final class ChatScene implements EventListener, Restorable {
localDB.getMessage(evt.getID()).ifPresent(groupMessage -> {
((GroupMessage) groupMessage).getMemberStatuses().replace(evt.getMemberID(), evt.get());
- // Update UI if in current chat
- if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh);
+ // Update UI if in current chat
+ if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh);
});
}
diff --git a/common/src/main/java/envoy/data/Message.java b/common/src/main/java/envoy/data/Message.java
index 8d31bd3..3258e34 100644
--- a/common/src/main/java/envoy/data/Message.java
+++ b/common/src/main/java/envoy/data/Message.java
@@ -3,6 +3,8 @@ package envoy.data;
import java.io.Serializable;
import java.time.Instant;
+import dev.kske.eventbus.IEvent;
+
/**
* Represents a unique message with a unique, numeric ID. Further metadata
* includes the sender and recipient {@link User}s, as well as the creation
@@ -16,7 +18,7 @@ import java.time.Instant;
* @author Leon Hofmeister
* @since Envoy Common v0.2-alpha
*/
-public class Message implements Serializable {
+public class Message implements Serializable, IEvent {
/**
* This enumeration defines all possible statuses a {link Message} can have.