Ensure recycle bin is ignored when disabled

This commit is contained in:
Ensar Sarajčić 2023-07-20 16:34:05 +02:00
parent cc6e9358f6
commit bcb42d0ff5
3 changed files with 21 additions and 8 deletions

View File

@ -85,6 +85,7 @@ class MainActivity : SimpleActivity() {
override fun onResume() {
super.onResume()
updateMenuColors()
refreshMenuItems()
getOrCreateConversationsAdapter().apply {
if (storedTextColor != getProperTextColor()) {

View File

@ -312,10 +312,14 @@ class ThreadActivity : SimpleActivity() {
ensureBackgroundThread {
messages = try {
if (isRecycleBin) {
messagesDB.getThreadMessagesFromRecycleBin(threadId).toMutableList() as ArrayList<Message>
messagesDB.getThreadMessagesFromRecycleBin(threadId)
} else {
messagesDB.getThreadMessages(threadId).toMutableList() as ArrayList<Message>
}
if (config.useRecycleBin) {
messagesDB.getNonRecycledThreadMessages(threadId)
} else {
messagesDB.getThreadMessages(threadId)
}
}.toMutableList() as ArrayList<Message>
} 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<Message>
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<Message>
}
}
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 ->

View File

@ -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<Message>
@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<Message>
@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<Message>
@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<Message>