Skip to content

Commit a66031c

Browse files
lisa-signalcody-signal
authored andcommitted
Fix chat folder to not show mute option if there isn't any chat.
1 parent cf0dfdc commit a66031c

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

app/src/main/java/org/thoughtcrime/securesms/components/settings/app/chats/folders/ChatFolderContextMenu.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object ChatFolderContextMenu {
1919
rootView: ViewGroup = anchorView.rootView as ViewGroup,
2020
folderType: ChatFolderRecord.FolderType,
2121
unreadCount: Int,
22+
isEmpty: Boolean,
2223
isMuted: Boolean,
2324
onEdit: () -> Unit = {},
2425
onMuteAll: () -> Unit = {},
@@ -32,6 +33,7 @@ object ChatFolderContextMenu {
3233
rootView = rootView,
3334
folderType = folderType,
3435
unreadCount = unreadCount,
36+
isEmpty = isEmpty,
3537
isMuted = isMuted,
3638
callbacks = object : Callbacks {
3739
override fun onEdit() = onEdit()
@@ -48,6 +50,7 @@ object ChatFolderContextMenu {
4850
anchorView: View,
4951
rootView: ViewGroup,
5052
unreadCount: Int,
53+
isEmpty: Boolean,
5154
isMuted: Boolean,
5255
folderType: ChatFolderRecord.FolderType,
5356
callbacks: Callbacks
@@ -61,13 +64,13 @@ object ChatFolderContextMenu {
6164
)
6265
}
6366

64-
if (isMuted) {
67+
if (isMuted && !isEmpty) {
6568
add(
6669
ActionItem(R.drawable.symbol_bell_24, context.getString(R.string.ChatFoldersFragment__unmute_all)) {
6770
callbacks.onUnmuteAll()
6871
}
6972
)
70-
} else {
73+
} else if (!isEmpty) {
7174
add(
7275
ActionItem(R.drawable.symbol_bell_slash_24, context.getString(R.string.ChatFoldersFragment__mute_all)) {
7376
callbacks.onMuteAll()

app/src/main/java/org/thoughtcrime/securesms/components/settings/app/chats/folders/ChatFoldersRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ object ChatFoldersRepository {
1313
return SignalDatabase.chatFolders.getCurrentChatFolders()
1414
}
1515

16-
fun getUnreadCountAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Pair<Int, Boolean>> {
17-
return SignalDatabase.chatFolders.getUnreadCountAndMutedStatusForFolders(folders)
16+
fun getUnreadCountAndEmptyAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Triple<Int, Boolean, Boolean>> {
17+
return SignalDatabase.chatFolders.getUnreadCountAndEmptyAndMutedStatusForFolders(folders)
1818
}
1919

2020
fun createFolder(folder: ChatFolderRecord, includedRecipients: Set<Recipient>, excludedRecipients: Set<Recipient>) {

app/src/main/java/org/thoughtcrime/securesms/conversationlist/ChatFolderAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ChatFolderAdapter(val callbacks: Callbacks) : MappingAdapter() {
4343
anchorView = view,
4444
folderType = model.chatFolder.folderType,
4545
unreadCount = model.unreadCount,
46+
isEmpty = model.isEmpty,
4647
isMuted = model.isMuted,
4748
onEdit = { callbacks.onEdit(model.chatFolder) },
4849
onMuteAll = { callbacks.onMuteAll(model.chatFolder) },

app/src/main/java/org/thoughtcrime/securesms/conversationlist/ChatFolderMappingModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel
1212
data class ChatFolderMappingModel(
1313
val chatFolder: ChatFolderRecord,
1414
val unreadCount: Int,
15+
val isEmpty: Boolean,
1516
val isMuted: Boolean,
1617
val isSelected: Boolean
1718
) : MappingModel<ChatFolderMappingModel>, Parcelable {
@@ -22,6 +23,7 @@ data class ChatFolderMappingModel(
2223
override fun areContentsTheSame(newItem: ChatFolderMappingModel): Boolean {
2324
return chatFolder == newItem.chatFolder &&
2425
unreadCount == newItem.unreadCount &&
26+
isEmpty == newItem.isEmpty &&
2527
isMuted == newItem.isMuted &&
2628
isSelected == newItem.isSelected
2729
}

app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListViewModel.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ sealed class ConversationListViewModel(
217217
private fun loadCurrentFolders() {
218218
viewModelScope.launch(Dispatchers.IO) {
219219
val folders = ChatFoldersRepository.getCurrentFolders()
220-
val unreadCountAndMutedStatus = ChatFoldersRepository.getUnreadCountAndMutedStatusForFolders(folders)
220+
val unreadCountAndEmptyAndMutedStatus = ChatFoldersRepository.getUnreadCountAndEmptyAndMutedStatusForFolders(folders)
221221

222222
val selectedFolderId = if (currentFolder.id == -1L) {
223223
folders.firstOrNull()?.id
@@ -227,8 +227,9 @@ sealed class ConversationListViewModel(
227227
val chatFolders = folders.map { folder ->
228228
ChatFolderMappingModel(
229229
chatFolder = folder,
230-
unreadCount = unreadCountAndMutedStatus[folder.id]?.first ?: 0,
231-
isMuted = unreadCountAndMutedStatus[folder.id]?.second ?: false,
230+
unreadCount = unreadCountAndEmptyAndMutedStatus[folder.id]?.first ?: 0,
231+
isEmpty = unreadCountAndEmptyAndMutedStatus[folder.id]?.second ?: false,
232+
isMuted = unreadCountAndEmptyAndMutedStatus[folder.id]?.third ?: false,
232233
isSelected = selectedFolderId == folder.id
233234
)
234235
}

app/src/main/java/org/thoughtcrime/securesms/database/ChatFolderTables.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,13 @@ class ChatFolderTables(context: Context?, databaseHelper: SignalDatabase?) : Dat
236236
/**
237237
* 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
238238
*/
239-
fun getUnreadCountAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Pair<Int, Boolean>> {
240-
val map: HashMap<Long, Pair<Int, Boolean>> = hashMapOf()
239+
fun getUnreadCountAndEmptyAndMutedStatusForFolders(folders: List<ChatFolderRecord>): HashMap<Long, Triple<Int, Boolean, Boolean>> {
240+
val map: HashMap<Long, Triple<Int, Boolean, Boolean>> = hashMapOf()
241241
folders.map { folder ->
242242
val unreadCount = SignalDatabase.threads.getUnreadCountByChatFolder(folder)
243+
val isEmpty = !SignalDatabase.threads.hasChatInFolder(folder)
243244
val isMuted = !SignalDatabase.threads.hasUnmutedChatsInFolder(folder)
244-
map[folder.id] = Pair(unreadCount, isMuted)
245+
map[folder.id] = Triple(unreadCount, isEmpty, isMuted)
245246
}
246247
return map
247248
}

app/src/main/java/org/thoughtcrime/securesms/database/ThreadTable.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,28 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
650650
return allCount + forcedUnreadCount
651651
}
652652

653+
/**
654+
* Returns whether or not there are chats in a chat folder
655+
*/
656+
fun hasChatInFolder(folder: ChatFolderRecord): Boolean {
657+
val chatFolderQuery = folder.toQuery()
658+
659+
val hasChats =
660+
"""
661+
SELECT EXISTS(
662+
SELECT 1
663+
FROM $TABLE_NAME
664+
LEFT OUTER JOIN ${RecipientTable.TABLE_NAME} ON $TABLE_NAME.$RECIPIENT_ID = ${RecipientTable.TABLE_NAME}.${RecipientTable.ID}
665+
WHERE
666+
$ARCHIVED = 0
667+
$chatFolderQuery
668+
LIMIT 1
669+
)
670+
"""
671+
672+
return readableDatabase.rawQuery(hasChats, null).readToSingleBoolean()
673+
}
674+
653675
/**
654676
* Returns whether or not there are any unmuted chats in a chat folder
655677
*/

0 commit comments

Comments
 (0)