Added IsWriting event on common, server and partially on client side

additionally fixed NullPointerException in ContactSearchScene and typo
in Javadoc

PS: this is the 1000th commit in Envoy! 🥳 🎉
This commit is contained in:
delvh
2020-07-25 16:26:13 +02:00
parent 72d1e074f4
commit 6f8859c3fd
9 changed files with 151 additions and 18 deletions

View File

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