Added support for forwarding messages (#17)
* Added message forwarding capability * added newline at EOF for any file not having one at its end
This commit is contained in:
parent
ae7384c31a
commit
3d7199f146
@ -78,4 +78,4 @@ public class LoginCredentials implements Serializable {
|
|||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public boolean isRegistration() { return registration; }
|
public boolean isRegistration() { return registration; }
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ public class Message implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final long id, senderId, recipientId;
|
private final long id, senderId, recipientId;
|
||||||
|
private final boolean forwarded;
|
||||||
private final Date creationDate;
|
private final Date creationDate;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final MessageAttachment<?> attachment;
|
private final MessageAttachment<?> attachment;
|
||||||
@ -71,9 +72,11 @@ public class Message implements Serializable {
|
|||||||
* @param text the text content of the message
|
* @param text the text content of the message
|
||||||
* @param attachment the attachment of the message, if present
|
* @param attachment the attachment of the message, if present
|
||||||
* @param status the current {@link MessageStatus} of the message
|
* @param status the current {@link MessageStatus} of the message
|
||||||
|
* @param forwarded whether this message was forwarded
|
||||||
* @since Envoy Common v0.2-alpha
|
* @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.id = id;
|
||||||
this.senderId = senderId;
|
this.senderId = senderId;
|
||||||
this.recipientId = recipientId;
|
this.recipientId = recipientId;
|
||||||
@ -81,6 +84,7 @@ public class Message implements Serializable {
|
|||||||
this.text = text;
|
this.text = text;
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
this.status = status;
|
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");
|
if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time");
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @return whether this message was forwarded
|
||||||
|
* @since Envoy common v0.1-beta
|
||||||
|
*/
|
||||||
|
public boolean isForwarded() { return forwarded; }
|
||||||
|
}
|
||||||
|
@ -25,27 +25,26 @@ public class MessageBuilder {
|
|||||||
private String text;
|
private String text;
|
||||||
private MessageAttachment<?> attachment;
|
private MessageAttachment<?> attachment;
|
||||||
private Message.MessageStatus status;
|
private Message.MessageStatus status;
|
||||||
|
private boolean forwarded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of {@link MessageBuilder} with all mandatory values
|
* Creates an instance of {@link MessageBuilder} with all mandatory values
|
||||||
* without defaults for the {@link Message} class.
|
* without defaults for the {@link Message} class.
|
||||||
*
|
*
|
||||||
* @param senderId the ID of the user who sends the {@link Message}
|
* @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}
|
* @param idGenerator the ID generator used to generate a unique {@link Message}
|
||||||
* id
|
* id
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) {
|
public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) { this(senderId, recipientId, idGenerator.next()); }
|
||||||
this(senderId, recipientId, idGenerator.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of {@link MessageBuilder} with all mandatory values
|
* Creates an instance of {@link MessageBuilder} with all mandatory values
|
||||||
* without defaults for the {@link Message} class.
|
* without defaults for the {@link Message} class.
|
||||||
*
|
*
|
||||||
* @param senderId the ID of the user who sends the {@link Message}
|
* @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}
|
* @param messageId the ID of the {@link Message}
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
@ -55,6 +54,26 @@ public class MessageBuilder {
|
|||||||
id = messageId;
|
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.
|
* 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:<br>
|
* If a mandatory value is not set, a default value will be used instead:<br>
|
||||||
@ -83,7 +102,7 @@ public class MessageBuilder {
|
|||||||
if (text == null) text = "";
|
if (text == null) text = "";
|
||||||
if (status == null) status = MessageStatus.WAITING;
|
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;
|
this.status = status;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class User implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public User(long id, String name, UserStatus status) {
|
public User(long id, String name, UserStatus status) {
|
||||||
this(id, name);
|
this(id, name);
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,4 +104,4 @@ public class User implements Serializable {
|
|||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public void setStatus(UserStatus status) { this.status = status; }
|
public void setStatus(UserStatus status) { this.status = status; }
|
||||||
}
|
}
|
||||||
|
@ -147,4 +147,4 @@ public class SerializationUtils {
|
|||||||
out.write(objLen);
|
out.write(objLen);
|
||||||
out.write(objBytes);
|
out.write(objBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user