Skip to content

Commit

Permalink
Fix scroll to end and request more history
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Jan 20, 2024
1 parent 1338574 commit b659237
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ protected void onInitialize() {
if (newValue != null) {
newValue.getMessages().addListener(chatMessageListener);
newValue.getMessages().forEach(message -> fxApplicationThreadExecutor.execute(() -> rawMessages.add(message)));
fxApplicationThreadExecutor.execute(() -> messageListView.showAsLast(filteredMessages.size() - 1));
ObservableList<ChatChannelUser> typingUsers = newValue.getTypingUsers();
setTypingLabel(typingUsers);
typingUsers.addListener(typingUsersChangeListener);

scrollToEnd();
}
}));

Expand Down Expand Up @@ -179,11 +180,15 @@ protected void onInitialize() {

filteredMessages.subscribe(() -> {
if (messageListView.getLastVisibleIndex() == filteredMessages.size() - 2) {
fxApplicationThreadExecutor.execute(() -> messageListView.showAsLast(filteredMessages.size() - 1));
scrollToEnd();
}
});
}

private void scrollToEnd() {
fxApplicationThreadExecutor.execute(() -> messageListView.showAsLast(filteredMessages.size() - 1));
}

private void onMessageChange(SetChangeListener.Change<? extends ChatMessage> change) {
if (change.wasAdded()) {
fxApplicationThreadExecutor.execute(() -> rawMessages.add(change.getElementAdded()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ public void joinChannel(String channelName) {
bufferedChannels.add(channelName);
} else {
client.addChannel(channelName);
client.sendRawLine("CHATHISTORY LATEST " + channelName + " * " + (chatPrefs.getMaxMessages() + 50));
client.sendRawLine("CHATHISTORY LATEST " + channelName + " * " + (chatPrefs.getMaxMessages() * 2));
client.sendRawLine("WHO " + channelName);
}
}
Expand Down Expand Up @@ -936,7 +936,7 @@ private void incrementUnreadMessagesCount(Number oldValue, Number newValue) {
@Override
public void joinPrivateChat(String username) {
getOrCreateChannel(username);
client.sendRawLine("CHATHISTORY LATEST " + username + " * " + (chatPrefs.getMaxMessages() + 50));
client.sendRawLine("CHATHISTORY LATEST " + username + " * " + (chatPrefs.getMaxMessages() * 2));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public void testOnChatUserQuit() {
public void testJoinPrivateChat() {
instance.joinPrivateChat("junit");

verify(spyClient).sendRawLine("CHATHISTORY LATEST junit" + " * " + (chatPrefs.getMaxMessages() + 50));
verify(spyClient).sendRawLine("CHATHISTORY LATEST junit" + " * " + (chatPrefs.getMaxMessages() * 2));
}

@Test
Expand Down Expand Up @@ -779,7 +779,7 @@ public void testJoinChannel() {
instance.joinChannel(channelToJoin);

verify(spyClient).addChannel(channelToJoin);
verify(spyClient).sendRawLine("CHATHISTORY LATEST " + channelToJoin + " * " + (chatPrefs.getMaxMessages() + 50));
verify(spyClient).sendRawLine("CHATHISTORY LATEST " + channelToJoin + " * " + (chatPrefs.getMaxMessages() * 2));
verify(spyClient).sendRawLine("WHO " + channelToJoin);
}

Expand Down

0 comments on commit b659237

Please sign in to comment.