Fix unread message counter
A bug remains when the total status of a group message is SENT, but the individual status for the client user is RECEIVED. In this case, the counter should be incremented but isn't.
This commit is contained in:
parent
afcf1e48a4
commit
47ab5d1e0c
@ -138,7 +138,13 @@ public final class ChatScene implements Restorable {
|
|||||||
// Listen to received messages
|
// Listen to received messages
|
||||||
eventBus.register(MessageCreationEvent.class, e -> {
|
eventBus.register(MessageCreationEvent.class, e -> {
|
||||||
final var message = e.get();
|
final var message = e.get();
|
||||||
localDB.getChat(message instanceof GroupMessage ? message.getRecipientID() : message.getSenderID()).ifPresent(chat -> {
|
|
||||||
|
// The sender of the message is the recipient of the chat
|
||||||
|
// Exceptions: this user is the sender (sync) or group message (group is
|
||||||
|
// recipient)
|
||||||
|
final long recipientID = message instanceof GroupMessage || message.getSenderID() == localDB.getUser().getID() ? message.getRecipientID()
|
||||||
|
: message.getSenderID();
|
||||||
|
localDB.getChat(recipientID).ifPresent(chat -> {
|
||||||
chat.insert(message);
|
chat.insert(message);
|
||||||
if (chat.equals(currentChat)) {
|
if (chat.equals(currentChat)) {
|
||||||
try {
|
try {
|
||||||
@ -147,8 +153,10 @@ public final class ChatScene implements Restorable {
|
|||||||
logger.log(Level.WARNING, "Could not read current chat: ", e1);
|
logger.log(Level.WARNING, "Could not read current chat: ", e1);
|
||||||
}
|
}
|
||||||
Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); });
|
Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); });
|
||||||
} else if (message.getRecipientID() == chat.getRecipient().getID() && message.getStatus() == RECEIVED) chat.incrementUnreadAmount();
|
// TODO: Increment unread counter for group messages with status < RECEIVED
|
||||||
// Moving chat with most recent unreadMessages to the top
|
} else if (message.getSenderID() != localDB.getUser().getID() && message.getStatus() == RECEIVED) chat.incrementUnreadAmount();
|
||||||
|
|
||||||
|
// Move chat with most recent unread messages to the top
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
chatList.getItems().remove(chat);
|
chatList.getItems().remove(chat);
|
||||||
chatList.getItems().add(0, chat);
|
chatList.getItems().add(0, chat);
|
||||||
|
@ -110,8 +110,9 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
|||||||
logger.info(user + " successfully authenticated.");
|
logger.info(user + " successfully authenticated.");
|
||||||
connectionManager.registerUser(user.getID(), socketID);
|
connectionManager.registerUser(user.getID(), socketID);
|
||||||
|
|
||||||
// Complete the handshake
|
// Change status and notify contacts about it
|
||||||
writeProxy.write(socketID, user.toCommon());
|
user.setStatus(ONLINE);
|
||||||
|
UserStatusChangeProcessor.updateUserStatus(user);
|
||||||
|
|
||||||
final var pendingMessages = PersistenceManager.getInstance().getPendingMessages(user, credentials.getLastSync());
|
final var pendingMessages = PersistenceManager.getInstance().getPendingMessages(user, credentials.getLastSync());
|
||||||
pendingMessages.removeIf(GroupMessage.class::isInstance);
|
pendingMessages.removeIf(GroupMessage.class::isInstance);
|
||||||
@ -145,7 +146,7 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
|||||||
final var gmsgCommon = gmsg.toCommon();
|
final var gmsgCommon = gmsg.toCommon();
|
||||||
|
|
||||||
// Deliver the message to the user if he hasn't received it yet
|
// Deliver the message to the user if he hasn't received it yet
|
||||||
if (gmsg.getMemberMessageStatus().get(user.getID()) == SENT) {
|
if (gmsg.getCreationDate().isAfter(credentials.getLastSync()) || gmsg.getMemberMessageStatus().get(user.getID()) == SENT) {
|
||||||
if (gmsg.getMemberMessageStatus().replace(user.getID(), RECEIVED) != RECEIVED) {
|
if (gmsg.getMemberMessageStatus().replace(user.getID(), RECEIVED) != RECEIVED) {
|
||||||
|
|
||||||
gmsg.setLastStatusChangeDate(Instant.now());
|
gmsg.setLastStatusChangeDate(Instant.now());
|
||||||
@ -187,9 +188,8 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change status and notify contacts about it
|
// Complete the handshake
|
||||||
user.setStatus(ONLINE);
|
writeProxy.write(socketID, user.toCommon());
|
||||||
UserStatusChangeProcessor.updateUserStatus(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user