cleaning up getMessages, threadId cannot be null

This commit is contained in:
tibbi 2020-04-11 19:43:39 +02:00
parent 21dd815f2a
commit a4adf59323
1 changed files with 3 additions and 16 deletions

View File

@ -43,7 +43,7 @@ import kotlin.collections.ArrayList
val Context.config: Config get() = Config.newInstance(applicationContext)
fun Context.getMessages(threadId: Int? = null): ArrayList<Message> {
fun Context.getMessages(threadId: Int): ArrayList<Message> {
val uri = Sms.CONTENT_URI
val projection = arrayOf(
Sms._ID,
@ -55,17 +55,8 @@ fun Context.getMessages(threadId: Int? = null): ArrayList<Message> {
Sms.THREAD_ID
)
val selection = if (threadId == null) {
"1 == 1) GROUP BY (${Sms.THREAD_ID}"
} else {
"${Sms.THREAD_ID} = ?"
}
val selectionArgs = if (threadId == null) {
null
} else {
arrayOf(threadId.toString())
}
val selection = "${Sms.THREAD_ID} = ?"
val selectionArgs = arrayOf(threadId.toString())
var messages = ArrayList<Message>()
queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor ->
@ -93,10 +84,6 @@ fun Context.getMessages(threadId: Int? = null): ArrayList<Message> {
messages = messages.filter { it.participants.isNotEmpty() }
.sortedByDescending { it.date }.toMutableList() as ArrayList<Message>
if (threadId == null) {
messages = messages.distinctBy { it.thread }.toMutableList() as ArrayList<Message>
}
return messages
}