Merge branch 'develop' into f/groupMessages

This commit is contained in:
Kai S. K. Engelbart 2020-07-04 14:23:12 +00:00 committed by GitHub
commit 8ba70407af
6 changed files with 50 additions and 29 deletions

View File

@ -40,7 +40,7 @@ public class Startup {
/** /**
* Initializes the logger with a new config instance. * Initializes the logger with a new config instance.
* *
* @since Envoy Server Standalone v0.1-beta * @since Envoy Server Standalone v0.1-beta
*/ */
private static void initLogging() { private static void initLogging() {
@ -60,14 +60,15 @@ public class Startup {
/** /**
* Starts the server. * Starts the server.
* *
* @param args the run configuration. Currently unused. * @param args the run configuration. If it is "no-enter-to-stop" at position 0,
* no command to read in an enter press will be generated
* @throws IOException if the server crashes * @throws IOException if the server crashes
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
initLogging(); initLogging();
Server server = new Server(8080, ObjectMessageReader::new, final Server server = new Server(8080, ObjectMessageReader::new,
new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(), new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(),
new MessageProcessor(), new MessageProcessor(),
new GroupMessageProcessor(), new GroupMessageProcessor(),
@ -80,16 +81,18 @@ public class Startup {
new ContactOperationProcessor()))); new ContactOperationProcessor())));
// Initialize the current message ID // Initialize the current message ID
PersistenceManager persistenceManager = PersistenceManager.getInstance(); final PersistenceManager persistenceManager = PersistenceManager.getInstance();
if (persistenceManager.getConfigItemByID("currentMessageId") == null) if (persistenceManager.getConfigItemByID("currentMessageId") == null)
persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0")); persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0"));
server.start(); server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
System.out.println("Press the return key to stop the server..."); if (args.length == 0 || !args[0].equalsIgnoreCase("no-enter-to-stop")) {
System.in.read(); System.out.println("Press the return key to stop the server...");
System.out.println("Stopped"); System.in.read();
System.exit(0); System.out.println("Stopped");
System.exit(0);
}
} }
} }

View File

@ -11,7 +11,7 @@ import javax.persistence.NamedQuery;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import envoy.data.MessageBuilder; import envoy.data.Group;
/** /**
* Project: <strong>envoy-server-standalone</strong><br> * Project: <strong>envoy-server-standalone</strong><br>
@ -71,15 +71,7 @@ public class GroupMessage extends Message {
*/ */
@Override @Override
public envoy.data.GroupMessage toCommon() { public envoy.data.GroupMessage toCommon() {
// TODO: Attachment return prepareBuilder().buildGroupMessage((Group) recipient.toCommon(), new HashMap<>(memberMessageStatus));
envoy.data.GroupMessage groupMessage = new MessageBuilder(sender.getID(), recipient.getID(), id).setCreationDate(creationDate)
.setForwarded(forwarded)
.setStatus(status)
.setText(text)
.buildGroupMessage((envoy.data.Group) recipient.toCommon(), new HashMap<>(memberMessageStatus));
groupMessage.setReceivedDate(receivedDate);
groupMessage.setReadDate(readDate);
return groupMessage;
} }
/** /**

View File

@ -6,6 +6,8 @@ import java.time.LocalDateTime;
import javax.persistence.*; import javax.persistence.*;
import envoy.data.Attachment;
import envoy.data.Attachment.AttachmentType;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.data.MessageBuilder; import envoy.data.MessageBuilder;
@ -63,6 +65,7 @@ public class Message {
protected String text; protected String text;
protected envoy.data.Message.MessageStatus status; protected envoy.data.Message.MessageStatus status;
protected AttachmentType attachmentType;
protected byte[] attachment; protected byte[] attachment;
protected boolean forwarded; protected boolean forwarded;
@ -91,7 +94,10 @@ public class Message {
sender = persistenceManager.getUserByID(message.getSenderID()); sender = persistenceManager.getUserByID(message.getSenderID());
recipient = persistenceManager.getContactByID(message.getRecipientID()); recipient = persistenceManager.getContactByID(message.getRecipientID());
forwarded = message.isForwarded(); forwarded = message.isForwarded();
// TODO: Attachment if (message.hasAttachment()) {
attachment = message.getAttachment().getData();
attachmentType = message.getAttachment().getType();
}
} }
/** /**
@ -102,15 +108,23 @@ public class Message {
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
public envoy.data.Message toCommon() { public envoy.data.Message toCommon() {
// TODO: Attachment return prepareBuilder().build();
envoy.data.Message message = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(text) }
/**
* @return a message builder containing the state of this message
* @since Envoy Server Standalone v0.1-beta
*/
MessageBuilder prepareBuilder() {
var builder = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(
text)
.setCreationDate(creationDate) .setCreationDate(creationDate)
.setReceivedDate(receivedDate)
.setReadDate(readDate)
.setStatus(status) .setStatus(status)
.setForwarded(forwarded) .setForwarded(forwarded);
.build(); if (attachment != null) builder.setAttachment(new Attachment(attachment, attachmentType));
message.setReceivedDate(receivedDate); return builder;
message.setReadDate(readDate);
return message;
} }
/** /**
@ -250,6 +264,18 @@ public class Message {
*/ */
public void setAttachment(byte[] attachment) { this.attachment = attachment; } public void setAttachment(byte[] attachment) { this.attachment = attachment; }
/**
* @return the attachmentType
* @since Envoy Server Standalone v0.1-beta
*/
public AttachmentType getAttachmentType() { return attachmentType; }
/**
* @param attachmentType the attachmentType to set
* @since Envoy Server Standalone v0.1-beta
*/
public void setAttachmentType(AttachmentType attachmentType) { this.attachmentType = attachmentType; }
/** /**
* @return whether this message is a forwarded message * @return whether this message is a forwarded message
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha

View File

@ -16,7 +16,6 @@ import java.util.logging.Logger;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import enovy.server.util.VersionUtils;
import envoy.data.LoginCredentials; import envoy.data.LoginCredentials;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.event.GroupMessageStatusChange; import envoy.event.GroupMessageStatusChange;
@ -27,6 +26,7 @@ import envoy.server.data.PersistenceManager;
import envoy.server.data.User; import envoy.server.data.User;
import envoy.server.net.ConnectionManager; import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy; import envoy.server.net.ObjectWriteProxy;
import envoy.server.util.VersionUtils;
import envoy.util.Bounds; import envoy.util.Bounds;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;

View File

@ -1,4 +1,4 @@
package enovy.server.util; package envoy.server.util;
import java.util.regex.Pattern; import java.util.regex.Pattern;

View File

@ -8,4 +8,4 @@
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-beta * @since Envoy Server Standalone v0.1-beta
*/ */
package enovy.server.util; package envoy.server.util;