Add received and read date to MessageBuilder

This simplifies some calls on the server
This commit is contained in:
Kai S. K. Engelbart 2020-07-02 14:47:04 +02:00
parent 0f1bce87e0
commit ef1d9785e0
3 changed files with 36 additions and 9 deletions

View File

@ -29,6 +29,8 @@ public final class GroupMessage extends Message {
* @param senderID the ID of the user who sends the message
* @param groupID the ID of the group which 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 Message.MessageStatus} of the
@ -38,9 +40,9 @@ public final class GroupMessage extends Message {
* {@link GroupMessage}
* @since Envoy Common v0.1-beta
*/
GroupMessage(long id, long senderID, long groupID, LocalDateTime creationDate, String text,
GroupMessage(long id, long senderID, long groupID, LocalDateTime creationDate, LocalDateTime receivedDate, LocalDateTime readDate, String text,
Attachment attachment, MessageStatus status, boolean forwarded, Map<Long, MessageStatus> memberStatuses) {
super(id, senderID, groupID, creationDate, text, attachment, status, forwarded);
super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
this.memberStatuses = memberStatuses;
}

View File

@ -69,18 +69,22 @@ public class Message implements Serializable {
* @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-alpha
*/
Message(long id, long senderID, long recipientID, LocalDateTime creationDate, String text, Attachment attachment, MessageStatus status,
boolean forwarded) {
Message(long id, long senderID, long recipientID, LocalDateTime creationDate, LocalDateTime receivedDate, LocalDateTime 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;

View File

@ -23,7 +23,7 @@ public class MessageBuilder {
// Properties with default values
private long id;
private LocalDateTime creationDate;
private LocalDateTime creationDate, receivedDate, readDate;
private String text;
private Attachment attachment;
private Message.MessageStatus status;
@ -83,7 +83,8 @@ public class MessageBuilder {
* <table border="1">
* <tr>
* <td>{@code date}</td>
* <td>{@code LocalDateTime.now()}</td>
* <td>{@code LocalDateTime.now()} and {@code null} for {@code receivedDate} and
* {@code readDate}</td>
* <tr>
* <tr>
* <td>{@code text}</td>
@ -100,7 +101,7 @@ public class MessageBuilder {
*/
public Message build() {
supplyDefaults();
return new Message(id, senderID, recipientID, creationDate, text, attachment, status, forwarded);
return new Message(id, senderID, recipientID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
}
/**
@ -157,7 +158,7 @@ public class MessageBuilder {
public GroupMessage buildGroupMessage(Group group, Map<Long, MessageStatus> memberStatuses) {
if (group == null || memberStatuses == null) throw new NullPointerException();
supplyDefaults();
return new GroupMessage(id, senderID, recipientID, creationDate, text, attachment, status, forwarded, memberStatuses);
return new GroupMessage(id, senderID, recipientID, creationDate, receivedDate, readDate, text, attachment, status, forwarded, memberStatuses);
}
private void supplyDefaults() {
@ -171,11 +172,31 @@ public class MessageBuilder {
* @return this {@link MessageBuilder}
* @since Envoy Common v0.2-alpha
*/
public MessageBuilder setDate(LocalDateTime creationDate) {
public MessageBuilder setCreationDate(LocalDateTime creationDate) {
this.creationDate = creationDate;
return this;
}
/**
* @param receivedDate the received date of the {@link Message} to create
* @return this {@link MessageBuilder}
* @since Envoy Common v0.1-beta
*/
public MessageBuilder setReceivedDate(LocalDateTime receivedDate) {
this.receivedDate = receivedDate;
return this;
}
/**
* @param readDate the read date of the {@link Message} to create
* @return this {@link MessageBuilder}
* @since Envoy Common v0.1-beta
*/
public MessageBuilder setReadDate(LocalDateTime readDate) {
this.readDate = readDate;
return this;
}
/**
* @param text the text of the {@link Message} to create
* @return this {@link MessageBuilder}