diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 39d1985f..6a116d02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -520,7 +520,8 @@ class ThreadActivity : SimpleActivity() { return } - val dateOfFirstItem = messages.first().date + val firstItem = messages.first() + val dateOfFirstItem = firstItem.date if (oldestMessageDate == dateOfFirstItem) { allMessagesFetched = true return @@ -530,12 +531,11 @@ class ThreadActivity : SimpleActivity() { loadingOlderMessages = true ensureBackgroundThread { - val firstItem = messages.first() val olderMessages = getMessages(threadId, true, oldestMessageDate) .filter { message -> !messages.contains(message) } messages.addAll(0, olderMessages) - allMessagesFetched = olderMessages.size < MESSAGES_LIMIT || olderMessages.isEmpty() + allMessagesFetched = olderMessages.isEmpty() threadItems = getThreadItems() runOnUiThread { diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index 2aa8604b..0bfbcb2a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -135,6 +135,7 @@ fun Context.getMessages( .filter { it.participants.isNotEmpty() } .filterNot { it.isScheduled && it.millis() < System.currentTimeMillis() } .sortedWith(compareBy { it.date }.thenBy { it.id }) + .takeLast(limit) .toMutableList() as ArrayList return messages