Implemented good suggestion by @delvh regarding performance increase
This commit is contained in:
parent
4b3fa65822
commit
a6efe7cd9b
@ -29,6 +29,8 @@ public class Chat implements Serializable {
|
|||||||
protected final Contact recipient;
|
protected final Contact recipient;
|
||||||
protected final List<Message> messages = new ArrayList<>();
|
protected final List<Message> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
protected int unreadAmount;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,6 +89,7 @@ public class Chat implements Serializable {
|
|||||||
writeProxy.writeMessageStatusChange(new MessageStatusChange(m));
|
writeProxy.writeMessageStatusChange(new MessageStatusChange(m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unreadAmount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,14 +114,9 @@ public class Chat implements Serializable {
|
|||||||
messages.add(0, message);
|
messages.add(0, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnreadAmount() {
|
public void incrementUnreadAmount() { unreadAmount++; }
|
||||||
int unreadMessagesAmount = 0;
|
|
||||||
for (int i = messages.size() - 1; i >= 0; i--) {
|
public int getUnreadAmount() { return unreadAmount; }
|
||||||
if (messages.get(i).getSenderID() == recipient.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
return unreadMessagesAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all messages in the current chat
|
* @return all messages in the current chat
|
||||||
|
@ -37,16 +37,6 @@ public class GroupChat extends Chat {
|
|||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getUnreadAmount() {
|
|
||||||
int unreadMessagesAmount = 0;
|
|
||||||
for (int i = messages.size() - 1; i >= 0; i--) {
|
|
||||||
if (messages.get(i).getSenderID() != sender.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
return unreadMessagesAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(WriteProxy writeProxy) throws IOException {
|
public void read(WriteProxy writeProxy) throws IOException {
|
||||||
for (int i = messages.size() - 1; i >= 0; --i) {
|
for (int i = messages.size() - 1; i >= 0; --i) {
|
||||||
@ -60,5 +50,6 @@ public class GroupChat extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
super.unreadAmount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ 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 chat.incrementUnreadAmount();
|
||||||
// Moving chat with most recent unreadMessages to the top
|
// Moving chat with most recent unreadMessages to the top
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
userList.getItems().remove(chat);
|
userList.getItems().remove(chat);
|
||||||
|
Reference in New Issue
Block a user