Started implementing group message status handling

* Group creation works
This commit is contained in:
DieGurke 2020-06-09 21:05:30 +02:00 committed by CyB3RC0nN0R
parent 90103d5c49
commit 47e03dc4f4
4 changed files with 46 additions and 9 deletions

View File

@ -11,7 +11,16 @@ import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager; import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectMessageProcessor; import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader; 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.<br> * Starts the server.<br>
@ -36,6 +45,7 @@ public class Startup {
Set<ObjectProcessor<?>> processors = new HashSet<>(); Set<ObjectProcessor<?>> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor()); processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor()); processors.add(new MessageProcessor());
processors.add(new GroupCreationProcessor());
processors.add(new GroupMessageProcessor()); processors.add(new GroupMessageProcessor());
processors.add(new MessageStatusChangeProcessor()); processors.add(new MessageStatusChangeProcessor());
processors.add(new UserStatusChangeProcessor()); processors.add(new UserStatusChangeProcessor());

View File

@ -1,9 +1,12 @@
package envoy.server.data; package envoy.server.data;
import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import envoy.data.MessageBuilder; import envoy.data.MessageBuilder;
@ -22,6 +25,9 @@ public class GroupMessage extends Message {
@ElementCollection @ElementCollection
private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus; private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus;
@Temporal(TemporalType.TIMESTAMP)
protected Date lastStatusChangeDate;
/** /**
* The constructor for a database object. * The constructor for a database object.
* *
@ -32,13 +38,16 @@ public class GroupMessage extends Message {
/** /**
* Constructs a database groupMessage from a common groupMessage. * Constructs a database groupMessage from a common groupMessage.
* *
* @param groupMessage the {@link envoy.data.GroupMessage} to convert into a * @param groupMessage the {@link envoy.data.GroupMessage} to convert
* into a
* database {@link GroupMessage} * database {@link GroupMessage}
* @param lastStatusChangeDate the {@link Date} to set
* @since Envoy Server Standalone v0.1-beta * @since Envoy Server Standalone v0.1-beta
*/ */
public GroupMessage(envoy.data.GroupMessage groupMessage) { public GroupMessage(envoy.data.GroupMessage groupMessage, Date lastStatusChangeDate) {
super(groupMessage); super(groupMessage);
memberMessageStatus = groupMessage.getMemberStatuses(); memberMessageStatus = groupMessage.getMemberStatuses();
this.lastStatusChangeDate = lastStatusChangeDate;
} }
/** /**
@ -76,4 +85,16 @@ public class GroupMessage extends Message {
public void setMemberMessageStatus(Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus) { public void setMemberMessageStatus(Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus) {
this.memberMessageStatus = 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; }
} }

View File

@ -1,8 +1,11 @@
package envoy.server.processors; package envoy.server.processors;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import envoy.event.ElementOperation;
import envoy.event.GroupCreationEvent; import envoy.event.GroupCreationEvent;
import envoy.event.contact.ContactOperationEvent;
import envoy.server.data.Contact; import envoy.server.data.Contact;
import envoy.server.data.PersistenceManager; import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager; import envoy.server.net.ConnectionManager;
@ -25,10 +28,12 @@ public class GroupCreationProcessor implements ObjectProcessor<GroupCreationEven
public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException { public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
envoy.server.data.Group group = new envoy.server.data.Group(); envoy.server.data.Group group = new envoy.server.data.Group();
group.setName(input.get()); group.setName(input.get());
group.setContacts(new HashSet<>());
input.getInitialMemberIDs().stream().map(persistenceManager::getUserByID).forEach(group.getContacts()::add); 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))); group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketId(socketID)));
persistenceManager.addContact(group); persistenceManager.addContact(group);
writeProxy.write(socketID, group);
group.getContacts() group.getContacts()
.stream() .stream()
.map(Contact::getID) .map(Contact::getID)
@ -36,7 +41,7 @@ public class GroupCreationProcessor implements ObjectProcessor<GroupCreationEven
.map(connectionManager::getSocketId) .map(connectionManager::getSocketId)
.forEach(memberSocketID -> { .forEach(memberSocketID -> {
try { try {
writeProxy.write(memberSocketID, group); writeProxy.write(memberSocketID, new ContactOperationEvent(group.toCommon(), ElementOperation.ADD));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -1,6 +1,7 @@
package envoy.server.processors; package envoy.server.processors;
import java.io.IOException; import java.io.IOException;
import java.util.Date;
import javax.persistence.EntityExistsException; import javax.persistence.EntityExistsException;
@ -33,7 +34,7 @@ public class GroupMessageProcessor implements ObjectProcessor<GroupMessage> {
} }
final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts(); 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); groupMessage.getMemberStatuses().replace(i, MessageStatus.SENT);
} }
members.forEach(user -> { setMemberStatus(connectionManager, groupMessage, user.getID()); }); members.forEach(user -> { setMemberStatus(connectionManager, groupMessage, user.getID()); });
@ -45,9 +46,9 @@ public class GroupMessageProcessor implements ObjectProcessor<GroupMessage> {
members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); }); members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
try { try {
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(groupMessage)); PersistenceManager.getInstance().addMessage(new envoy.server.data.GroupMessage(groupMessage, new Date()));
} catch (EntityExistsException e) { } 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");
} }
} }