Add client side errors in case of data initialization with null values
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package envoy.server.data;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.persistence.*;
|
||||
@ -223,6 +223,9 @@ public final class PersistenceManager {
|
||||
* @since Envoy Server Standalone v0.2-beta
|
||||
*/
|
||||
public List<Message> getPendingMessages(User user, Instant lastSync) {
|
||||
if (user == null)
|
||||
return new ArrayList<>();
|
||||
lastSync = Objects.requireNonNullElse(lastSync, Instant.EPOCH);
|
||||
return entityManager.createNamedQuery(Message.getPending).setParameter("user", user)
|
||||
.setParameter("lastSeen", lastSync).getResultList();
|
||||
}
|
||||
@ -236,6 +239,9 @@ public final class PersistenceManager {
|
||||
* @since Envoy Server Standalone v0.2-beta
|
||||
*/
|
||||
public List<GroupMessage> getPendingGroupMessages(User user, Instant lastSync) {
|
||||
if (user == null)
|
||||
return new ArrayList<>();
|
||||
lastSync = Objects.requireNonNullElse(lastSync, Instant.EPOCH);
|
||||
return entityManager.createNamedQuery(GroupMessage.getPendingGroupMsg)
|
||||
.setParameter("userId", user.getID())
|
||||
.setParameter("lastSeen", lastSync)
|
||||
@ -277,16 +283,18 @@ public final class PersistenceManager {
|
||||
* @since Envoy Server v0.3-beta
|
||||
*/
|
||||
public void addContactBidirectional(Contact contact1, Contact contact2) {
|
||||
if (!(contact1 == null || contact2 == null)) {
|
||||
|
||||
// Add users to each others contact list
|
||||
contact1.getContacts().add(contact2);
|
||||
contact2.getContacts().add(contact1);
|
||||
// Add users to each others contact list
|
||||
contact1.getContacts().add(contact2);
|
||||
contact2.getContacts().add(contact1);
|
||||
|
||||
// Synchronize changes with the database
|
||||
transaction(() -> {
|
||||
entityManager.merge(contact1);
|
||||
entityManager.merge(contact2);
|
||||
});
|
||||
// Synchronize changes with the database
|
||||
transaction(() -> {
|
||||
entityManager.merge(contact1);
|
||||
entityManager.merge(contact2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -308,16 +316,18 @@ public final class PersistenceManager {
|
||||
* @since Envoy Server v0.3-beta
|
||||
*/
|
||||
public void removeContactBidirectional(Contact contact1, Contact contact2) {
|
||||
if (!(contact1 == null || contact2 == null)) {
|
||||
|
||||
// Remove users from each others contact list
|
||||
contact1.getContacts().remove(contact2);
|
||||
contact2.getContacts().remove(contact1);
|
||||
// Remove users from each others contact list
|
||||
contact1.getContacts().remove(contact2);
|
||||
contact2.getContacts().remove(contact1);
|
||||
|
||||
// Synchronize changes with the database
|
||||
transaction(() -> {
|
||||
entityManager.merge(contact1);
|
||||
entityManager.merge(contact2);
|
||||
});
|
||||
// Synchronize changes with the database
|
||||
transaction(() -> {
|
||||
entityManager.merge(contact1);
|
||||
entityManager.merge(contact2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user