From 57599f5ea018da976fe37050d172005f373051c1 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 25 Jul 2020 17:12:24 +0200 Subject: [PATCH] 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); } }