diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index 0811bbb..bdcac7d 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -11,7 +11,16 @@ import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
-import envoy.server.processors.*;
+import envoy.server.processors.ContactOperationProcessor;
+import envoy.server.processors.ContactsRequestEventProcessor;
+import envoy.server.processors.GroupCreationProcessor;
+import envoy.server.processors.GroupMessageProcessor;
+import envoy.server.processors.IDGeneratorRequestProcessor;
+import envoy.server.processors.LoginCredentialProcessor;
+import envoy.server.processors.MessageProcessor;
+import envoy.server.processors.MessageStatusChangeProcessor;
+import envoy.server.processors.ObjectProcessor;
+import envoy.server.processors.UserStatusChangeProcessor;
/**
* Starts the server.
@@ -36,6 +45,7 @@ public class Startup {
Set> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
+ processors.add(new GroupCreationProcessor());
processors.add(new GroupMessageProcessor());
processors.add(new MessageStatusChangeProcessor());
processors.add(new UserStatusChangeProcessor());
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index ad9da17..bc9fed7 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -1,9 +1,12 @@
package envoy.server.data;
+import java.util.Date;
import java.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import envoy.data.MessageBuilder;
@@ -22,6 +25,9 @@ public class GroupMessage extends Message {
@ElementCollection
private Map memberMessageStatus;
+ @Temporal(TemporalType.TIMESTAMP)
+ protected Date lastStatusChangeDate;
+
/**
* The constructor for a database object.
*
@@ -32,13 +38,16 @@ public class GroupMessage extends Message {
/**
* Constructs a database groupMessage from a common groupMessage.
*
- * @param groupMessage the {@link envoy.data.GroupMessage} to convert into a
- * database {@link GroupMessage}
+ * @param groupMessage the {@link envoy.data.GroupMessage} to convert
+ * into a
+ * database {@link GroupMessage}
+ * @param lastStatusChangeDate the {@link Date} to set
* @since Envoy Server Standalone v0.1-beta
*/
- public GroupMessage(envoy.data.GroupMessage groupMessage) {
+ public GroupMessage(envoy.data.GroupMessage groupMessage, Date lastStatusChangeDate) {
super(groupMessage);
memberMessageStatus = groupMessage.getMemberStatuses();
+ this.lastStatusChangeDate = lastStatusChangeDate;
}
/**
@@ -76,4 +85,16 @@ public class GroupMessage extends Message {
public void setMemberMessageStatus(Map memberMessageStatus) {
this.memberMessageStatus = memberMessageStatus;
}
+
+ /**
+ * @return the date at which one of the member statuses changed last
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Date getLastStatusChangeDate() { return lastStatusChangeDate; }
+
+ /**
+ * @param date the date to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setLastStatusChangeDate(Date date) { lastStatusChangeDate = date; }
}
diff --git a/src/main/java/envoy/server/processors/GroupCreationProcessor.java b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
index 7bb71b3..8e4cf1b 100644
--- a/src/main/java/envoy/server/processors/GroupCreationProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
@@ -1,8 +1,11 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.HashSet;
+import envoy.event.ElementOperation;
import envoy.event.GroupCreationEvent;
+import envoy.event.contact.ContactOperationEvent;
import envoy.server.data.Contact;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
@@ -25,10 +28,12 @@ public class GroupCreationProcessor implements ObjectProcessor());
input.getInitialMemberIDs().stream().map(persistenceManager::getUserByID).forEach(group.getContacts()::add);
+ group.getContacts().add(persistenceManager.getContactByID(connectionManager.getUserIdBySocketId(socketID)));
+ group.getContacts().forEach(c -> c.getContacts().add(group));
group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketId(socketID)));
persistenceManager.addContact(group);
- writeProxy.write(socketID, group);
group.getContacts()
.stream()
.map(Contact::getID)
@@ -36,7 +41,7 @@ public class GroupCreationProcessor implements ObjectProcessor {
try {
- writeProxy.write(memberSocketID, group);
+ writeProxy.write(memberSocketID, new ContactOperationEvent(group.toCommon(), ElementOperation.ADD));
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
index e1815b3..48f1441 100644
--- a/src/main/java/envoy/server/processors/GroupMessageProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -1,6 +1,7 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.Date;
import javax.persistence.EntityExistsException;
@@ -33,7 +34,7 @@ public class GroupMessageProcessor implements ObjectProcessor {
}
final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts();
- for (long i = 0; i < groupMessage.getMemberStatuses().keySet().size(); i++) {
+ for (long i = 0; i < groupMessage.getMemberStatuses().size(); i++) {
groupMessage.getMemberStatuses().replace(i, MessageStatus.SENT);
}
members.forEach(user -> { setMemberStatus(connectionManager, groupMessage, user.getID()); });
@@ -45,9 +46,9 @@ public class GroupMessageProcessor implements ObjectProcessor {
members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
try {
- PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(groupMessage));
+ PersistenceManager.getInstance().addMessage(new envoy.server.data.GroupMessage(groupMessage, new Date()));
} catch (EntityExistsException e) {
- System.err.println("Received a groupMessage with an id that already exists");
+ System.err.println("Received a groupMessage with an ID that already exists");
}
}