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() { override fun onResume() {
super.onResume() super.onResume()
updateMenuColors() updateMenuColors()
refreshMenuItems()
getOrCreateConversationsAdapter().apply { getOrCreateConversationsAdapter().apply {
if (storedTextColor != getProperTextColor()) { if (storedTextColor != getProperTextColor()) {

View File

@ -312,10 +312,14 @@ class ThreadActivity : SimpleActivity() {
ensureBackgroundThread { ensureBackgroundThread {
messages = try { messages = try {
if (isRecycleBin) { if (isRecycleBin) {
messagesDB.getThreadMessagesFromRecycleBin(threadId).toMutableList() as ArrayList<Message> messagesDB.getThreadMessagesFromRecycleBin(threadId)
} else { } 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) { } catch (e: Exception) {
ArrayList() ArrayList()
} }
@ -351,8 +355,11 @@ class ThreadActivity : SimpleActivity() {
val cachedMessagesCode = messages.clone().hashCode() val cachedMessagesCode = messages.clone().hashCode()
if (!isRecycleBin) { if (!isRecycleBin) {
val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).map { it.id } messages = getMessages(threadId, true)
messages = getMessages(threadId, true).filter { !recycledMessages.contains(it.id) }.toMutableList() as ArrayList<Message> 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 -> val hasParticipantWithoutName = participants.any { contact ->
@ -1543,8 +1550,10 @@ class ThreadActivity : SimpleActivity() {
val scheduledMessages = messagesDB.getScheduledThreadMessages(threadId) val scheduledMessages = messagesDB.getScheduledThreadMessages(threadId)
.filterNot { it.isScheduled && it.millis() < System.currentTimeMillis() } .filterNot { it.isScheduled && it.millis() < System.currentTimeMillis() }
addAll(scheduledMessages) addAll(scheduledMessages)
val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).toSet() if (config.useRecycleBin) {
removeAll(recycledMessages) val recycledMessages = messagesDB.getThreadMessagesFromRecycleBin(threadId).toSet()
removeAll(recycledMessages)
}
} }
messages.filter { !it.isScheduled && !it.isReceivedMessage() && it.id > lastMaxId }.forEach { latestMessage -> 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") @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> 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> 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") @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> fun getThreadMessagesFromRecycleBin(threadId: Long): List<Message>