Added ability to save attachments
This commit is contained in:
		@@ -47,7 +47,7 @@ public class Message {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Named query retrieving pending messages for a user (parameter {@code :user})
 | 
			
		||||
	 * which was last seen after a specific date (parameter {@code :lastSeen}).
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static final String getPending = "Message.getPending";
 | 
			
		||||
@@ -76,6 +76,7 @@ public class Message {
 | 
			
		||||
	protected envoy.data.Message.MessageStatus	status;
 | 
			
		||||
	protected AttachmentType					attachmentType;
 | 
			
		||||
	protected byte[]							attachment;
 | 
			
		||||
	protected String							attachmentName;
 | 
			
		||||
	protected boolean							forwarded;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -93,7 +94,7 @@ public class Message {
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public Message(envoy.data.Message message) {
 | 
			
		||||
		PersistenceManager persistenceManager = PersistenceManager.getInstance();
 | 
			
		||||
		final var persistenceManager = PersistenceManager.getInstance();
 | 
			
		||||
		id				= message.getID();
 | 
			
		||||
		status			= message.getStatus();
 | 
			
		||||
		text			= message.getText();
 | 
			
		||||
@@ -104,8 +105,10 @@ public class Message {
 | 
			
		||||
		recipient		= persistenceManager.getContactByID(message.getRecipientID());
 | 
			
		||||
		forwarded		= message.isForwarded();
 | 
			
		||||
		if (message.hasAttachment()) {
 | 
			
		||||
			attachment		= message.getAttachment().getData();
 | 
			
		||||
			attachmentType	= message.getAttachment().getType();
 | 
			
		||||
			final var messageAttachment = message.getAttachment();
 | 
			
		||||
			attachment		= messageAttachment.getData();
 | 
			
		||||
			attachmentName	= messageAttachment.getName();
 | 
			
		||||
			attachmentType	= messageAttachment.getType();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -123,20 +126,20 @@ public class Message {
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	MessageBuilder prepareBuilder() {
 | 
			
		||||
		var builder = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(text)
 | 
			
		||||
		final var builder = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(text)
 | 
			
		||||
			.setCreationDate(creationDate)
 | 
			
		||||
			.setReceivedDate(receivedDate)
 | 
			
		||||
			.setReadDate(readDate)
 | 
			
		||||
			.setStatus(status)
 | 
			
		||||
			.setForwarded(forwarded);
 | 
			
		||||
		if (attachment != null) builder.setAttachment(new Attachment(attachment, attachmentType));
 | 
			
		||||
		if (attachment != null) builder.setAttachment(new Attachment(attachment, attachmentName, attachmentType));
 | 
			
		||||
		return builder;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sets the message status to {@link MessageStatus#RECEIVED} and sets the
 | 
			
		||||
	 * current time stamp as the received date.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void received() {
 | 
			
		||||
@@ -147,7 +150,7 @@ public class Message {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sets the message status to {@link MessageStatus#READ} and sets the
 | 
			
		||||
	 * current time stamp as the read date.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void read() {
 | 
			
		||||
@@ -282,6 +285,18 @@ public class Message {
 | 
			
		||||
	 */
 | 
			
		||||
	public void setAttachmentType(AttachmentType attachmentType) { this.attachmentType = attachmentType; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the attachmentName
 | 
			
		||||
	 * @since Envoy Server v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public String getAttachmentName() { return attachmentName; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param attachmentName the attachmentName to set
 | 
			
		||||
	 * @since Envoy Server v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void setAttachmentName(String attachmentName) { this.attachmentName = attachmentName; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return whether this message is a forwarded message
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user