Only consider the latest item for preloading.

This commit is contained in:
akwizgran
2018-11-14 15:13:25 +00:00
parent 78a8ae6b8e
commit 4db075d643

View File

@@ -336,17 +336,19 @@ public class ConversationActivity extends BriarActivity
new ArrayList<>(headers);
sort(sorted, (a, b) ->
Long.compare(b.getTimestamp(), a.getTimestamp()));
// Eagerly load the text of the latest message to avoid jumping
for (ConversationMessageHeader h : sorted) {
if (h instanceof PrivateMessageHeader) {
MessageId id = h.getId();
if (!sorted.isEmpty()) {
// If the latest header is a private message, eagerly load
// its text so we can set the scroll position correctly
ConversationMessageHeader latest = sorted.get(0);
if (latest instanceof PrivateMessageHeader &&
((PrivateMessageHeader) latest).hasText()) {
MessageId id = latest.getId();
String text = textCache.get(id);
if (text == null) {
LOG.info("Eagerly loading text of latest message");
text = messagingManager.getMessageText(id);
textCache.put(id, text);
}
break;
}
}
displayMessages(revision, sorted);