diff --git a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt index 8e18d8d2..fc75f0bc 100644 --- a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt @@ -278,11 +278,11 @@ fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList< projection += Threads.ARCHIVED } - var selection = "${Threads.MESSAGE_COUNT} > ?" - var selectionArgs = arrayOf("0") + var selection = "${Threads.MESSAGE_COUNT} > 0" + var selectionArgs = arrayOf() if (threadId != null) { selection += " AND ${Threads._ID} = ?" - selectionArgs = arrayOf("0", threadId.toString()) + selectionArgs += threadId.toString() } val sortOrder = "${Threads.DATE} DESC" @@ -355,11 +355,10 @@ private fun Context.queryCursorUnsafe( fun Context.getConversationIds(): List { val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true") val projection = arrayOf(Threads._ID) - val selection = "${Threads.MESSAGE_COUNT} > ?" - val selectionArgs = arrayOf("0") + val selection = "${Threads.MESSAGE_COUNT} > 0" val sortOrder = "${Threads.DATE} ASC" val conversationIds = mutableListOf() - queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor -> + queryCursor(uri, projection, selection, null, sortOrder, true) { cursor -> val id = cursor.getLongValue(Threads._ID) conversationIds.add(id) } @@ -1058,16 +1057,9 @@ fun Context.insertOrUpdateConversation( conversation: Conversation, cachedConv: Conversation? = conversationsDB.getConversationWithThreadId(conversation.threadId) ) { - val updatedConv = if (cachedConv != null) { - val usesCustomTitle = cachedConv.usesCustomTitle - val title = if (usesCustomTitle) { - cachedConv.title - } else { - conversation.title - } - conversation.copy(title = title, usesCustomTitle = usesCustomTitle) - } else { - conversation + var updatedConv = conversation + if (cachedConv != null && cachedConv.usesCustomTitle) { + updatedConv = updatedConv.copy(title = cachedConv.title, usesCustomTitle = cachedConv.usesCustomTitle) } conversationsDB.insertOrUpdate(updatedConv) }