Refactored IsWriting to IsTyping

This commit is contained in:
delvh 2020-07-25 17:12:24 +02:00
parent e382a86623
commit 5a5e6e2086
6 changed files with 27 additions and 36 deletions

View File

@ -34,7 +34,7 @@ public class Chat implements Serializable {
protected int unreadAmount; 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; protected transient long lastWritingEvent;
@ -145,7 +145,7 @@ public class Chat implements Serializable {
public Contact getRecipient() { return recipient; } 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 * sent
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */

View File

@ -155,8 +155,8 @@ public class Client implements Closeable {
// Process group size changes // Process group size changes
receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); }); receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); });
// Process IsWriting events // Process IsTyping events
receiver.registerProcessor(IsWriting.class, eventBus::dispatch); receiver.registerProcessor(IsTyping.class, eventBus::dispatch);
// Send event // Send event
eventBus.register(SendEvent.class, evt -> { eventBus.register(SendEvent.class, evt -> {

View File

@ -445,10 +445,10 @@ public final class ChatScene implements Restorable {
private void checkKeyCombination(KeyEvent e) { private void checkKeyCombination(KeyEvent e) {
// Checks whether the text is too long // Checks whether the text is too long
messageTextUpdated(); messageTextUpdated();
// Sending an IsWriting event if none has been sent for // Sending an IsTyping event if none has been sent for
// IsWriting#millisecondsActive // IsTyping#millisecondsActive
if (client.isOnline() && currentChat.getLastWritingEvent() + IsWriting.millisecondsActive <= System.currentTimeMillis()) { if (client.isOnline() && currentChat.getLastWritingEvent() + IsTyping.millisecondsActive <= System.currentTimeMillis()) {
eventBus.dispatch(new SendEvent(new IsWriting(getChatID(), currentChat.getRecipient().getID(), client.getSender().getName()))); eventBus.dispatch(new SendEvent(new IsTyping(getChatID(), currentChat.getRecipient().getID())));
currentChat.lastWritingEventWasNow(); currentChat.lastWritingEventWasNow();
} }
// Automatic sending of messages via (ctrl +) enter // Automatic sending of messages via (ctrl +) enter

View File

@ -1,21 +1,20 @@
package envoy.event; 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.
* <p> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>IsWriting.java</strong><br> * File: <strong>IsTyping.java</strong><br>
* Created: <strong>24.07.2020</strong><br> * Created: <strong>24.07.2020</strong><br>
* *
* @author Leon Hofmeister * @author Leon Hofmeister
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
public class IsWriting extends Event<Long> { public class IsTyping extends Event<Long> {
private final long destinationID; private final long destinationID;
private final String displayName;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
@ -27,28 +26,20 @@ public class IsWriting extends Event<Long> {
public static final int millisecondsActive = 3500; 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 sourceID the id of the originator
* @param displayName the name of the originator
* @param destinationID the id of the contact the user wrote to * @param destinationID the id of the contact the user wrote to
* @since Envoy Common v0.2-beta * @since Envoy Common v0.2-beta
*/ */
public IsWriting(Long sourceID, long destinationID, String displayName) { public IsTyping(Long sourceID, long destinationID) {
super(sourceID); super(sourceID);
this.destinationID = destinationID; this.destinationID = destinationID;
this.displayName = displayName;
} }
/** /**
* @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 * @since Envoy Common v0.2-beta
*/ */
public long getDestinationID() { return destinationID; } public long getDestinationID() { return destinationID; }
/**
* @return the name of the originator to display
* @since Envoy Common v0.2-beta
*/
public String getDisplayName() { return displayName; }
} }

View File

@ -70,7 +70,7 @@ public class Startup {
new IDGeneratorRequestProcessor(), new IDGeneratorRequestProcessor(),
new UserSearchProcessor(), new UserSearchProcessor(),
new ContactOperationProcessor(), new ContactOperationProcessor(),
new IsWritingProcessor()))); new IsTypingProcessor())));
// Initialize the current message ID // Initialize the current message ID
final PersistenceManager persistenceManager = PersistenceManager.getInstance(); final PersistenceManager persistenceManager = PersistenceManager.getInstance();

View File

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