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

@@ -19,6 +19,7 @@ object ChatFolderContextMenu {
rootView: ViewGroup = anchorView.rootView as ViewGroup,
folderType: ChatFolderRecord.FolderType,
unreadCount: Int,
isEmpty: Boolean,
isMuted: Boolean,
onEdit: () -> Unit = {},
onMuteAll: () -> Unit = {},
@@ -32,6 +33,7 @@ object ChatFolderContextMenu {
rootView = rootView,
folderType = folderType,
unreadCount = unreadCount,
isEmpty = isEmpty,
isMuted = isMuted,
callbacks = object : Callbacks {
override fun onEdit() = onEdit()
@@ -48,6 +50,7 @@ object ChatFolderContextMenu {
anchorView: View,
rootView: ViewGroup,
unreadCount: Int,
isEmpty: Boolean,
isMuted: Boolean,
folderType: ChatFolderRecord.FolderType,
callbacks: Callbacks
@@ -61,13 +64,13 @@ object ChatFolderContextMenu {
)
}
if (isMuted) {
if (isMuted && !isEmpty) {
add(
ActionItem(R.drawable.symbol_bell_24, context.getString(R.string.ChatFoldersFragment__unmute_all)) {
callbacks.onUnmuteAll()
}
)
} else {
} else if (!isEmpty) {
add(
ActionItem(R.drawable.symbol_bell_slash_24, context.getString(R.string.ChatFoldersFragment__mute_all)) {
callbacks.onMuteAll()

View File

@@ -13,8 +13,8 @@ object ChatFoldersRepository {
return SignalDatabase.chatFolders.getCurrentChatFolders()
}
fun getUnreadCountAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Pair<Int, Boolean>> {
return SignalDatabase.chatFolders.getUnreadCountAndMutedStatusForFolders(folders)
fun getUnreadCountAndEmptyAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Triple<Int, Boolean, Boolean>> {
return SignalDatabase.chatFolders.getUnreadCountAndEmptyAndMutedStatusForFolders(folders)
}
fun createFolder(folder: ChatFolderRecord, includedRecipients: Set<Recipient>, excludedRecipients: Set<Recipient>) {

View File

@@ -43,6 +43,7 @@ class ChatFolderAdapter(val callbacks: Callbacks) : MappingAdapter() {
anchorView = view,
folderType = model.chatFolder.folderType,
unreadCount = model.unreadCount,
isEmpty = model.isEmpty,
isMuted = model.isMuted,
onEdit = { callbacks.onEdit(model.chatFolder) },
onMuteAll = { callbacks.onMuteAll(model.chatFolder) },

View File

@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel
data class ChatFolderMappingModel(
val chatFolder: ChatFolderRecord,
val unreadCount: Int,
val isEmpty: Boolean,
val isMuted: Boolean,
val isSelected: Boolean
) : MappingModel<ChatFolderMappingModel>, Parcelable {
@@ -22,6 +23,7 @@ data class ChatFolderMappingModel(
override fun areContentsTheSame(newItem: ChatFolderMappingModel): Boolean {
return chatFolder == newItem.chatFolder &&
unreadCount == newItem.unreadCount &&
isEmpty == newItem.isEmpty &&
isMuted == newItem.isMuted &&
isSelected == newItem.isSelected
}

View File

@@ -217,7 +217,7 @@ sealed class ConversationListViewModel(
private fun loadCurrentFolders() {
viewModelScope.launch(Dispatchers.IO) {
val folders = ChatFoldersRepository.getCurrentFolders()
val unreadCountAndMutedStatus = ChatFoldersRepository.getUnreadCountAndMutedStatusForFolders(folders)
val unreadCountAndEmptyAndMutedStatus = ChatFoldersRepository.getUnreadCountAndEmptyAndMutedStatusForFolders(folders)
val selectedFolderId = if (currentFolder.id == -1L) {
folders.firstOrNull()?.id
@@ -227,8 +227,9 @@ sealed class ConversationListViewModel(
val chatFolders = folders.map { folder ->
ChatFolderMappingModel(
chatFolder = folder,
unreadCount = unreadCountAndMutedStatus[folder.id]?.first ?: 0,
isMuted = unreadCountAndMutedStatus[folder.id]?.second ?: false,
unreadCount = unreadCountAndEmptyAndMutedStatus[folder.id]?.first ?: 0,
isEmpty = unreadCountAndEmptyAndMutedStatus[folder.id]?.second ?: false,
isMuted = unreadCountAndEmptyAndMutedStatus[folder.id]?.third ?: false,
isSelected = selectedFolderId == folder.id
)
}

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
*/