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

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