properly sort multipart messages by date, then by id

This commit is contained in:
tibbi 2020-04-15 12:09:12 +02:00
parent 647410f4aa
commit 64ee324d1a
1 changed files with 2 additions and 2 deletions

View File

@ -58,7 +58,7 @@ fun Context.getMessages(threadId: Int): ArrayList<Message> {
val selection = "${Sms.THREAD_ID} = ?" val selection = "${Sms.THREAD_ID} = ?"
val selectionArgs = arrayOf(threadId.toString()) val selectionArgs = arrayOf(threadId.toString())
val sortOrder = "${Sms._ID} DESC LIMIT 100" val sortOrder = "${Sms._ID} LIMIT 100"
var messages = ArrayList<Message>() var messages = ArrayList<Message>()
queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor -> queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor ->
@ -84,7 +84,7 @@ fun Context.getMessages(threadId: Int): ArrayList<Message> {
messages.addAll(getMMS(threadId, sortOrder)) messages.addAll(getMMS(threadId, sortOrder))
messages = messages.filter { it.participants.isNotEmpty() } messages = messages.filter { it.participants.isNotEmpty() }
.sortedByDescending { it.date }.toMutableList() as ArrayList<Message> .sortedWith(compareBy<Message> { it.date }.thenBy { it.id }).toMutableList() as ArrayList<Message>
return messages return messages
} }