Added received and read dates to database message copy constructor
Fixes #24
This commit is contained in:
		@@ -52,14 +52,15 @@ public class Message {
 | 
			
		||||
	private byte[]								attachment;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * The constructor for a database object
 | 
			
		||||
	 * The constructor for a database object.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public Message() {}
 | 
			
		||||
 | 
			
		||||
	// TODO: everything except ID
 | 
			
		||||
	/**
 | 
			
		||||
	 * Constructs a database message from a common message.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param message the {@link envoy.data.Message} to convert into a database
 | 
			
		||||
	 *                {@link Message}
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
			
		||||
@@ -70,9 +71,11 @@ public class Message {
 | 
			
		||||
		status			= message.getStatus();
 | 
			
		||||
		text			= message.getText();
 | 
			
		||||
		creationDate	= message.getCreationDate();
 | 
			
		||||
		receivedDate	= message.getReceivedDate();
 | 
			
		||||
		readDate		= message.getReadDate();
 | 
			
		||||
		sender			= persMan.getUserById(message.getSenderId());
 | 
			
		||||
		recipient		= persMan.getUserById(message.getRecipientId());
 | 
			
		||||
		// attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
 | 
			
		||||
		// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
@@ -22,9 +22,6 @@ import envoy.server.net.ObjectWriteProxy;
 | 
			
		||||
 */
 | 
			
		||||
public class MessageProcessor implements ObjectProcessor<Message> {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Class<Message> getInputClass() { return Message.class; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void process(Message message, long socketId, ObjectWriteProxy writeProxy) {
 | 
			
		||||
 | 
			
		||||
@@ -44,4 +41,7 @@ public class MessageProcessor implements ObjectProcessor<Message> {
 | 
			
		||||
		}
 | 
			
		||||
		PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public Class<Message> getInputClass() { return Message.class; }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,26 +20,28 @@ import envoy.server.net.ObjectWriteProxy;
 | 
			
		||||
 */
 | 
			
		||||
public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStatusChangeEvent> {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Class<MessageStatusChangeEvent> getInputClass() { return MessageStatusChangeEvent.class; }
 | 
			
		||||
	private final PersistenceManager	persistenceManager	= PersistenceManager.getInstance();
 | 
			
		||||
	private final ConnectionManager		connectionManager	= ConnectionManager.getInstance();
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void process(MessageStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
 | 
			
		||||
		try {
 | 
			
		||||
			// any other status than read is not supposed to be sent to the server
 | 
			
		||||
			if (input.get() != MessageStatus.READ) throw new EnvoyException("Message" + input.getId() + "has an invalid status");
 | 
			
		||||
			if (input.get() != MessageStatus.READ) throw new EnvoyException("Message " + input + " has an invalid status");
 | 
			
		||||
		} catch (EnvoyException e) {
 | 
			
		||||
			throw new IOException(e);
 | 
			
		||||
		}
 | 
			
		||||
		ConnectionManager	conMan	= ConnectionManager.getInstance();
 | 
			
		||||
		PersistenceManager	perMan	= PersistenceManager.getInstance();
 | 
			
		||||
 | 
			
		||||
		envoy.server.data.Message msg = perMan.getMessageById(input.getId());
 | 
			
		||||
		envoy.server.data.Message msg = persistenceManager.getMessageById(input.getId());
 | 
			
		||||
		msg.setStatus(input.get());
 | 
			
		||||
		msg.setReadDate(input.getDate());
 | 
			
		||||
		perMan.updateMessage(msg);
 | 
			
		||||
		persistenceManager.updateMessage(msg);
 | 
			
		||||
 | 
			
		||||
		// Notifies the sender of the message about the status-update to READ
 | 
			
		||||
		if (conMan.isOnline(msg.getSender().getId())) writeProxy.write(conMan.getSocketId(msg.getSender().getId()), input);
 | 
			
		||||
		final long senderId = msg.getSender().getId();
 | 
			
		||||
		if (connectionManager.isOnline(senderId)) writeProxy.write(connectionManager.getSocketId(senderId), input);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Class<MessageStatusChangeEvent> getInputClass() { return MessageStatusChangeEvent.class; }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user