Fix chat folder to not show mute option if there isn't any chat.

This commit is contained in:
lisa-signal
2025-06-04 15:16:14 -04:00
committed by Cody Henthorne
parent cf0dfdceb1
commit a66031cfce
7 changed files with 40 additions and 10 deletions

View File

@@ -236,12 +236,13 @@ class ChatFolderTables(context: Context?, databaseHelper: SignalDatabase?) : Dat
/**
* Given a list of folders, maps a folder id to the folder's unread count and whether all the chats in the folder are muted
*/
fun getUnreadCountAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Pair<Int, Boolean>> {
val map: HashMap<Long, Pair<Int, Boolean>> = hashMapOf()
fun getUnreadCountAndEmptyAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Triple<Int, Boolean, Boolean>> {
val map: HashMap<Long, Triple<Int, Boolean, Boolean>> = hashMapOf()
folders.map { folder ->
val unreadCount = SignalDatabase.threads.getUnreadCountByChatFolder(folder)
val isEmpty = !SignalDatabase.threads.hasChatInFolder(folder)
val isMuted = !SignalDatabase.threads.hasUnmutedChatsInFolder(folder)
map[folder.id] = Pair(unreadCount, isMuted)
map[folder.id] = Triple(unreadCount, isEmpty, isMuted)
}
return map
}

View File

@@ -650,6 +650,28 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
return allCount + forcedUnreadCount
}
/**
* Returns whether or not there are chats in a chat folder
*/
fun hasChatInFolder(folder: ChatFolderRecord): Boolean {
val chatFolderQuery = folder.toQuery()
val hasChats =
"""
SELECT EXISTS(
SELECT 1
FROM $TABLE_NAME
LEFT OUTER JOIN ${RecipientTable.TABLE_NAME} ON $TABLE_NAME.$RECIPIENT_ID = ${RecipientTable.TABLE_NAME}.${RecipientTable.ID}
WHERE
$ARCHIVED = 0
$chatFolderQuery
LIMIT 1
)
"""
return readableDatabase.rawQuery(hasChats, null).readToSingleBoolean()
}
/**
* Returns whether or not there are any unmuted chats in a chat folder
*/