Fix various bugs for chat folders.

This commit is contained in:
Michelle Tang
2024-10-21 11:02:40 -07:00
committed by Greyson Parrelli
parent b519bf6772
commit dd4fcffec4
18 changed files with 228 additions and 144 deletions

View File

@@ -152,7 +152,7 @@ class ChatFolderTables(context: Context?, databaseHelper: SignalDatabase?) : Dat
/**
* Maps the chat folder ids to its corresponding chat folder
*/
fun getChatFolders(includeUnreads: Boolean = false): List<ChatFolderRecord> {
fun getChatFolders(includeUnreadAndMutedCount: Boolean = false): List<ChatFolderRecord> {
val includedChats: Map<Long, List<Long>> = getIncludedChats()
val excludedChats: Map<Long, List<Long>> = getExcludedChats()
@@ -178,10 +178,11 @@ class ChatFolderTables(context: Context?, databaseHelper: SignalDatabase?) : Dat
)
}
if (includeUnreads) {
if (includeUnreadAndMutedCount) {
return folders.map { folder ->
folder.copy(
unreadCount = SignalDatabase.threads.getUnreadCountByChatFolder(folder)
unreadCount = SignalDatabase.threads.getUnreadCountByChatFolder(folder),
isMuted = !SignalDatabase.threads.hasUnmutedChatsInFolder(folder)
)
}
}

View File

@@ -18,6 +18,7 @@ import org.signal.core.util.exists
import org.signal.core.util.logging.Log
import org.signal.core.util.or
import org.signal.core.util.readToList
import org.signal.core.util.readToSingleBoolean
import org.signal.core.util.readToSingleInt
import org.signal.core.util.readToSingleLong
import org.signal.core.util.requireBoolean
@@ -631,6 +632,26 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
return allCount + forcedUnreadCount
}
/**
* Returns whether or not there are any unmuted chats in a chat folder
*/
fun hasUnmutedChatsInFolder(folder: ChatFolderRecord): Boolean {
val chatFolderQuery = folder.toQuery()
val unmutedChats =
"""
SELECT COUNT(${RecipientTable.MUTE_UNTIL})
FROM $TABLE_NAME
LEFT OUTER JOIN ${RecipientTable.TABLE_NAME} ON $TABLE_NAME.$RECIPIENT_ID = ${RecipientTable.TABLE_NAME}.${RecipientTable.ID}
WHERE
$ARCHIVED = 0 AND
${RecipientTable.MUTE_UNTIL} = 0
$chatFolderQuery
"""
return readableDatabase.rawQuery(unmutedChats, null).readToSingleBoolean()
}
/**
* Returns the number of unread messages across all threads within a chat folder
* Threads that are forced-unread count as 1.