Implemented GroupMessageStatusChange handling (not with pending yet)

This commit is contained in:
DieGurke 2020-07-03 16:25:49 +02:00
parent 5e46ba88c9
commit 3c8a5c7abb
3 changed files with 74 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import envoy.server.processors.ContactOperationProcessor;
import envoy.server.processors.ContactSearchProcessor;
import envoy.server.processors.GroupCreationProcessor;
import envoy.server.processors.GroupMessageProcessor;
import envoy.server.processors.GroupMessageStatusChangeProcessor;
import envoy.server.processors.IDGeneratorRequestProcessor;
import envoy.server.processors.LoginCredentialProcessor;
import envoy.server.processors.MessageProcessor;
@ -72,6 +73,7 @@ public class Startup {
new GroupMessageProcessor(),
new GroupCreationProcessor(),
new MessageStatusChangeProcessor(),
new GroupMessageStatusChangeProcessor(),
new UserStatusChangeProcessor(),
new IDGeneratorRequestProcessor(),
new ContactSearchProcessor(),

View File

@ -0,0 +1,69 @@
package envoy.server.processors;
import java.io.IOException;
import envoy.data.Message.MessageStatus;
import envoy.event.GroupMessageStatusChange;
import envoy.event.MessageStatusChange;
import envoy.exception.EnvoyException;
import envoy.server.data.GroupMessage;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
/**
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>GroupMessageStatusChangeProcessor.java</strong><br>
* Created: <strong>03.07.2020</strong><br>
*
* @author Maximilian K&auml;fer
* @since Envoy Server Standalone v0.1-beta
*/
public class GroupMessageStatusChangeProcessor implements ObjectProcessor<GroupMessageStatusChange> {
private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
private final ConnectionManager connectionManager = ConnectionManager.getInstance();
@Override
public void process(GroupMessageStatusChange input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
GroupMessage gmsg = (GroupMessage) persistenceManager.getMessageByID(input.getID());
if (gmsg.getStatus() == input.get())
throw new IOException(new EnvoyException("The groupMessage already has the status " + input.get()));
gmsg.getMemberMessageStatus().replace(input.getMemberID(), input.get());
// Notifying the other members about memberStatusChange
gmsg.getMemberMessageStatus().keySet().stream().filter(k -> connectionManager.getUserIdBySocketID(socketID) != k).forEach(k -> {
if(connectionManager.isOnline(k)) {
try {
writeProxy.write(connectionManager.getSocketID(k), input);
} catch (IOException e) {
// TODO Maybe Try Catch block is not necessarily needed but if so write proper
// logger statement here.
e.printStackTrace();
}
}
});
if (!gmsg.getMemberMessageStatus().containsValue(MessageStatus.SENT)
&& !gmsg.getMemberMessageStatus().containsValue(MessageStatus.RECEIVED)) {
gmsg.read();
// Notifying the other members about messageStatusChange
gmsg.getMemberMessageStatus().keySet().forEach(k -> {
if (connectionManager.isOnline(k)) {
try {
writeProxy.write(connectionManager.getSocketID(k), new MessageStatusChange(input.getID(), input.get(), input.getDate()));
} catch (IOException e) {
// TODO Maybe Try Catch block is not necessarily needed but if so write proper
// logger statement here.
e.printStackTrace();
}
}
});
}
persistenceManager.updateMessage(gmsg);
}
@Override
public Class<GroupMessageStatusChange> getInputClass() { return GroupMessageStatusChange.class; }
}

View File

@ -3,6 +3,7 @@ package envoy.server.processors;
import java.io.IOException;
import envoy.data.Message.MessageStatus;
import envoy.event.GroupMessageStatusChange;
import envoy.event.MessageStatusChange;
import envoy.exception.EnvoyException;
import envoy.server.data.PersistenceManager;
@ -24,6 +25,8 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
@Override
public void process(MessageStatusChange statusChange, long socketID, ObjectWriteProxy writeProxy) throws IOException {
// Filtering out subclass objects, which should not be processed here.
if (statusChange.getClass().equals(GroupMessageStatusChange.class)) return;
// Any other status than READ is not supposed to be sent to the server
if (statusChange.get() != MessageStatus.READ) throw new IOException(new EnvoyException(statusChange + " has an invalid status"));