Removed MessageCreationEvent and MessageModificationEvent
Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/25 Reviewed-by: kske <kai@kske.dev>
This commit is contained in:
commit
4ba85f68ef
@ -1,22 +0,0 @@
|
||||
package envoy.client.event;
|
||||
|
||||
import envoy.data.Message;
|
||||
import envoy.event.Event;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>MessageCreationEvent.java</strong><br>
|
||||
* Created: <strong>4 Dec 2019</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Client v0.2-alpha
|
||||
*/
|
||||
public final class MessageCreationEvent extends Event<Message> {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* @param message the {@link Message} that has been created
|
||||
*/
|
||||
public MessageCreationEvent(Message message) { super(message); }
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package envoy.client.event;
|
||||
|
||||
import envoy.data.Message;
|
||||
import envoy.event.Event;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>MessageModificationEvent.java</strong><br>
|
||||
* Created: <strong>4 Dec 2019</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Client v0.2-alpha
|
||||
*/
|
||||
public final class MessageModificationEvent extends Event<Message> {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* @param message the {@link Message} that has been modified
|
||||
*/
|
||||
public MessageModificationEvent(Message message) { super(message); }
|
||||
}
|
@ -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<GroupMessag
|
||||
logger.warning("The groupMessage has the unexpected status " + groupMessage.getStatus());
|
||||
|
||||
// Dispatch event
|
||||
EventBus.getInstance().dispatch(new MessageCreationEvent(groupMessage));
|
||||
EventBus.getInstance().dispatch(groupMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package envoy.client.net;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import envoy.client.event.MessageCreationEvent;
|
||||
import envoy.data.Message;
|
||||
import envoy.data.Message.MessageStatus;
|
||||
|
||||
@ -23,7 +22,7 @@ public final class ReceivedMessageProcessor implements Consumer<Message> {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user