package envoy.data;
import java.io.Serializable;
import java.time.Instant;
/**
* Represents a unique message with a unique, numeric ID. Further metadata
* includes the sender and recipient {@link User}s, as well as the creation
* date and the current {@link MessageStatus}.
*
* Project: envoy-common
* File: Message.java
* Created: 28.12.2019
*
* @author Kai S. K. Engelbart
* @author Leon Hofmeister
* @since Envoy Common v0.2-alpha
*/
public class Message implements Serializable {
/**
* This enumeration defines all possible statuses a {link Message} can have.
*
* @since Envoy Common v0.2-alpha
*/
public enum MessageStatus {
/**
* is selected, if a message was sent but not received by the server yet.
*/
WAITING,
/**
* is selected, if a sent message was received by the server.
*/
SENT,
/**
* is selected, if a message was delivered from the server to the recipient, but
* has not been read yet.
*/
RECEIVED,
/**
* is selected, if a recipient opened the corresponding chat of said message.
*/
READ
}
private final long id, senderID, recipientID;
private final boolean forwarded;
private final Instant creationDate;
private final String text;
private final Attachment attachment;
private Instant receivedDate, readDate;
private MessageStatus status;
private static final long serialVersionUID = 2L;
/**
* Initializes a {@link Message} with values for all of its properties. The use
* of this constructor is only intended for the {@link MessageBuilder} class, as
* this class provides {@code null} checks and default values for all
* properties.
*
* @param id unique ID
* @param senderID the ID of the user who sends the message
* @param recipientID the ID of the user who receives the message
* @param creationDate the creation date of the message
* @param receivedDate the received date of the message
* @param readDate the read date of the message
* @param text the text content of the message
* @param attachment the attachment of the message, if present
* @param status the current {@link MessageStatus} of the message
* @param forwarded whether this message was forwarded
* @since Envoy Common v0.2-beta
*/
Message(long id, long senderID, long recipientID, Instant creationDate, Instant receivedDate, Instant readDate, String text,
Attachment attachment, MessageStatus status, boolean forwarded) {
this.id = id;
this.senderID = senderID;
this.recipientID = recipientID;
this.creationDate = creationDate;
this.receivedDate = receivedDate;
this.readDate = readDate;
this.text = text;
this.attachment = attachment;
this.status = status;
this.forwarded = forwarded;
}
/**
* Changes the current {@link MessageStatus} to the next logical status.
*
* The underlying order is as follows:
*