Implemented functionality regarding pending groupMessages (unfinished)
(This was implemented some weeks ago but never pushed (made some revision))
This commit is contained in:
parent
be40f24904
commit
a34e90adb8
@ -3,7 +3,12 @@ package envoy.server.data;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.*;
|
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 envoy.data.MessageBuilder;
|
import envoy.data.MessageBuilder;
|
||||||
|
|
||||||
@ -16,8 +21,14 @@ import envoy.data.MessageBuilder;
|
|||||||
* @since Envoy Server Standalone v0.1-beta
|
* @since Envoy Server Standalone v0.1-beta
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
|
@NamedQuery(
|
||||||
|
name = GroupMessage.getPendingGroupMsg,
|
||||||
|
query = "SELECT m FROM GroupMessage m JOIN m.memberMessageStatus s WHERE (KEY(s) = :userId) AND (m.creationDate > :lastSeen)"
|
||||||
|
)
|
||||||
public class GroupMessage extends Message {
|
public class GroupMessage extends Message {
|
||||||
|
|
||||||
|
public static final String getPendingGroupMsg = "GroupMessage.getPendingGroupMsg";
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus;
|
private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus;
|
||||||
|
|
||||||
|
@ -194,6 +194,22 @@ public class PersistenceManager {
|
|||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all groupMessages received while being offline or the ones that have
|
||||||
|
* changed.
|
||||||
|
*
|
||||||
|
* @param user the user who wants to receive his unread groupMessages
|
||||||
|
* @return all groupMessages that the client does not yet have (unread
|
||||||
|
* groupMessages)
|
||||||
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
|
*/
|
||||||
|
public List<GroupMessage> getPendingGroupMessages(User user) {
|
||||||
|
return entityManager.createNamedQuery(GroupMessage.getPendingGroupMsg)
|
||||||
|
.setParameter("userId", user.getID())
|
||||||
|
.setParameter("lastSeen", user.getLastSeen())
|
||||||
|
.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for users matching a search phrase. Contacts of the attached user
|
* Searches for users matching a search phrase. Contacts of the attached user
|
||||||
* and the attached user is ignored.
|
* and the attached user is ignored.
|
||||||
|
@ -8,7 +8,6 @@ import javax.persistence.EntityExistsException;
|
|||||||
|
|
||||||
import envoy.data.GroupMessage;
|
import envoy.data.GroupMessage;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.event.MessageStatusChange;
|
|
||||||
import envoy.server.data.PersistenceManager;
|
import envoy.server.data.PersistenceManager;
|
||||||
import envoy.server.net.ConnectionManager;
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
@ -43,12 +42,12 @@ public class GroupMessageProcessor implements ObjectProcessor<GroupMessage> {
|
|||||||
// sender, if he is still online.
|
// sender, if he is still online.
|
||||||
if (!groupMessage.getMemberStatuses().containsValue(MessageStatus.SENT)) {
|
if (!groupMessage.getMemberStatuses().containsValue(MessageStatus.SENT)) {
|
||||||
groupMessage.setStatus(MessageStatus.RECEIVED);
|
groupMessage.setStatus(MessageStatus.RECEIVED);
|
||||||
if (connectionManager.isOnline(connectionManager.getUserIdBySocketID(socketID))) try {
|
// if (connectionManager.isOnline(connectionManager.getUserIdBySocketID(socketID))) try {
|
||||||
writeProxy.write(socketID, new MessageStatusChange(groupMessage));
|
// writeProxy.write(socketID, new MessageStatusChange(groupMessage));
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
logger.warning("Sender of the groupMessage online. Failed to send MessageStatusChange");
|
// logger.warning("Sender of the groupMessage online. Failed to send MessageStatusChange");
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
members.stream()
|
members.stream()
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package envoy.server.processors;
|
package envoy.server.processors;
|
||||||
|
|
||||||
import static envoy.data.User.UserStatus.ONLINE;
|
import static envoy.data.User.UserStatus.ONLINE;
|
||||||
import static envoy.event.HandshakeRejection.*;
|
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 java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
@ -16,6 +20,7 @@ import envoy.data.LoginCredentials;
|
|||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.event.HandshakeRejection;
|
import envoy.event.HandshakeRejection;
|
||||||
import envoy.event.MessageStatusChange;
|
import envoy.event.MessageStatusChange;
|
||||||
|
import envoy.server.data.GroupMessage;
|
||||||
import envoy.server.data.PersistenceManager;
|
import envoy.server.data.PersistenceManager;
|
||||||
import envoy.server.data.User;
|
import envoy.server.data.User;
|
||||||
import envoy.server.net.ConnectionManager;
|
import envoy.server.net.ConnectionManager;
|
||||||
@ -117,6 +122,9 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
|||||||
final var pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
|
final var pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
|
||||||
logger.fine("Sending " + pendingMessages.size() + " pending messages to " + user + "...");
|
logger.fine("Sending " + pendingMessages.size() + " pending messages to " + user + "...");
|
||||||
|
|
||||||
|
List<GroupMessage> pendingGroupMessages = PersistenceManager.getInstance().getPendingGroupMessages(user);
|
||||||
|
logger.fine("Sending " + pendingGroupMessages.size() + " pending group messages to " + user + "...");
|
||||||
|
|
||||||
for (var msg : pendingMessages) {
|
for (var msg : pendingMessages) {
|
||||||
final var msgCommon = msg.toCommon();
|
final var msgCommon = msg.toCommon();
|
||||||
if (msg.getStatus() == MessageStatus.SENT) {
|
if (msg.getStatus() == MessageStatus.SENT) {
|
||||||
@ -133,6 +141,23 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
|||||||
}
|
}
|
||||||
} else writeProxy.write(socketID, new MessageStatusChange(msgCommon));
|
} else writeProxy.write(socketID, new MessageStatusChange(msgCommon));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (GroupMessage gmsg : pendingGroupMessages) {
|
||||||
|
if (gmsg.getMemberMessageStatus().get(user.getID()) == MessageStatus.SENT) {
|
||||||
|
gmsg.getMemberMessageStatus().replace(user.getID(), MessageStatus.RECEIVED);
|
||||||
|
logger.info("Sending groupMessage" + gmsg.toCommon());
|
||||||
|
System.out.println(gmsg.toCommon().toString());
|
||||||
|
writeProxy.write(socketID, gmsg.toCommon());
|
||||||
|
// Sending memberStatusEvent to all members (event does not exist yet I think)
|
||||||
|
if (!gmsg.getMemberMessageStatus().containsValue(MessageStatus.SENT)) {
|
||||||
|
gmsg.setStatus(MessageStatus.RECEIVED);
|
||||||
|
// TODO: Sending MessageStatusChangeEvent to all other members
|
||||||
|
}
|
||||||
|
PersistenceManager.getInstance().updateMessage(gmsg);
|
||||||
|
} else {
|
||||||
|
// Sending memberStatusEvents and MessageStatusChange Events
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,8 +34,9 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
|||||||
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
|
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
|
||||||
// Makes sure, that there are no groupMessages processed here, because
|
// Makes sure, that there are no groupMessages processed here, because
|
||||||
// groupMessage is a subclass of message.
|
// groupMessage is a subclass of message.
|
||||||
if (message.getClass().equals(envoy.data.GroupMessage.class)) return;
|
if (message.getClass().equals(envoy.data.GroupMessage.class)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
message.nextStatus();
|
message.nextStatus();
|
||||||
|
|
||||||
// Convert to server message
|
// Convert to server message
|
||||||
|
Reference in New Issue
Block a user