diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index 4cf4af2..8007796 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -78,4 +78,4 @@ public class LoginCredentials implements Serializable { * @since Envoy Common v0.2-alpha */ public boolean isRegistration() { return registration; } -} \ No newline at end of file +} diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 85702ca..7a8adc4 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -49,6 +49,7 @@ public class Message implements Serializable { } private final long id, senderId, recipientId; + private final boolean forwarded; private final Date creationDate; private final String text; private final MessageAttachment attachment; @@ -71,9 +72,11 @@ public class Message implements Serializable { * @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, Date creationDate, String text, MessageAttachment attachment, MessageStatus status) { + Message(long id, long senderId, long recipientId, Date creationDate, String text, MessageAttachment attachment, MessageStatus status, + boolean forwarded) { this.id = id; this.senderId = senderId; this.recipientId = recipientId; @@ -81,6 +84,7 @@ public class Message implements Serializable { this.text = text; this.attachment = attachment; this.status = status; + this.forwarded = forwarded; } /** @@ -188,4 +192,10 @@ public class Message implements Serializable { if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time"); this.status = status; } -} \ No newline at end of file + + /** + * @return whether this message was forwarded + * @since Envoy common v0.1-beta + */ + public boolean isForwarded() { return forwarded; } +} diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 5166352..9129357 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -25,27 +25,26 @@ public class MessageBuilder { private String text; private MessageAttachment attachment; private Message.MessageStatus status; + private boolean forwarded; /** * Creates an instance of {@link MessageBuilder} with all mandatory values * without defaults for the {@link Message} class. * * @param senderId the ID of the user who sends the {@link Message} - * @param recipientId the ID of the user who received the {@link Message} + * @param recipientId the ID of the user who receives the {@link Message} * @param idGenerator the ID generator used to generate a unique {@link Message} * id * @since Envoy Common v0.2-alpha */ - public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) { - this(senderId, recipientId, idGenerator.next()); - } + public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) { this(senderId, recipientId, idGenerator.next()); } /** * Creates an instance of {@link MessageBuilder} with all mandatory values * without defaults for the {@link Message} class. * * @param senderId the ID of the user who sends the {@link Message} - * @param recipientId the ID of the user who received the {@link Message} + * @param recipientId the ID of the user who receives the {@link Message} * @param messageId the ID of the {@link Message} * @since Envoy Common v0.2-alpha */ @@ -55,6 +54,26 @@ public class MessageBuilder { id = messageId; } + /** + * This constructor transforms a given {@link Message} into a new message for a + * new receiver. + * This makes it especially useful in the case of forwarding messages. + * + * @param msg the message to copy + * @param recipientId the ID of the user who receives the {@link Message} + * @param idGenerator the ID generator used to generate a unique {@link Message} + * id + * @since Envoy v0.1-beta + */ + public MessageBuilder(Message msg, long recipientId, IdGenerator idGenerator) { + this(msg.getRecipientId(), recipientId, idGenerator.next()); + this.attachment = msg.getAttachment(); + this.creationDate = new Date(); + this.forwarded = true; + this.text = msg.getText(); + this.status = MessageStatus.WAITING; + } + /** * Creates an instance of {@link Message} with the previously supplied values. * If a mandatory value is not set, a default value will be used instead:
@@ -83,7 +102,7 @@ public class MessageBuilder { if (text == null) text = ""; if (status == null) status = MessageStatus.WAITING; - return new Message(id, senderId, recipientId, creationDate, text, attachment, status); + return new Message(id, senderId, recipientId, creationDate, text, attachment, status, forwarded); } /** @@ -126,4 +145,14 @@ public class MessageBuilder { this.status = status; return this; } -} \ No newline at end of file + + /** + * @param forwarded sets whether this message is a forwarded message or not + * @return this {@link MessageBuilder} + * @since Envoy Common v0.1-beta + */ + public MessageBuilder setForwarded(boolean forwarded) { + this.forwarded = forwarded; + return this; + } +} diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index bc9cf0f..25be9e8 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -75,7 +75,7 @@ public class User implements Serializable { */ public User(long id, String name, UserStatus status) { this(id, name); - this.status = status; + this.status = status; } @Override @@ -104,4 +104,4 @@ public class User implements Serializable { * @since Envoy Common v0.2-alpha */ public void setStatus(UserStatus status) { this.status = status; } -} \ No newline at end of file +} diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java index 3007bfe..68bd098 100644 --- a/src/main/java/envoy/util/SerializationUtils.java +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -147,4 +147,4 @@ public class SerializationUtils { out.write(objLen); out.write(objBytes); } -} \ No newline at end of file +}