Added received and read dates to database message copy constructor
Fixes #24
This commit is contained in:
parent
0347715d72
commit
87ca90c333
@ -52,14 +52,15 @@ public class Message {
|
|||||||
private byte[] attachment;
|
private byte[] attachment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor for a database object
|
* The constructor for a database object.
|
||||||
*
|
*
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public Message() {}
|
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
|
* @param message the {@link envoy.data.Message} to convert into a database
|
||||||
* {@link Message}
|
* {@link Message}
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
@ -70,9 +71,11 @@ public class Message {
|
|||||||
status = message.getStatus();
|
status = message.getStatus();
|
||||||
text = message.getText();
|
text = message.getText();
|
||||||
creationDate = message.getCreationDate();
|
creationDate = message.getCreationDate();
|
||||||
|
receivedDate = message.getReceivedDate();
|
||||||
|
readDate = message.getReadDate();
|
||||||
sender = persMan.getUserById(message.getSenderId());
|
sender = persMan.getUserById(message.getSenderId());
|
||||||
recipient = persMan.getUserById(message.getRecipientId());
|
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> {
|
public class MessageProcessor implements ObjectProcessor<Message> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<Message> getInputClass() { return Message.class; }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(Message message, long socketId, ObjectWriteProxy writeProxy) {
|
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));
|
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> {
|
public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStatusChangeEvent> {
|
||||||
|
|
||||||
@Override
|
private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
||||||
public Class<MessageStatusChangeEvent> getInputClass() { return MessageStatusChangeEvent.class; }
|
private final ConnectionManager connectionManager = ConnectionManager.getInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(MessageStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(MessageStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
try {
|
try {
|
||||||
// any other status than read is not supposed to be sent to the server
|
// 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) {
|
} catch (EnvoyException e) {
|
||||||
throw new IOException(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.setStatus(input.get());
|
||||||
msg.setReadDate(input.getDate());
|
msg.setReadDate(input.getDate());
|
||||||
perMan.updateMessage(msg);
|
persistenceManager.updateMessage(msg);
|
||||||
|
|
||||||
// Notifies the sender of the message about the status-update to READ
|
// 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