From 6f8859c3fd9f7c2d24e73c9e6fbdd14364f20a00 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 25 Jul 2020 16:26:13 +0200 Subject: [PATCH 1/3] Added IsWriting event on common, server and partially on client side MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit additionally fixed NullPointerException in ContactSearchScene and typo in Javadoc PS: this is the 1000th commit in Envoy! 🥳 🎉 --- .../src/main/java/envoy/client/data/Chat.java | 36 +++++++++---- .../main/java/envoy/client/net/Client.java | 3 ++ .../envoy/client/ui/controller/ChatScene.java | 21 +++++++- .../ui/controller/ContactSearchScene.java | 6 ++- .../client/ui/controller/LoginScene.java | 6 +-- .../envoy/client/ui/listcell/ChatControl.java | 4 +- .../src/main/java/envoy/event/IsWriting.java | 53 +++++++++++++++++++ .../src/main/java/envoy/server/Startup.java | 3 +- .../server/processors/IsWritingProcessor.java | 37 +++++++++++++ 9 files changed, 151 insertions(+), 18 deletions(-) create mode 100644 common/src/main/java/envoy/event/IsWriting.java create mode 100644 server/src/main/java/envoy/server/processors/IsWritingProcessor.java diff --git a/client/src/main/java/envoy/client/data/Chat.java b/client/src/main/java/envoy/client/data/Chat.java index b1c2beb..d35993a 100644 --- a/client/src/main/java/envoy/client/data/Chat.java +++ b/client/src/main/java/envoy/client/data/Chat.java @@ -9,6 +9,7 @@ import java.util.Objects; import envoy.client.net.WriteProxy; import envoy.data.*; import envoy.data.Message.MessageStatus; +import envoy.event.IsWriting; import envoy.event.MessageStatusChange; /** @@ -31,6 +32,12 @@ public class Chat implements Serializable { protected int unreadAmount; + /** + * Counts the milliseconds until another {@link IsWriting} event will be sent if + * something is typed. + */ + protected transient long lastWritingEvent; + private static final long serialVersionUID = 1L; /** @@ -41,16 +48,14 @@ public class Chat implements Serializable { * @param recipient the user who receives the messages * @since Envoy Client v0.1-alpha */ - public Chat(Contact recipient) { - this.recipient = recipient; - } + public Chat(Contact recipient) { this.recipient = recipient; } @Override public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); } /** * Generates a hash code based on the recipient. - * + * * @since Envoy Client v0.1-beta */ @Override @@ -58,14 +63,14 @@ public class Chat implements Serializable { /** * Tests equality to another object based on the recipient. - * + * * @since Envoy Client v0.1-beta */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Chat)) return false; - Chat other = (Chat) obj; + final Chat other = (Chat) obj; return Objects.equals(recipient, other.recipient); } @@ -101,7 +106,7 @@ public class Chat implements Serializable { /** * Inserts a message at the correct place according to its creation date. - * + * * @param message the message to insert * @since Envoy Client v0.1-beta */ @@ -116,13 +121,13 @@ public class Chat implements Serializable { /** * Increments the amount of unread messages. - * + * * @since Envoy Client v0.1-beta */ public void incrementUnreadAmount() { unreadAmount++; } /** - * @return the amount of unread mesages in this chat + * @return the amount of unread messages in this chat * @since Envoy Client v0.1-beta */ public int getUnreadAmount() { return unreadAmount; } @@ -150,4 +155,17 @@ public class Chat implements Serializable { * @since Envoy Client v0.1-beta */ public boolean isGroupChat() { return recipient instanceof Group; } + + /** + * @return the last known time a {@link IsWriting} event has been sent + * @since Envoy Client v0.2-beta + */ + public long getLastWritingEvent() { return lastWritingEvent; } + + /** + * Sets the {@code lastWritingEvent} to {@code System#currentTimeMillis()}. + * + * @since Envoy Client v0.2-beta + */ + public void lastWritingEventWasNow() { lastWritingEvent = System.currentTimeMillis(); } } diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index a01468f..dbbe5e2 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -155,6 +155,9 @@ public class Client implements Closeable { // Process group size changes receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); }); + // Process IsWriting events + receiver.registerProcessor(IsWriting.class, eventBus::dispatch); + // Send event eventBus.register(SendEvent.class, evt -> { try { 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 a05150c..38c94ff 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -33,6 +33,7 @@ import envoy.client.data.audio.AudioRecorder; import envoy.client.data.commands.SystemCommandBuilder; import envoy.client.data.commands.SystemCommandsMap; import envoy.client.event.MessageCreationEvent; +import envoy.client.event.SendEvent; import envoy.client.net.Client; import envoy.client.net.WriteProxy; import envoy.client.ui.*; @@ -444,10 +445,28 @@ public final class ChatScene implements Restorable { private void checkKeyCombination(KeyEvent e) { // Checks whether the text is too long messageTextUpdated(); + // Sending an IsWriting event if none has been sent for + // IsWriting#millisecondsActive + if (client.isOnline() && currentChat.getLastWritingEvent() + IsWriting.millisecondsActive <= System.currentTimeMillis()) { + eventBus.dispatch(new SendEvent(new IsWriting(getChatID(), currentChat.getRecipient().getID(), client.getSender().getName()))); + currentChat.lastWritingEventWasNow(); + } // Automatic sending of messages via (ctrl +) enter checkPostConditions(e); } + /** + * Returns the id that should be used to send things to the server: + * the id of 'our' {@link User} if the recipient of that object is another User, + * else the id of the {@link Group} 'our' user is sending to. + * + * @return an id that can be sent to the server + * @since Envoy Client v0.2-beta + */ + private long getChatID() { + return currentChat.getRecipient() instanceof User ? client.getSender().getID() : currentChat.getRecipient().getID(); + } + /** * @param e the keys that have been pressed * @since Envoy Client v0.1-beta @@ -515,7 +534,7 @@ public final class ChatScene implements Restorable { updateInfoLabel("You need to go online to send more messages", "infoLabel-error"); return; } - final var text = messageTextArea.getText().strip(); + final var text = messageTextArea.getText().strip(); if (!messageTextAreaCommands.executeIfAnyPresent(text)) try { // Creating the message and its metadata final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()) diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 4583aad..3e6071a 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -60,8 +60,10 @@ public class ContactSearchScene { private final Consumer handler = e -> { final var contact = e.get(); - if (e.getOperationType() == ElementOperation.ADD) Platform - .runLater(() -> { userList.getItems().remove(contact); if (currentlySelectedUser.equals(contact) && alert.isShowing()) alert.close(); }); + if (e.getOperationType() == ElementOperation.ADD) Platform.runLater(() -> { + userList.getItems().remove(contact); + if (currentlySelectedUser != null && currentlySelectedUser.equals(contact) && alert.isShowing()) alert.close(); + }); }; private static final EventBus eventBus = EventBus.getInstance(); diff --git a/client/src/main/java/envoy/client/ui/controller/LoginScene.java b/client/src/main/java/envoy/client/ui/controller/LoginScene.java index 177524b..2b03a5b 100644 --- a/client/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/client/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -138,7 +138,7 @@ public final class LoginScene { localDB.setUser(localDB.getUsers().get(identifier)); localDB.initializeUserStorage(); localDB.loadUserData(); - } catch (Exception e) { + } catch (final Exception e) { // User storage empty, wrong user name etc. -> default lastSync } return localDB.getLastSync(); @@ -161,7 +161,7 @@ public final class LoginScene { try { // Try entering offline mode localDB.loadUsers(); - final User clientUser = (User) localDB.getUsers().get(credentials.getIdentifier()); + final User clientUser = localDB.getUsers().get(credentials.getIdentifier()); if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown"); client.setSender(clientUser); loadChatScene(); @@ -223,7 +223,7 @@ public final class LoginScene { // Initialize status tray icon final var trayIcon = new StatusTrayIcon(sceneContext.getStage()); settings.getItems().get("hideOnClose").setChangeHandler(c -> { - if (((Boolean) c)) trayIcon.show(); + if ((Boolean) c) trayIcon.show(); else trayIcon.hide(); }); } diff --git a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java index c2e942c..9e20eb7 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -31,12 +31,12 @@ public class ChatControl extends HBox { // Unread messages if (chat.getUnreadAmount() != 0) { - Region spacing = new Region(); + final Region spacing = new Region(); setHgrow(spacing, Priority.ALWAYS); getChildren().add(spacing); final var unreadMessagesLabel = new Label(Integer.toString(chat.getUnreadAmount())); unreadMessagesLabel.setMinSize(15, 15); - var vBox2 = new VBox(); + final var vBox2 = new VBox(); vBox2.setAlignment(Pos.CENTER_RIGHT); unreadMessagesLabel.setAlignment(Pos.CENTER); unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount"); diff --git a/common/src/main/java/envoy/event/IsWriting.java b/common/src/main/java/envoy/event/IsWriting.java new file mode 100644 index 0000000..7efe32b --- /dev/null +++ b/common/src/main/java/envoy/event/IsWriting.java @@ -0,0 +1,53 @@ +package envoy.event; + +/** + * This event should be sent when a user wrote anything in a chat. + *

+ * Project: envoy-client
+ * File: IsWriting.java
+ * Created: 24.07.2020
+ * + * @author Leon Hofmeister + * @since Envoy Client v0.2-beta + */ +public class IsWriting extends Event { + + private final long destinationID; + + private final String displayName; + + private static final long serialVersionUID = 1L; + + /** + * The number of milliseconds that this event will be active.
+ * Currently set to 3.5 seconds. + */ + public static final int millisecondsActive = 3500; + + /** + * Creates a new {@code IsWriting} with originator and recipient. + * + * @param sourceID the id of the originator + * @param displayName the name of the originator + * @param destinationID the id of the contact the user wrote to + * @since Envoy Client v0.2-beta + */ + public IsWriting(Long sourceID, long destinationID, String displayName) { + super(sourceID); + this.destinationID = destinationID; + this.displayName = displayName; + } + + /** + * @return the id of the contact in whose chat the user wrote something + * @since Envoy Client v0.2-beta + */ + public long getDestinationID() { return destinationID; } + + /** + * @return the name of the originator to display + * @since Envoy Common v0.2-beta + */ + public String getDisplayName() { return displayName; } + +} diff --git a/server/src/main/java/envoy/server/Startup.java b/server/src/main/java/envoy/server/Startup.java index 489a060..a906d0e 100755 --- a/server/src/main/java/envoy/server/Startup.java +++ b/server/src/main/java/envoy/server/Startup.java @@ -69,7 +69,8 @@ public class Startup { new UserStatusChangeProcessor(), new IDGeneratorRequestProcessor(), new UserSearchProcessor(), - new ContactOperationProcessor()))); + new ContactOperationProcessor(), + new IsWritingProcessor()))); // Initialize the current message ID final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/IsWritingProcessor.java b/server/src/main/java/envoy/server/processors/IsWritingProcessor.java new file mode 100644 index 0000000..aec1c24 --- /dev/null +++ b/server/src/main/java/envoy/server/processors/IsWritingProcessor.java @@ -0,0 +1,37 @@ +package envoy.server.processors; + +import java.io.IOException; + +import envoy.event.IsWriting; +import envoy.server.data.PersistenceManager; +import envoy.server.data.User; +import envoy.server.net.ConnectionManager; +import envoy.server.net.ObjectWriteProxy; + +/** + * This processor handles incoming {@link IsWriting}s. + *

