Adjusted Query and implemented pending groupMessageStatusChange proc*ing

This commit is contained in:
DieGurke 2020-07-08 13:53:10 +02:00
parent b6de5b2c20
commit 0bbb4c9f29
3 changed files with 16 additions and 2 deletions

View File

@ -21,7 +21,8 @@ import envoy.data.Group;
name = GroupMessage.getPendingGroupMsg,
query = "SELECT m FROM GroupMessage m JOIN m.memberMessageStatus s WHERE (KEY(s) = :userId) AND ((m.creationDate > :lastSeen)"
+ "OR ((m.status = envoy.data.Message$MessageStatus.RECEIVED) AND (m.receivedDate > :lastSeen))"
+ "OR ((m.status = envoy.data.Message$MessageStatus.READ) AND (m.readDate > :lastSeen)))"
+ "OR ((m.status = envoy.data.Message$MessageStatus.READ) AND (m.readDate > :lastSeen))"
+ "OR ((m.lastStatusChangeDate > :lastSeen)))"
)
public class GroupMessage extends Message {

View File

@ -42,6 +42,7 @@ public class GroupMessageStatusChangeProcessor implements ObjectProcessor<GroupM
// Apply the status change
gmsg.getMemberMessageStatus().replace(statusChange.getMemberID(), statusChange.get());
gmsg.setLastStatusChangeDate(LocalDateTime.now());
// Notifying the other members about the status change
gmsg.getMemberMessageStatus()

View File

@ -144,6 +144,9 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
// Deliver the message to the user if he hasn't received it yet
if (gmsg.getMemberMessageStatus().get(user.getID()) == SENT) {
gmsg.getMemberMessageStatus().replace(user.getID(), RECEIVED);
gmsg.setLastStatusChangeDate(LocalDateTime.now());
writeProxy.write(socketID, gmsgCommon);
// Notify all online group members about the status change
@ -163,8 +166,17 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
PersistenceManager.getInstance().updateMessage(gmsg);
} else {
// Sending group message status changes
if (gmsg.getStatus() == SENT && gmsg.getLastStatusChangeDate().isAfter(gmsg.getCreationDate())
|| gmsg.getStatus() == RECEIVED && gmsg.getLastStatusChangeDate().isAfter(gmsg.getReceivedDate())) {
gmsg.getMemberMessageStatus().forEach((memberID, memberStatus) ->
writeProxy.write(socketID, new GroupMessageStatusChange(gmsg.getID(), memberStatus, gmsg.getLastStatusChangeDate(), memberID)));
}
// Deliver just a status change instead of the whole message
writeProxy.write(socketID, new MessageStatusChange(gmsgCommon));
if (gmsg.getStatus() == SENT && user.getLastSeen().isBefore(gmsg.getCreationDate())
|| gmsg.getStatus() == RECEIVED && user.getLastSeen().isBefore(gmsg.getReceivedDate()))
writeProxy.write(socketID, new MessageStatusChange(gmsgCommon));
}
}
}