From 64ee324d1a382eeb69a38c332408141f77d5fc0e Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 15 Apr 2020 12:09:12 +0200 Subject: [PATCH] properly sort multipart messages by date, then by id --- .../com/simplemobiletools/smsmessenger/extensions/Context.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 82185071..4efd922f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -58,7 +58,7 @@ fun Context.getMessages(threadId: Int): ArrayList { val selection = "${Sms.THREAD_ID} = ?" val selectionArgs = arrayOf(threadId.toString()) - val sortOrder = "${Sms._ID} DESC LIMIT 100" + val sortOrder = "${Sms._ID} LIMIT 100" var messages = ArrayList() queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor -> @@ -84,7 +84,7 @@ fun Context.getMessages(threadId: Int): ArrayList { messages.addAll(getMMS(threadId, sortOrder)) messages = messages.filter { it.participants.isNotEmpty() } - .sortedByDescending { it.date }.toMutableList() as ArrayList + .sortedWith(compareBy { it.date }.thenBy { it.id }).toMutableList() as ArrayList return messages }