Fix notifying the sender about a message delivery

This addresses bugs in two instances of delivery notification:
* the sender is online -> no event was sent
* the sender comes online later -> wrong status (SENT) was sent
This commit is contained in:
2020-06-25 17:00:41 +02:00
parent 3ba5a0c64e
commit e1bfab814c
2 changed files with 37 additions and 21 deletions

View File

@ -109,14 +109,21 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
final var pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
logger.fine("Sending " + pendingMessages.size() + " pending messages to " + user + "...");
for (var msg : pendingMessages) {
final var msgCommon = msg.toCommon();
if (msg.getStatus() == MessageStatus.SENT) {
// Send the message
writeProxy.write(socketID, msgCommon);
msg.received();
if (connectionManager.isOnline(msg.getSender().getID()))
writeProxy.write(connectionManager.getSocketID(msg.getSender().getID()), new MessageStatusChange(msgCommon));
PersistenceManager.getInstance().updateMessage(msg);
// Notify the sender about the delivery
if (connectionManager.isOnline(msg.getSender().getID())) {
msgCommon.nextStatus();
writeProxy.write(connectionManager.getSocketID(msg.getSender().getID()), new MessageStatusChange(msgCommon));
}
} else writeProxy.write(socketID, new MessageStatusChange(msgCommon));
}
}