Removed MessageCreationEvent and MessageModificationEvent
This commit is contained in:
parent
8829f267ec
commit
c21da25789
@ -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.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import envoy.client.event.MessageCreationEvent;
|
|
||||||
import envoy.data.GroupMessage;
|
import envoy.data.GroupMessage;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.util.EnvoyLog;
|
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());
|
logger.warning("The groupMessage has the unexpected status " + groupMessage.getStatus());
|
||||||
|
|
||||||
// Dispatch event
|
// 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 java.util.function.Consumer;
|
||||||
|
|
||||||
import envoy.client.event.MessageCreationEvent;
|
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ public final class ReceivedMessageProcessor implements Consumer<Message> {
|
|||||||
// Update status to RECEIVED
|
// Update status to RECEIVED
|
||||||
if (message.getStatus() == MessageStatus.SENT) message.nextStatus();
|
if (message.getStatus() == MessageStatus.SENT) message.nextStatus();
|
||||||
|
|
||||||
// Dispatch event
|
// Dispatch message
|
||||||
EventBus.getInstance().dispatch(new MessageCreationEvent(message));
|
EventBus.getInstance().dispatch(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import java.awt.TrayIcon.MessageType;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import envoy.client.event.MessageCreationEvent;
|
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
|
|
||||||
import dev.kske.eventbus.*;
|
import dev.kske.eventbus.*;
|
||||||
@ -91,9 +90,10 @@ public final class StatusTrayIcon implements EventListener {
|
|||||||
public void hide() { SystemTray.getSystemTray().remove(trayIcon); }
|
public void hide() { SystemTray.getSystemTray().remove(trayIcon); }
|
||||||
|
|
||||||
@Event
|
@Event
|
||||||
private void onMessageCreation(MessageCreationEvent evt) {
|
private void onMessage(Message evt) {
|
||||||
if (displayMessages) trayIcon
|
if (displayMessages) trayIcon.displayMessage(
|
||||||
.displayMessage(evt.get().hasAttachment() ? "New " + evt.get().getAttachment().getType().toString().toLowerCase() + " message received"
|
evt.hasAttachment() ? "New " + evt.getAttachment().getType().toString().toLowerCase() + " message received" : "New message received",
|
||||||
: "New message received", evt.get().getText(), MessageType.INFO);
|
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()); }
|
private void onBackEvent() { tabPane.getSelectionModel().select(Tabs.CONTACT_LIST.ordinal()); }
|
||||||
|
|
||||||
@Event
|
@Event
|
||||||
private void onMessageCreation(MessageCreationEvent evt) {
|
private void onMessage(Message message) {
|
||||||
final var message = evt.get();
|
|
||||||
|
|
||||||
// The sender of the message is the recipient of the chat
|
// The sender of the message is the recipient of the chat
|
||||||
// Exceptions: this user is the sender (sync) or group message (group is
|
// Exceptions: this user is the sender (sync) or group message (group is
|
||||||
@ -245,10 +244,10 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
@Event
|
@Event
|
||||||
private void onMessageStatusChange(MessageStatusChange evt) {
|
private void onMessageStatusChange(MessageStatusChange evt) {
|
||||||
localDB.getMessage(evt.getID()).ifPresent(message -> {
|
localDB.getMessage(evt.getID()).ifPresent(message -> {
|
||||||
message.setStatus(evt.get());
|
message.setStatus(evt.get());
|
||||||
// Update UI if in current chat and the current user was the sender of the
|
// Update UI if in current chat and the current user was the sender of the
|
||||||
// message
|
// message
|
||||||
if (currentChat != null && message.getSenderID() == client.getSender().getID()) Platform.runLater(messageList::refresh);
|
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 -> {
|
localDB.getMessage(evt.getID()).ifPresent(groupMessage -> {
|
||||||
((GroupMessage) groupMessage).getMemberStatuses().replace(evt.getMemberID(), evt.get());
|
((GroupMessage) groupMessage).getMemberStatuses().replace(evt.getMemberID(), evt.get());
|
||||||
|
|
||||||
// Update UI if in current chat
|
// Update UI if in current chat
|
||||||
if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh);
|
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.io.Serializable;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
|
import dev.kske.eventbus.IEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a unique message with a unique, numeric ID. Further metadata
|
* Represents a unique message with a unique, numeric ID. Further metadata
|
||||||
* includes the sender and recipient {@link User}s, as well as the creation
|
* includes the sender and recipient {@link User}s, as well as the creation
|
||||||
@ -16,7 +18,7 @@ import java.time.Instant;
|
|||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Common v0.2-alpha
|
* @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.
|
* This enumeration defines all possible statuses a {link Message} can have.
|
||||||
|
Reference in New Issue
Block a user