Remove account deletion on the server
This commit is contained in:
@ -59,8 +59,7 @@ public final class Startup {
|
||||
new NameChangeProcessor(),
|
||||
new ProfilePicChangeProcessor(),
|
||||
new PasswordChangeRequestProcessor(),
|
||||
new IssueProposalProcessor(),
|
||||
new AccountDeletionProcessor())));
|
||||
new IssueProposalProcessor())));
|
||||
|
||||
// Initialize the current message ID
|
||||
final var persistenceManager = PersistenceManager.getInstance();
|
||||
|
@ -27,18 +27,14 @@ import envoy.data.Message.MessageStatus;
|
||||
@Entity
|
||||
@Table(name = "messages")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = Message.getPending, query = "SELECT m FROM Message m WHERE "
|
||||
// Send to or by the user before last seen
|
||||
+ "(m.sender = :user OR m.recipient = :user) AND m.creationDate > :lastSeen "
|
||||
// SENT to the user
|
||||
+ "OR m.recipient = :user AND m.status = envoy.data.Message$MessageStatus.SENT "
|
||||
// Sent by the user and RECEIVED / READ after last seen
|
||||
+ "OR m.sender = :user AND (m.status = envoy.data.Message$MessageStatus.RECEIVED AND m.receivedDate > :lastSeen "
|
||||
+ "OR m.status = envoy.data.Message$MessageStatus.READ AND m.readDate > :lastSeen)"),
|
||||
@NamedQuery(name = Message.deleteByRecipient, query = "DELETE FROM Message m WHERE m.recipient = :deleted OR m.sender = :deleted")
|
||||
|
||||
})
|
||||
@NamedQuery(name = Message.getPending, query = "SELECT m FROM Message m WHERE "
|
||||
// Send to or by the user before last seen
|
||||
+ "(m.sender = :user OR m.recipient = :user) AND m.creationDate > :lastSeen "
|
||||
// SENT to the user
|
||||
+ "OR m.recipient = :user AND m.status = envoy.data.Message$MessageStatus.SENT "
|
||||
// Sent by the user and RECEIVED / READ after last seen
|
||||
+ "OR m.sender = :user AND (m.status = envoy.data.Message$MessageStatus.RECEIVED AND m.receivedDate > :lastSeen "
|
||||
+ "OR m.status = envoy.data.Message$MessageStatus.READ AND m.readDate > :lastSeen)")
|
||||
public class Message {
|
||||
|
||||
/**
|
||||
@ -49,13 +45,6 @@ public class Message {
|
||||
*/
|
||||
public static final String getPending = "Message.getPending";
|
||||
|
||||
/**
|
||||
* Named query deleting all messages of a user (parameter {@code :deleted}).
|
||||
*
|
||||
* @since Envoy Server v0.3-beta
|
||||
*/
|
||||
public static final String deleteByRecipient = "Message.deleteByRecipient";
|
||||
|
||||
@Id
|
||||
protected long id;
|
||||
|
||||
|
@ -121,12 +121,9 @@ public final class PersistenceManager {
|
||||
transaction(() -> {
|
||||
|
||||
// Remove this contact from the contact list of his contacts
|
||||
for (final var remainingContact : contact.getContacts())
|
||||
for (final var remainingContact : contact.contacts)
|
||||
remainingContact.getContacts().remove(contact);
|
||||
|
||||
entityManager
|
||||
.createNamedQuery(Message.deleteByRecipient).setParameter("deleted", contact)
|
||||
.executeUpdate();
|
||||
contact.contacts.clear();
|
||||
});
|
||||
remove(contact);
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package envoy.server.processors;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
import envoy.event.contact.AccountDeletion;
|
||||
|
||||
import envoy.server.data.*;
|
||||
import envoy.server.net.ObjectWriteProxy;
|
||||
|
||||
/**
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy Server v0.3-beta
|
||||
*/
|
||||
public class AccountDeletionProcessor implements ObjectProcessor<AccountDeletion> {
|
||||
|
||||
private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
||||
|
||||
@Override
|
||||
public void process(AccountDeletion input, long socketID, ObjectWriteProxy writeProxy)
|
||||
throws IOException {
|
||||
final var contact = persistenceManager.getContactByID(input.get());
|
||||
|
||||
contact.getContacts().forEach(c -> {
|
||||
persistenceManager.removeContactBidirectional(contact, c);
|
||||
if (c instanceof User)
|
||||
((User) c).setLatestContactDeletion(Instant.now());
|
||||
});
|
||||
|
||||
writeProxy.writeToOnlineContacts(contact.getContacts(), input);
|
||||
persistenceManager.deleteContact(contact);
|
||||
}
|
||||
}
|
@ -38,6 +38,8 @@ public final class GroupMessageStatusChangeProcessor
|
||||
}
|
||||
|
||||
GroupMessage gmsg = (GroupMessage) persistenceManager.getMessageByID(statusChange.getID());
|
||||
if (gmsg == null)
|
||||
return;
|
||||
|
||||
// Any other status than READ is not supposed to be sent to the server
|
||||
if (statusChange.get() != MessageStatus.READ) {
|
||||
|
@ -4,7 +4,6 @@ import java.time.Instant;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import envoy.event.GroupResize;
|
||||
import envoy.event.contact.AccountDeletion;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
import envoy.server.data.*;
|
||||
@ -25,11 +24,9 @@ public final class GroupResizeProcessor implements ObjectProcessor<GroupResize>
|
||||
final var group = persistenceManager.getGroupByID(groupResize.getGroupID());
|
||||
final var sender = persistenceManager.getUserByID(groupResize.get().getID());
|
||||
|
||||
// Inform the sender that this group has already been deleted
|
||||
if (group == null) {
|
||||
writeProxy.write(socketID, new AccountDeletion(groupResize.getGroupID()));
|
||||
// TODO: Inform the sender that this group has already been deleted
|
||||
if (group == null)
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform the desired operation
|
||||
switch (groupResize.getOperation()) {
|
||||
|
@ -32,6 +32,8 @@ public final class MessageStatusChangeProcessor implements ObjectProcessor<Messa
|
||||
}
|
||||
|
||||
final var msg = persistenceManager.getMessageByID(statusChange.getID());
|
||||
if (msg == null)
|
||||
return;
|
||||
msg.read();
|
||||
persistenceManager.updateMessage(msg);
|
||||
|
||||
|
@ -4,7 +4,7 @@ import java.time.Instant;
|
||||
import java.util.logging.*;
|
||||
|
||||
import envoy.event.ElementOperation;
|
||||
import envoy.event.contact.*;
|
||||
import envoy.event.contact.UserOperation;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
import envoy.server.data.PersistenceManager;
|
||||
@ -27,11 +27,9 @@ public final class UserOperationProcessor implements ObjectProcessor<UserOperati
|
||||
final long contactID = evt.get().getID();
|
||||
final var recipient = persistenceManager.getUserByID(contactID);
|
||||
|
||||
// Inform the sender if the requested contact has already been deleted
|
||||
if (recipient == null) {
|
||||
writeProxy.write(socketID, new AccountDeletion(contactID));
|
||||
// TODO: Inform the sender if the requested contact has already been deleted
|
||||
if (recipient == null)
|
||||
return;
|
||||
}
|
||||
|
||||
final var sender = persistenceManager.getUserByID(userID);
|
||||
switch (evt.getOperationType()) {
|
||||
|
Reference in New Issue
Block a user