+ * Project: envoy-server-standalone
+ * File: IsWritingProcessor.java
+ * Created: 24.07.2020
+ * + * @author Leon Hofmeister + * @since Envoy Server v0.2-beta + */ +public class IsWritingProcessor implements ObjectProcessor { + + private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); + private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); + + @Override + public Class getInputClass() { return IsWriting.class; } + + @Override + public void process(IsWriting input, long socketID, ObjectWriteProxy writeProxy) throws IOException { + final var contact = persistenceManager.getContactByID(input.get()); + if (contact instanceof User) { + final var destinationID = input.getDestinationID(); + if (connectionManager.isOnline(destinationID)) writeProxy.write(connectionManager.getSocketID(destinationID), input); + } else writeProxy.writeToOnlineContacts(contact.getContacts(), input); + } +} From e382a866233302cef2d714cbcbd1dbbb727416c3 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 25 Jul 2020 16:51:46 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: CyB3RC0nN0R --- .../src/main/java/envoy/client/data/Chat.java | 23 +++++-------------- .../envoy/client/ui/listcell/ChatControl.java | 2 +- .../src/main/java/envoy/event/IsWriting.java | 7 +++--- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/client/src/main/java/envoy/client/data/Chat.java b/client/src/main/java/envoy/client/data/Chat.java index d35993a..fd87050 100644 --- a/client/src/main/java/envoy/client/data/Chat.java +++ b/client/src/main/java/envoy/client/data/Chat.java @@ -7,9 +7,10 @@ import java.util.List; import java.util.Objects; import envoy.client.net.WriteProxy; -import envoy.data.*; +import envoy.data.Contact; +import envoy.data.Message; import envoy.data.Message.MessageStatus; -import envoy.event.IsWriting; +import envoy.data.User; import envoy.event.MessageStatusChange; /** @@ -33,8 +34,7 @@ public class Chat implements Serializable { protected int unreadAmount; /** - * Counts the milliseconds until another {@link IsWriting} event will be sent if - * something is typed. + * Stores the last time an {@link envoy.event.IsWriting} event has been sent. */ protected transient long lastWritingEvent; @@ -145,19 +145,8 @@ public class Chat implements Serializable { public Contact getRecipient() { return recipient; } /** - * @return whether this {@link Chat} points at a {@link User} - * @since Envoy Client v0.1-beta - */ - public boolean isUserChat() { return recipient instanceof User; } - - /** - * @return whether this {@link Chat} points at a {@link Group} - * @since Envoy Client v0.1-beta - */ - public boolean isGroupChat() { return recipient instanceof Group; } - - /** - * @return the last known time a {@link IsWriting} event has been sent + * @return the last known time a {@link envoy.event.IsWriting} event has been + * sent * @since Envoy Client v0.2-beta */ public long getLastWritingEvent() { return lastWritingEvent; } diff --git a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java index 9e20eb7..e19cd54 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -31,7 +31,7 @@ public class ChatControl extends HBox { // Unread messages if (chat.getUnreadAmount() != 0) { - final Region spacing = new Region(); + final var spacing = new Region(); setHgrow(spacing, Priority.ALWAYS); getChildren().add(spacing); final var unreadMessagesLabel = new Label(Integer.toString(chat.getUnreadAmount())); diff --git a/common/src/main/java/envoy/event/IsWriting.java b/common/src/main/java/envoy/event/IsWriting.java index 7efe32b..88b62d2 100644 --- a/common/src/main/java/envoy/event/IsWriting.java +++ b/common/src/main/java/envoy/event/IsWriting.java @@ -21,6 +21,8 @@ public class IsWriting extends Event { /** * The number of milliseconds that this event will be active.
* Currently set to 3.5 seconds. + * + * @since Envoy Common v0.2-beta */ public static final int millisecondsActive = 3500; @@ -30,7 +32,7 @@ public class IsWriting extends Event { * @param sourceID the id of the originator * @param displayName the name of the originator * @param destinationID the id of the contact the user wrote to - * @since Envoy Client v0.2-beta + * @since Envoy Common v0.2-beta */ public IsWriting(Long sourceID, long destinationID, String displayName) { super(sourceID); @@ -40,7 +42,7 @@ public class IsWriting extends Event { /** * @return the id of the contact in whose chat the user wrote something - * @since Envoy Client v0.2-beta + * @since Envoy Common v0.2-beta */ public long getDestinationID() { return destinationID; } @@ -49,5 +51,4 @@ public class IsWriting extends Event { * @since Envoy Common v0.2-beta */ public String getDisplayName() { return displayName; } - } From 5a5e6e208627716be57bb40e6b4d8c32e08a8a0e Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 25 Jul 2020 17:12:24 +0200 Subject: [PATCH 3/3] Refactored IsWriting to IsTyping --- .../src/main/java/envoy/client/data/Chat.java | 4 +-- .../main/java/envoy/client/net/Client.java | 4 +-- .../envoy/client/ui/controller/ChatScene.java | 8 +++--- .../event/{IsWriting.java => IsTyping.java} | 25 ++++++------------- .../src/main/java/envoy/server/Startup.java | 2 +- ...gProcessor.java => IsTypingProcessor.java} | 20 +++++++-------- 6 files changed, 27 insertions(+), 36 deletions(-) rename common/src/main/java/envoy/event/{IsWriting.java => IsTyping.java} (53%) rename server/src/main/java/envoy/server/processors/{IsWritingProcessor.java => IsTypingProcessor.java} (58%) diff --git a/client/src/main/java/envoy/client/data/Chat.java b/client/src/main/java/envoy/client/data/Chat.java index fd87050..81d6d97 100644 --- a/client/src/main/java/envoy/client/data/Chat.java +++ b/client/src/main/java/envoy/client/data/Chat.java @@ -34,7 +34,7 @@ public class Chat implements Serializable { protected int unreadAmount; /** - * Stores the last time an {@link envoy.event.IsWriting} event has been sent. + * Stores the last time an {@link envoy.event.IsTyping} event has been sent. */ protected transient long lastWritingEvent; @@ -145,7 +145,7 @@ public class Chat implements Serializable { public Contact getRecipient() { return recipient; } /** - * @return the last known time a {@link envoy.event.IsWriting} event has been + * @return the last known time a {@link envoy.event.IsTyping} event has been * sent * @since Envoy Client v0.2-beta */ diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index dbbe5e2..b642141 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -155,8 +155,8 @@ public class Client implements Closeable { // Process group size changes receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); }); - // Process IsWriting events - receiver.registerProcessor(IsWriting.class, eventBus::dispatch); + // Process IsTyping events + receiver.registerProcessor(IsTyping.class, eventBus::dispatch); // Send event eventBus.register(SendEvent.class, evt -> { 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 38c94ff..f9ba2d7 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -445,10 +445,10 @@ public final class ChatScene implements Restorable { private void checkKeyCombination(KeyEvent e) { // Checks whether the text is too long messageTextUpdated(); - // Sending an IsWriting event if none has been sent for - // IsWriting#millisecondsActive - if (client.isOnline() && currentChat.getLastWritingEvent() + IsWriting.millisecondsActive <= System.currentTimeMillis()) { - eventBus.dispatch(new SendEvent(new IsWriting(getChatID(), currentChat.getRecipient().getID(), client.getSender().getName()))); + // Sending an IsTyping event if none has been sent for + // IsTyping#millisecondsActive + if (client.isOnline() && currentChat.getLastWritingEvent() + IsTyping.millisecondsActive <= System.currentTimeMillis()) { + eventBus.dispatch(new SendEvent(new IsTyping(getChatID(), currentChat.getRecipient().getID()))); currentChat.lastWritingEventWasNow(); } // Automatic sending of messages via (ctrl +) enter diff --git a/common/src/main/java/envoy/event/IsWriting.java b/common/src/main/java/envoy/event/IsTyping.java similarity index 53% rename from common/src/main/java/envoy/event/IsWriting.java rename to common/src/main/java/envoy/event/IsTyping.java index 88b62d2..f720459 100644 --- a/common/src/main/java/envoy/event/IsWriting.java +++ b/common/src/main/java/envoy/event/IsTyping.java @@ -1,21 +1,20 @@ package envoy.event; /** - * This event should be sent when a user wrote anything in a chat. + * This event should be sent when a user is currently typing something in a + * chat. *

* Project: envoy-client
- * File: IsWriting.java
+ * File: IsTyping.java
* Created: 24.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class IsWriting extends Event { +public class IsTyping extends Event { private final long destinationID; - private final String displayName; - private static final long serialVersionUID = 1L; /** @@ -27,28 +26,20 @@ public class IsWriting extends Event { public static final int millisecondsActive = 3500; /** - * Creates a new {@code IsWriting} with originator and recipient. + * Creates a new {@code IsTyping} event with originator and recipient. * * @param sourceID the id of the originator - * @param displayName the name of the originator * @param destinationID the id of the contact the user wrote to * @since Envoy Common v0.2-beta */ - public IsWriting(Long sourceID, long destinationID, String displayName) { + public IsTyping(Long sourceID, long destinationID) { super(sourceID); - this.destinationID = destinationID; - this.displayName = displayName; + this.destinationID = destinationID; } /** - * @return the id of the contact in whose chat the user wrote something + * @return the id of the contact in whose chat the user typed something * @since Envoy Common v0.2-beta */ public long getDestinationID() { return destinationID; } - - /** - * @return the name of the originator to display - * @since Envoy Common v0.2-beta - */ - public String getDisplayName() { return displayName; } } diff --git a/server/src/main/java/envoy/server/Startup.java b/server/src/main/java/envoy/server/Startup.java index a906d0e..ac24c40 100755 --- a/server/src/main/java/envoy/server/Startup.java +++ b/server/src/main/java/envoy/server/Startup.java @@ -70,7 +70,7 @@ public class Startup { new IDGeneratorRequestProcessor(), new UserSearchProcessor(), new ContactOperationProcessor(), - new IsWritingProcessor()))); + new IsTypingProcessor()))); // Initialize the current message ID final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/IsWritingProcessor.java b/server/src/main/java/envoy/server/processors/IsTypingProcessor.java similarity index 58% rename from server/src/main/java/envoy/server/processors/IsWritingProcessor.java rename to server/src/main/java/envoy/server/processors/IsTypingProcessor.java index aec1c24..bea5f97 100644 --- a/server/src/main/java/envoy/server/processors/IsWritingProcessor.java +++ b/server/src/main/java/envoy/server/processors/IsTypingProcessor.java @@ -2,36 +2,36 @@ package envoy.server.processors; import java.io.IOException; -import envoy.event.IsWriting; +import envoy.event.IsTyping; import envoy.server.data.PersistenceManager; import envoy.server.data.User; import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** - * This processor handles incoming {@link IsWriting}s. + * This processor handles incoming {@link IsTyping} events. *

* Project: envoy-server-standalone
- * File: IsWritingProcessor.java
+ * File: IsTypingProcessor.java
* Created: 24.07.2020
* * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ -public class IsWritingProcessor implements ObjectProcessor { +public class IsTypingProcessor implements ObjectProcessor { private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); @Override - public Class getInputClass() { return IsWriting.class; } + public Class getInputClass() { return IsTyping.class; } @Override - public void process(IsWriting input, long socketID, ObjectWriteProxy writeProxy) throws IOException { - final var contact = persistenceManager.getContactByID(input.get()); + public void process(IsTyping event, long socketID, ObjectWriteProxy writeProxy) throws IOException { + final var contact = persistenceManager.getContactByID(event.get()); if (contact instanceof User) { - final var destinationID = input.getDestinationID(); - if (connectionManager.isOnline(destinationID)) writeProxy.write(connectionManager.getSocketID(destinationID), input); - } else writeProxy.writeToOnlineContacts(contact.getContacts(), input); + final var destinationID = event.getDestinationID(); + if (connectionManager.isOnline(destinationID)) writeProxy.write(connectionManager.getSocketID(destinationID), event); + } else writeProxy.writeToOnlineContacts(contact.getContacts(), event); } }