Add partially working blocking and deletion (for both client and server)

Additionally had to refactor several classes "a little bit".
(Whenever one bug seemed fixed, another one appeared...)
This commit is contained in:
2020-10-11 23:04:25 +02:00
committed by KSKE Git
parent a515ec961a
commit 571a953c40
20 changed files with 326 additions and 94 deletions

View File

@ -4,7 +4,7 @@ import java.time.Instant;
import java.util.logging.*;
import envoy.event.ElementOperation;
import envoy.event.contact.ContactOperation;
import envoy.event.contact.UserOperation;
import envoy.server.data.*;
import envoy.server.net.*;
import envoy.util.EnvoyLog;
@ -13,14 +13,14 @@ import envoy.util.EnvoyLog;
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
public final class ContactOperationProcessor implements ObjectProcessor<ContactOperation> {
public final class ContactOperationProcessor implements ObjectProcessor<UserOperation> {
private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
private static final Logger logger = EnvoyLog.getLogger(ContactOperationProcessor.class);
private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
@Override
public void process(ContactOperation evt, long socketId, ObjectWriteProxy writeProxy) {
public void process(UserOperation evt, long socketId, ObjectWriteProxy writeProxy) {
final long userID = ConnectionManager.getInstance().getUserIDBySocketID(socketId);
final long contactID = evt.get().getID();
final var sender = persistenceManager.getUserByID(userID);
@ -31,7 +31,7 @@ public final class ContactOperationProcessor implements ObjectProcessor<ContactO
// Notify the contact if online
if (connectionManager.isOnline(contactID))
writeProxy.write(connectionManager.getSocketID(contactID), new ContactOperation(sender.toCommon(), ElementOperation.ADD));
writeProxy.write(connectionManager.getSocketID(contactID), new UserOperation(sender.toCommon(), ElementOperation.ADD));
break;
case REMOVE:
@ -49,7 +49,7 @@ public final class ContactOperationProcessor implements ObjectProcessor<ContactO
// Notify the removed contact if online
if (connectionManager.isOnline(contactID))
writeProxy.write(connectionManager.getSocketID(contactID), new ContactOperation(sender.toCommon(), ElementOperation.REMOVE));
writeProxy.write(connectionManager.getSocketID(contactID), new UserOperation(sender.toCommon(), ElementOperation.REMOVE));
} else {
// The sender wants to be removed from a Group
@ -60,7 +60,7 @@ public final class ContactOperationProcessor implements ObjectProcessor<ContactO
else {
// Informing the other members
writeProxy.writeToOnlineContacts(group.getContacts(), new ContactOperation(sender.toCommon(), ElementOperation.REMOVE));
writeProxy.writeToOnlineContacts(group.getContacts(), new UserOperation(sender.toCommon(), ElementOperation.REMOVE));
group.getContacts().forEach(c -> ((User) c).setLatestContactDeletion(Instant.now()));
}
}

View File

@ -5,7 +5,6 @@ import static envoy.server.Startup.config;
import java.util.HashSet;
import envoy.event.*;
import envoy.event.contact.ContactOperation;
import envoy.server.data.*;
import envoy.server.net.*;
@ -21,8 +20,10 @@ public final class GroupCreationProcessor implements ObjectProcessor<GroupCreati
@Override
public void process(GroupCreation groupCreation, long socketID, ObjectWriteProxy writeProxy) {
// Don't allow the creation of groups if manually disabled
writeProxy.write(socketID, new GroupCreationResult(config.isGroupSupportEnabled()));
if (!config.isGroupSupportEnabled()) return;
if (!config.isGroupSupportEnabled()) {
writeProxy.write(socketID, new GroupCreationResult());
return;
}
final envoy.server.data.Group group = new envoy.server.data.Group();
group.setName(groupCreation.get());
group.setContacts(new HashSet<>());
@ -31,11 +32,13 @@ public final class GroupCreationProcessor implements ObjectProcessor<GroupCreati
group.getContacts().forEach(c -> c.getContacts().add(group));
group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIDBySocketID(socketID)));
persistenceManager.addContact(group);
final var resultGroup = group.toCommon();
group.getContacts()
.stream()
.map(Contact::getID)
.filter(connectionManager::isOnline)
.map(connectionManager::getSocketID)
.forEach(memberSocketID -> writeProxy.write(memberSocketID, new ContactOperation(group.toCommon(), ElementOperation.ADD)));
.forEach(memberSocketID -> writeProxy.write(memberSocketID, new GroupCreationResult(resultGroup)));
writeProxy.write(socketID, new GroupCreationResult(resultGroup));
}
}

View File

@ -13,7 +13,7 @@ import javax.persistence.NoResultException;
import envoy.data.LoginCredentials;
import envoy.event.*;
import envoy.event.contact.ContactDeletionSinceLastLogin;
import envoy.event.contact.ContactsChangedSinceLastLogin;
import envoy.server.data.*;
import envoy.server.net.*;
import envoy.server.util.*;
@ -207,11 +207,10 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
writeProxy.write(socketID, new MessageStatusChange(gmsgCommon));
}
}
// Notify the user if a contact deletion has happened since he last logged in
if (user.getLatestContactDeletion().isAfter(user.getLastSeen())) writeProxy.write(socketID, new ContactsChangedSinceLastLogin());
// Complete the handshake
writeProxy.write(socketID, user.toCommon());
// Notify the user if a contact deletion has happened since he last logged in
if (user.getLatestContactDeletion().isAfter(user.getLastSeen())) writeProxy.write(socketID, new ContactDeletionSinceLastLogin());
}
}