From ef1d9785e08bab54d654eee29faef1def9ca6c0a Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 2 Jul 2020 14:47:04 +0200 Subject: [PATCH] Add received and read date to MessageBuilder This simplifies some calls on the server --- src/main/java/envoy/data/GroupMessage.java | 6 ++-- src/main/java/envoy/data/Message.java | 8 +++-- src/main/java/envoy/data/MessageBuilder.java | 31 ++++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/java/envoy/data/GroupMessage.java b/src/main/java/envoy/data/GroupMessage.java index cb79a12..7fb0d4a 100644 --- a/src/main/java/envoy/data/GroupMessage.java +++ b/src/main/java/envoy/data/GroupMessage.java @@ -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 memberStatuses) { - super(id, senderID, groupID, creationDate, text, attachment, status, forwarded); + super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status, forwarded); this.memberStatuses = memberStatuses; } diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index ba0a756..040ad59 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -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; diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 8a6164d..917adc4 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -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 { * * * - * + * * * * @@ -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 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}
{@code date}{@code LocalDateTime.now()}{@code LocalDateTime.now()} and {@code null} for {@code receivedDate} and + * {@code readDate}
{@code text}