Refactored IsWriting to IsTyping

This commit is contained in:
delvh 2020-07-25 17:12:24 +02:00
parent 53901d5109
commit 57599f5ea0
No known key found for this signature in database
GPG Key ID: 42B77E634CE94D82
6 changed files with 27 additions and 36 deletions

View File

@ -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
*/

View File

@ -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 -> {

View File

@ -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

View File

@ -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.
* <p>
* 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>
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public class IsWriting extends Event<Long> {
public class IsTyping extends Event<Long> {
private final long destinationID;
private final String displayName;
private static final long serialVersionUID = 1L;
/**
@ -27,28 +26,20 @@ public class IsWriting extends Event<Long> {
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; }
}

View File

@ -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();

View File

@ -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.
* <p>
* 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>
*
* @author Leon Hofmeister
* @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 PersistenceManager persistenceManager = PersistenceManager.getInstance();
@Override
public Class<IsWriting> getInputClass() { return IsWriting.class; }
public Class<IsTyping> 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);
}
}