From bcb42d0ff58424357364329fda7d50badeee11e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 20 Jul 2023 16:34:05 +0200 Subject: [PATCH] Ensure recycle bin is ignored when disabled --- .../smsmessenger/activities/MainActivity.kt | 1 + .../smsmessenger/activities/ThreadActivity.kt | 23 +++++++++++++------ .../smsmessenger/interfaces/MessagesDao.kt | 5 +++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index d1a5fad3..0c5c567e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -85,6 +85,7 @@ class MainActivity : SimpleActivity() { override fun onResume() { super.onResume() updateMenuColors() + refreshMenuItems() getOrCreateConversationsAdapter().apply { if (storedTextColor != getProperTextColor()) { 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 bbb98cbf..cc136d47 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -312,10 +312,14 @@ class ThreadActivity : SimpleActivity() { ensureBackgroundThread { messages = try { if (isRecycleBin) { - messagesDB.getThreadMessagesFromRecycleBin(threadId).toMutableList() as ArrayList + messagesDB.getThreadMessagesFromRecycleBin(threadId) } else { - messagesDB.getThreadMessages(threadId).toMutableList() as ArrayList - } + if (config.useRecycleBin) { + messagesDB.getNonRecycledThreadMessages(threadId) + } else { + messagesDB.getThreadMessages(threadId) + } + }.toMutableList() as ArrayList } catch (e: Exception) { ArrayList() } @@ -351,8 +355,11 @@ class ThreadActivity : SimpleActivity() { val cachedMessagesCode = messages.clone().hashCode() if (!isRecycleBin) { - val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).map { it.id } - messages = getMessages(threadId, true).filter { !recycledMessages.contains(it.id) }.toMutableList() as ArrayList + messages = getMessages(threadId, true) + if (config.useRecycleBin) { + val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).map { it.id } + messages = messages.filter { !recycledMessages.contains(it.id) }.toMutableList() as ArrayList + } } val hasParticipantWithoutName = participants.any { contact -> @@ -1543,8 +1550,10 @@ class ThreadActivity : SimpleActivity() { val scheduledMessages = messagesDB.getScheduledThreadMessages(threadId) .filterNot { it.isScheduled && it.millis() < System.currentTimeMillis() } addAll(scheduledMessages) - val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).toSet() - removeAll(recycledMessages) + if (config.useRecycleBin) { + val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).toSet() + removeAll(recycledMessages) + } } messages.filter { !it.isScheduled && !it.isReceivedMessage() && it.id > lastMaxId }.forEach { latestMessage -> diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt index f8bb9f38..3287ab64 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt @@ -27,9 +27,12 @@ interface MessagesDao { @Query("SELECT messages.* FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NOT NULL AND recycle_bin_messages.deleted_ts < :timestamp") fun getOldRecycleBinMessages(timestamp: Long): List - @Query("SELECT messages.* FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NULL AND thread_id = :threadId") + @Query("SELECT * FROM messages WHERE thread_id = :threadId") fun getThreadMessages(threadId: Long): List + @Query("SELECT messages.* FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NULL AND thread_id = :threadId") + fun getNonRecycledThreadMessages(threadId: Long): List + @Query("SELECT messages.* FROM messages LEFT OUTER JOIN recycle_bin_messages ON messages.id = recycle_bin_messages.id WHERE recycle_bin_messages.id IS NOT NULL AND thread_id = :threadId") fun getThreadMessagesFromRecycleBin(threadId: Long): List