Apply suggestions from code review (not everything)

Co-authored-by: CyB3RC0nN0R <CyB3RC0nN0R@users.noreply.github.com>
This commit is contained in:
DieGurke 2020-07-05 16:53:27 +02:00 committed by GitHub
parent 83ddc02187
commit e33bc726ac
6 changed files with 10 additions and 28 deletions

View File

@ -14,16 +14,7 @@ import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
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;
import envoy.server.processors.MessageStatusChangeProcessor;
import envoy.server.processors.UserStatusChangeProcessor;
import envoy.server.processors.*;
import envoy.util.EnvoyLog;
/**

View File

@ -4,12 +4,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.*;
import envoy.data.Group;

View File

@ -21,8 +21,9 @@ import envoy.server.net.ObjectWriteProxy;
*/
public class GroupMessageStatusChangeProcessor implements ObjectProcessor<GroupMessageStatusChange> {
private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
private final ConnectionManager connectionManager = ConnectionManager.getInstance();
private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
@Override
public void process(GroupMessageStatusChange input, long socketID, ObjectWriteProxy writeProxy) throws IOException {

View File

@ -1,10 +1,7 @@
package envoy.server.processors;
import static envoy.data.User.UserStatus.ONLINE;
import static envoy.event.HandshakeRejection.INTERNAL_ERROR;
import static envoy.event.HandshakeRejection.USERNAME_TAKEN;
import static envoy.event.HandshakeRejection.WRONG_PASSWORD_OR_USER;
import static envoy.event.HandshakeRejection.WRONG_VERSION;
import static envoy.event.HandshakeRejection.*;
import java.io.IOException;
import java.time.LocalDateTime;
@ -122,7 +119,7 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
writeProxy.write(socketID, user.toCommon());
final var pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
pendingMessages.removeIf(m -> m instanceof GroupMessage);
pendingMessages.removeIf(GroupMessage.class::isInstance);
logger.fine("Sending " + pendingMessages.size() + " pending messages to " + user + "...");
List<GroupMessage> pendingGroupMessages = PersistenceManager.getInstance().getPendingGroupMessages(user);
@ -161,9 +158,7 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
(new GroupMessageStatusChange(gmsg.getID(), MessageStatus.RECEIVED, LocalDateTime.now(),
connectionManager.getUserIdBySocketID(socketID))));
} catch (IOException e) {
// TODO Maybe Try Catch block is not necessarily needed but if so write proper
// logger statement here.
e.printStackTrace();
logger.log(Level.WARNING, "Could not deliver group message status changes", e);
}
});
if (!gmsg.getMemberMessageStatus().containsValue(MessageStatus.SENT)) {

View File

@ -34,7 +34,7 @@ public class MessageProcessor implements ObjectProcessor<Message> {
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
// Makes sure, that there are no groupMessages processed here, because
// groupMessage is a subclass of message.
if (message.getClass().equals(envoy.data.GroupMessage.class)) {
if (message instanceof envoy.data.GroupMessage)) {
return;
}
message.nextStatus();

View File

@ -26,7 +26,7 @@ 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;
if (statusChange instanceof GroupMessageStatusChange)) 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"));