mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Fix various bugs for chat folders.
This commit is contained in:
committed by
Greyson Parrelli
parent
b519bf6772
commit
dd4fcffec4
@@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user